[dev] [commit] r1026 - app phplib phplib/ads tools wwwbase wwwbase/ajax wwwbase/auth
automailer at dexonline.ro
automailer at dexonline.ro
Mon Oct 21 12:30:37 EEST 2013
Author: cata
Date: Mon Oct 21 12:30:37 2013
New Revision: 1026
Log:
Converted serverPreferences.php to a class, Config.php.
Simplified the syntax for reading preferences:
* pref_getSectionPreference('foo', 'bar') is now Config::get('foo.bar')
* pref_getServerPreference('foo') is now Config::get('global.foo')
Added:
phplib/Config.php
- copied, changed from r1025, phplib/serverPreferences.php
Deleted:
phplib/serverPreferences.php
Modified:
app/AbstractCrawler.php
app/Crawler.php
app/DiacriticsBuilder.php
app/clean.php
phplib/AppLog.php
phplib/DebugInfo.php
phplib/LocVersion.php
phplib/Log.php
phplib/SmartyWrap.php
phplib/ads/adsModule.php
phplib/db.php
phplib/memcache.php
phplib/session.php
phplib/util.php
tools/freezeLocVersion.php
tools/rebuildScrabbleForms.php
wwwbase/ajax/bookmarkAdd.php
wwwbase/ajax/fetchCrawlerStatus.php
wwwbase/auth/parola-uitata.php
wwwbase/diacritice.php
wwwbase/doneaza-euplatesc.php
wwwbase/doneaza.php
wwwbase/modele-flexiune.php
wwwbase/preferinte.php
wwwbase/scrabble-flexiune.php
wwwbase/scrabble-forme.php
wwwbase/scrabble-loc.php
wwwbase/search.php
wwwbase/siteClones.php
Modified: app/AbstractCrawler.php
==============================================================================
--- app/AbstractCrawler.php Mon Oct 21 10:58:30 2013 (r1025)
+++ app/AbstractCrawler.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -3,7 +3,7 @@
* Alin Ungureanu, 2013
* alyn.cti at gmail.com
*/
-require_once '../phplib/util.php';
+require_once __DIR__ . '/../phplib/util.php';
require_once util_getRootPath() . 'phplib/simple_html_dom.php';
require_once util_getRootPath() . 'phplib/AppLog.php';
@@ -37,9 +37,9 @@
$this->plainText = '';
$this->pageContent = '';
- $this->directoryIndexFile = pref_getSectionPreference('crawler', 'dir_index_file');
- $this->indexFileExt = explode(',', pref_getSectionPreference('crawler', 'index_file_ext'));
- $this->fileExt = explode(',', pref_getSectionPreference('crawler', 'index_file_ext').',txt');
+ $this->directoryIndexFile = Config::get('crawler.dir_index_file');
+ $this->indexFileExt = explode(',', Config::get('crawler.index_file_ext'));
+ $this->fileExt = explode(',', Config::get('crawler.index_file_ext').',txt');
}
@@ -47,10 +47,10 @@
function getPage($url) {
$this->ch = curl_init();
- Applog::log(file_get_contents(pref_getSectionPreference('crawler', 'user_agent_location')));
+ Applog::log(file_get_contents(Config::get('crawler.user_agent_location')));
curl_setopt ($this->ch, CURLOPT_URL, $url);
curl_setopt ($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt ($this->ch, CURLOPT_USERAGENT, file_get_contents(pref_getSectionPreference('crawler', 'user_agent_location')));
+ curl_setopt ($this->ch, CURLOPT_USERAGENT, file_get_contents(Config::get('crawler.user_agent_location')));
curl_setopt ($this->ch, CURLOPT_TIMEOUT, 20);
curl_setopt ($this->ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
@@ -93,9 +93,9 @@
function setStorePageParams() {
$this->currentTimestamp = date("Y-m-d H:i:s");
- $this->rawPagePath = pref_getSectionPreference('crawler', 'raw_page_path')
+ $this->rawPagePath = Config::get('crawler.raw_page_path')
.$this->urlResource['host'] .'/'. $this->currentTimestamp;
- $this->parsedTextPath = pref_getSectionPreference('crawler', 'parsed_text_path')
+ $this->parsedTextPath = Config::get('crawler.parsed_text_path')
.$this->urlResource['host'] .'/'. $this->currentTimestamp;
}
@@ -125,11 +125,11 @@
try {
- if (!file_exists(pref_getSectionPreference('crawler','raw_page_path').$this->urlResource['host'])) {
- mkdir(pref_getSectionPreference('crawler','raw_page_path').$this->urlResource['host'], 0777, true);
+ if (!file_exists(Config::get('crawler.raw_page_path').$this->urlResource['host'])) {
+ mkdir(Config::get('crawler.raw_page_path').$this->urlResource['host'], 0777, true);
}
- if (!file_exists(pref_getSectionPreference('crawler','parsed_text_path').$this->urlResource['host'])) {
- mkdir(pref_getSectionPreference('crawler','parsed_text_path').$this->urlResource['host'], 0777, true);
+ if (!file_exists(Config::get('crawler.parsed_text_path').$this->urlResource['host'])) {
+ mkdir(Config::get('crawler.parsed_text_path').$this->urlResource['host'], 0777, true);
}
//salveaza pagina raw pe disk
file_put_contents($this->rawPagePath, $this->pageContent);
Modified: app/Crawler.php
==============================================================================
--- app/Crawler.php Mon Oct 21 10:58:30 2013 (r1025)
+++ app/Crawler.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -52,7 +52,7 @@
MemoryManagement::showUsage('after cleaning', true, 'KB');
//niceness
- sleep(pref_getSectionPreference('crawler', 't_wait'));
+ sleep(Config::get('crawler.t_wait'));
}
catch (Exception $ex) {
Modified: app/DiacriticsBuilder.php
==============================================================================
--- app/DiacriticsBuilder.php Mon Oct 21 10:58:30 2013 (r1025)
+++ app/DiacriticsBuilder.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -10,7 +10,7 @@
db_init();
-$logFile = pref_getSectionPreference('app_log', 'diacritics_log');
+$logFile = Config::get('app_log.diacritics_log');
/*
* Builds examples and improves statistics for the diacritics mechanism
@@ -36,10 +36,10 @@
function __construct() {
Applog::log("INSIDE " . __FILE__ . ' - ' . __CLASS__ . '::' . __FUNCTION__ . '() - ' . 'line '.__LINE__, 4);
- self::$diacritics = pref_getSectionPreference("diacritics", "diacritics");
- self::$nonDiacritics = pref_getSectionPreference("diacritics", "non_lower_diacritics");
- self::$paddingNumber = pref_getSectionPreference('diacritics', 'diacritics_padding_length');
- self::$paddingChar = pref_getSectionPreference('diacritics', 'padding_char');
+ self::$diacritics = Config::get('diacritics.diacritics');
+ self::$nonDiacritics = Config::get('diacritics.non_lower_diacritics');
+ self::$paddingNumber = Config::get('diacritics.diacritics_padding_length');
+ self::$paddingChar = Config::get('diacritics.padding_char');
$this->globalCount = 0;
}
Modified: app/clean.php
==============================================================================
--- app/clean.php Mon Oct 21 10:58:30 2013 (r1025)
+++ app/clean.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -4,10 +4,6 @@
* alyn.cti at gmail.com
*/
require_once '../../phplib/util.php';
-require_once '../../phplib/serverPreferences.php';
-require_once '../../phplib/db.php';
-require_once '../../phplib/idiorm/idiorm.php';
-
function printUsage() {
echo "::Usage::".PHP_EOL."php clean_all.php [ -c | --crawler] [ -d | --diacritics]".PHP_EOL;
@@ -39,20 +35,20 @@
removeFiles('RawPage/*');
- echo 'files deleted'.pref_getSectionPreference('crawler', 'new_line');
+ echo 'files deleted' . Config::get('crawler.new_line');
$db->exec('TRUNCATE Table CrawledPage;');
$db->exec('TRUNCATE Table Link;');
$db->commit();
- echo "tables 'Link' and 'CrawledPage' truncated".pref_getSectionPreference('crawler', 'new_line');
+ echo "tables 'Link' and 'CrawledPage' truncated" . Config::get('crawler.new_line');
- echo 'The cleaning process was successful'.pref_getSectionPreference('crawler', 'new_line');
+ echo 'The cleaning process was successful' . Config::get('crawler.new_line');
}
catch(Exception $ex) {
- echo 'The cleaning process encountered a problem '.pref_getSectionPreference('crawler', 'new_line').$ex->getMessage();
+ echo 'The cleaning process encountered a problem ' . Config::get('crawler.new_line').$ex->getMessage();
}
}
else if ($argv[1] == '--diacritics' || $argv[1] == '-d') {
@@ -61,12 +57,12 @@
$db->exec('TRUNCATE Table Diacritics;');
$db->exec('TRUNCATE Table FilesUsedInDiacritics;');
$db->commit();
- echo "tables 'Diacritics' and 'FilesUsedInDiacritics' truncated".pref_getSectionPreference('crawler', 'new_line');
- echo 'The cleaning process was successful'.pref_getSectionPreference('crawler', 'new_line');
+ echo "tables 'Diacritics' and 'FilesUsedInDiacritics' truncated" . Config::get('crawler.new_line');
+ echo 'The cleaning process was successful' . Config::get('crawler.new_line');
}
catch(Exception $e) {
- echo 'The cleaning process encountered a problem '.pref_getSectionPreference('crawler', 'new_line').$ex->getMessage();
+ echo 'The cleaning process encountered a problem ' . Config::get('crawler.new_line').$ex->getMessage();
}
}
Modified: phplib/AppLog.php
==============================================================================
--- phplib/AppLog.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/AppLog.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -11,8 +11,8 @@
* $logFile = fisierul de log al aplicatiei, poate fi schimbat dupa
* includerea AppLog.php
*/
-$exceptionExit = pref_getSectionPreference('app_log', 'exception_exit');
-$logFile = pref_getSectionPreference('app_log', 'crawler_log');
+$exceptionExit = Config::get('app_log.exception_exit');
+$logFile = Config::get('app_log.crawler_log');
/*
* Logheaza activitatea crawlerului, afiseaza exceptiile
* $level poate fi de forma : __FILE__.' - '.__CLASS__.'::'.__FUNCTION__.' line '.__LINE__
@@ -42,12 +42,12 @@
global $logFile;
//filtreaza mesajele
- switch(pref_getSectionPreference('app_log', 'log_detail_level')) {
+ switch(Config::get('app_log.log_detail_level')) {
case 0:
return;
case 1: case 4:
//minimal sau doar function debug
- if ($detailLevel != pref_getSectionPreference('app_log', 'log_detail_level')) {
+ if ($detailLevel != Config::get('app_log.log_detail_level')) {
return;
}
break;
@@ -64,17 +64,17 @@
break;
}
//log in fisier
- if (pref_getSectionPreference('app_log', 'log2file'))
+ if (Config::get('app_log.log2file'))
try {
$fd = fopen($logFile, "a+");
fprintf($fd, "%s\n", date("Y-m-d H:i:s") . '::' . $message);
fclose( $fd);
}
- catch(Exception $ex) {
- echo "LOG FILE PROBLEM" .pref_getSectionPreference('app_log', 'new_line');
+ catch (Exception $ex) {
+ echo "LOG FILE PROBLEM" . Config::get('app_log.new_line');
}
//log in stdout
- if(pref_getSectionPreference('app_log', 'log2screen')) {
+ if (Config::get('app_log.log2screen')) {
echo date("Y-m-d H:i:s") . '::' . $message. self::getCorrespondentNewLine();
flush();
Copied and modified: phplib/Config.php (from r1025, phplib/serverPreferences.php)
==============================================================================
--- phplib/serverPreferences.php Mon Oct 21 10:58:30 2013 (r1025, copy source)
+++ phplib/Config.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -3,91 +3,63 @@
* Handles Java-style property files. If a property contains URL-style parameters (var=value1&var2=value2&...),
* we parse_str it and map the property name to the resulting associative array.
*/
-pref_parsePreferenceFile();
-function pref_parsePreferenceFile() {
- $raw = parse_ini_file(util_getRootPath() . "dex.conf", true);
- _pref_traverseRecursivePreferences($raw);
- $GLOBALS['serverPreferences'] = $raw;
-}
+class Config {
+ private static $config;
+ private static $locVersions = null;
+
+ static function load($fileName) {
+ self::$config = parse_ini_file($fileName, true);
+ self::traverseRecursivePreferences(self::$config);
+ }
-function _pref_traverseRecursivePreferences(&$pref) {
- foreach ($pref as $key => $value) {
- if (is_array($value)) {
- _pref_traverseRecursivePreferences($value);
- $pref[$key] = $value;
- } else {
- $pref[$key] = (strpos($value, '&') === false) ? $value : StringUtil::parseStr($value);
+ private static function traverseRecursivePreferences(&$a) {
+ foreach ($a as $key => $value) {
+ if (is_array($value)) {
+ self::traverseRecursivePreferences($value);
+ $a[$key] = $value;
+ } else if (strpos($value, '&') !== false) {
+ $a[$key] = StringUtil::parseStr($value);
+ }
}
}
-}
-function pref_getServerPreference($name) {
- if (array_key_exists('global', $GLOBALS['serverPreferences']) && array_key_exists($name, $GLOBALS['serverPreferences']['global'])) {
- return $GLOBALS['serverPreferences']['global'][$name];
- } else if (array_key_exists($name, $GLOBALS['serverPreferences'])) {
- // DEPRECATED. Python requires all INI file options to be contained in sections
- // We don't mind that, but we offer a fallback until people upgrade to the new config.
- return $GLOBALS['serverPreferences'][$name];
- } else {
- return false;
+ static function get($key, $defaultValue = null) {
+ list($section, $name) = explode('.', $key, 2);
+ if (array_key_exists($section, self::$config) && array_key_exists($name, self::$config[$section])) {
+ return self::$config[$section][$name];
+ } else {
+ return $defaultValue;
+ }
}
-}
-function pref_getSectionPreference($section, $name, $defaultValue = NULL) {
- if (array_key_exists($section, $GLOBALS['serverPreferences']) && array_key_exists($name, $GLOBALS['serverPreferences'][$section])) {
- return $GLOBALS['serverPreferences'][$section][$name];
- }
- else if (!is_null($defaultValue)) {
- return $defaultValue;
- } else {
- return false;
+ /* Returns an array containing all the variables in the given section, or the empty array if the section does not exist. */
+ static function getSection($section) {
+ return array_key_exists($section, self::$config) ? self::$config[$section] : array();
}
-}
-
-function pref_isMirror() {
- return pref_getServerPreference('mirror');
-}
-function pref_getLocPrefix() {
- return pref_getServerPreference('mysql_loc_prefix');
-}
-
-function pref_getContactEmail() {
- return pref_getServerPreference('contact');
-}
-
-function pref_getDebugUser() {
- return pref_getServerPreference('debugUser');
-}
-
-function pref_getMaxBookmarks() {
- return pref_getServerPreference('maxBookmarks');
-}
-
-function pref_getHostedBy() {
- return pref_getServerPreference('hostedBy');
-}
-
-function pref_getLocVersions() {
- if (!array_key_exists('locVersions', $GLOBALS)) {
- $result = array();
- $locParts = pref_getServerPreference('locVersions');
- foreach ($locParts as $part) {
- $part = trim($part);
- if ($part) {
- $versionAndDate = preg_split('/ /', $part);
- assert(count($versionAndDate == 2));
- $lv = new LocVersion();
- $lv->name = trim($versionAndDate[0]);
- $date = trim($versionAndDate[1]);
- $lv->freezeTimestamp = ($date == 'current') ? null : strtotime($date);
- $result[] = $lv;
+ static function getLocVersions() {
+ if (!self::$locVersions) {
+ $result = array();
+ $locParts = self::get('global.locVersions');
+ foreach ($locParts as $part) {
+ $part = trim($part);
+ if ($part) {
+ $versionAndDate = preg_split('/ /', $part);
+ assert(count($versionAndDate == 2));
+ $lv = new LocVersion();
+ $lv->name = trim($versionAndDate[0]);
+ $date = trim($versionAndDate[1]);
+ $lv->freezeTimestamp = ($date == 'current') ? null : strtotime($date);
+ $result[] = $lv;
+ }
}
+ self::$locVersions = array_reverse($result);
}
- $GLOBALS['locVersions'] = array_reverse($result);
+ return self::$locVersions;
}
- return $GLOBALS['locVersions'];
}
+Config::load(util_getRootPath() . "dex.conf");
+
?>
Modified: phplib/DebugInfo.php
==============================================================================
--- phplib/DebugInfo.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/DebugInfo.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -41,7 +41,7 @@
}
public static function getDebugInfo() {
- $enabled = self::$enabled && (session_getUserNick() == pref_getDebugUser());
+ $enabled = self::$enabled && (session_getUserNick() == Config::get('global.debugUser'));
SmartyWrap::assign('debug_enabled', $enabled);
if ($enabled) {
SmartyWrap::assign('debug_messages', self::$debugInfo);
Modified: phplib/LocVersion.php
==============================================================================
--- phplib/LocVersion.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/LocVersion.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -17,14 +17,14 @@
}
public static function changeDatabase($versionName) {
- $lvs = pref_getLocVersions();
+ $lvs = Config::getLocVersions();
if ($versionName == $lvs[0]->name || !$versionName) {
$dbInfo = db_splitDsn();
$dbName = $dbInfo['database'];
} else {
$lv = new LocVersion();
$lv->name = $versionName;
- $dbName = pref_getLocPrefix() . $lv->getDbName();
+ $dbName = Config::get('global.mysql_loc_prefix') . $lv->getDbName();
}
db_changeDatabase($dbName);
}
Modified: phplib/Log.php
==============================================================================
--- phplib/Log.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/Log.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -16,7 +16,7 @@
* @return void
**/
public function __construct($query, $queryBeforeRedirect, $searchType, $redirect = false, &$results = null) {
- if (!pref_getServerPreference('logSearch') || lcg_value() > pref_getServerPreference('logSampling')) {
+ if (!Config::get('global.logSearch') || lcg_value() > Config::get('global.logSampling')) {
$this->query = null;
return false;
}
@@ -37,7 +37,7 @@
$this->resultList = '';
if ($results != null) {
- $numResultsToLog = min(count($results), pref_getServerPreference('logResults'));
+ $numResultsToLog = min(count($results), Config::get('global.logResults'));
$this->resultList = '';
for ($i = 0; $i < $numResultsToLog; $i++) {
$this->resultList .= ($this->resultList ? ',' : '') . $results[$i]->id;
@@ -56,11 +56,11 @@
return false;
}
try {
- $f = fopen(pref_getServerPreference('logPath'), 'at');
+ $f = fopen(Config::get('global.logPath'), 'at');
}
catch (Exception $e) {
try {
- $f = fopen(pref_getServerPreference('logPath'), 'wt');
+ $f = fopen(Config::get('global.logPath'), 'wt');
}
catch (Exception $e) {
throw new Exception('Error trying to access the log file', -1, $e);
Modified: phplib/SmartyWrap.php
==============================================================================
--- phplib/SmartyWrap.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/SmartyWrap.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -13,13 +13,13 @@
self::assign('imgRoot', util_getImgRoot());
self::assign('sources', Model::factory('Source')->order_by_desc('isOfficial')->order_by_asc('displayOrder')->find_many());
self::assign('sUser', session_getUser());
- self::assign('is_mirror', pref_isMirror());
+ self::assign('is_mirror', Config::get('global.mirror'));
self::assign('nick', session_getUserNick());
- self::assign('contact_email', pref_getContactEmail());
- self::assign('hostedBy', pref_getHostedBy());
+ self::assign('contact_email', Config::get('global.contact'));
+ self::assign('hostedBy', Config::get('global.hostedBy'));
self::assign('currentYear', date("Y"));
- self::assign('bannerType', pref_getServerPreference('bannerType'));
- self::assign('developmentMode', pref_getServerPreference('developmentMode'));
+ self::assign('bannerType', Config::get('global.bannerType'));
+ self::assign('developmentMode', Config::get('global.developmentMode'));
self::assign('isMobile', util_isMobile());
self::assign('suggestNoBanner', util_suggestNoBanner());
self::assign('GLOBALS', $GLOBALS);
@@ -37,7 +37,7 @@
// Set some skin variables based on the skin preferences in the config file.
// Also assign some skin-specific variables so we don't compute them unless we need them
- $skinVariables = session_getSkinPreferences($skin);
+ $skinVariables = Config::getSection("skin-{$skin}");
switch ($skin) {
case 'zepu':
$skinVariables['afterSearchBoxBanner'] = true;
Modified: phplib/ads/adsModule.php
==============================================================================
--- phplib/ads/adsModule.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/ads/adsModule.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -10,7 +10,7 @@
abstract public function run($lexems, $definitions);
public static function runAllModules($lexems, $definitions) {
- $adsModules = pref_getServerPreference('adsModulesH');
+ $adsModules = Config::get('global.adsModulesH');
if ($adsModules) {
foreach ($adsModules as $adsModule) {
require_once util_getRootPath() . "phplib/ads/{$adsModule}/{$adsModule}AdsModule.php";
Modified: phplib/db.php
==============================================================================
--- phplib/db.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/db.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -1,11 +1,11 @@
<?php
function db_init() {
- $functestFile = pref_getSectionPreference('functest', 'functestLockFile');
+ $functestFile = Config::get('functest.functestLockFile');
if ($functestFile && file_exists($functestFile)) {
- $dsn = pref_getSectionPreference('functest', 'functestDatabase');
+ $dsn = Config::get('functest.functestDatabase');
} else {
- $dsn = pref_getServerPreference('database');
+ $dsn = Config::get('global.database');
}
$parts = db_splitDsn($dsn);
ORM::configure(sprintf("mysql:host=%s;dbname=%s", $parts['host'], $parts['database']));
@@ -32,7 +32,7 @@
* This function allows us to do that until we upgrade to PHP 5.4.
**/
function db_executeFromOS($query) {
- $dsn = pref_getServerPreference('database');
+ $dsn = Config::get('global.database');
$parts = db_splitDsn($dsn);
$command = sprintf("mysql -u %s %s %s -e \"{$query}\"",
$parts['user'],
@@ -53,7 +53,7 @@
function db_splitDsn($dsn = null) {
$result = array();
if (!$dsn) {
- $dsn = pref_getServerPreference('database');
+ $dsn = Config::get('global.database');
}
$prefix = 'mysql://';
assert(StringUtil::startsWith($dsn, $prefix));
Modified: phplib/memcache.php
==============================================================================
--- phplib/memcache.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/memcache.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -17,7 +17,7 @@
* We don't want it for moderators because they are the ones who can alter the results and we want them to see the changes right away.
*/
function mc_shouldUse() {
- return pref_getServerPreference('memcache') && !util_isModerator(PRIV_EDIT);
+ return Config::get('global.memcache') && !util_isModerator(PRIV_EDIT);
}
function mc_get($key) {
Deleted: phplib/serverPreferences.php
==============================================================================
--- phplib/serverPreferences.php Mon Oct 21 12:30:37 2013 (r1025)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,93 +0,0 @@
-<?php
-/**
- * Handles Java-style property files. If a property contains URL-style parameters (var=value1&var2=value2&...),
- * we parse_str it and map the property name to the resulting associative array.
- */
-pref_parsePreferenceFile();
-
-function pref_parsePreferenceFile() {
- $raw = parse_ini_file(util_getRootPath() . "dex.conf", true);
- _pref_traverseRecursivePreferences($raw);
- $GLOBALS['serverPreferences'] = $raw;
-}
-
-function _pref_traverseRecursivePreferences(&$pref) {
- foreach ($pref as $key => $value) {
- if (is_array($value)) {
- _pref_traverseRecursivePreferences($value);
- $pref[$key] = $value;
- } else {
- $pref[$key] = (strpos($value, '&') === false) ? $value : StringUtil::parseStr($value);
- }
- }
-}
-
-function pref_getServerPreference($name) {
- if (array_key_exists('global', $GLOBALS['serverPreferences']) && array_key_exists($name, $GLOBALS['serverPreferences']['global'])) {
- return $GLOBALS['serverPreferences']['global'][$name];
- } else if (array_key_exists($name, $GLOBALS['serverPreferences'])) {
- // DEPRECATED. Python requires all INI file options to be contained in sections
- // We don't mind that, but we offer a fallback until people upgrade to the new config.
- return $GLOBALS['serverPreferences'][$name];
- } else {
- return false;
- }
-}
-
-function pref_getSectionPreference($section, $name, $defaultValue = NULL) {
- if (array_key_exists($section, $GLOBALS['serverPreferences']) && array_key_exists($name, $GLOBALS['serverPreferences'][$section])) {
- return $GLOBALS['serverPreferences'][$section][$name];
- }
- else if (!is_null($defaultValue)) {
- return $defaultValue;
- } else {
- return false;
- }
-}
-
-function pref_isMirror() {
- return pref_getServerPreference('mirror');
-}
-
-function pref_getLocPrefix() {
- return pref_getServerPreference('mysql_loc_prefix');
-}
-
-function pref_getContactEmail() {
- return pref_getServerPreference('contact');
-}
-
-function pref_getDebugUser() {
- return pref_getServerPreference('debugUser');
-}
-
-function pref_getMaxBookmarks() {
- return pref_getServerPreference('maxBookmarks');
-}
-
-function pref_getHostedBy() {
- return pref_getServerPreference('hostedBy');
-}
-
-function pref_getLocVersions() {
- if (!array_key_exists('locVersions', $GLOBALS)) {
- $result = array();
- $locParts = pref_getServerPreference('locVersions');
- foreach ($locParts as $part) {
- $part = trim($part);
- if ($part) {
- $versionAndDate = preg_split('/ /', $part);
- assert(count($versionAndDate == 2));
- $lv = new LocVersion();
- $lv->name = trim($versionAndDate[0]);
- $date = trim($versionAndDate[1]);
- $lv->freezeTimestamp = ($date == 'current') ? null : strtotime($date);
- $result[] = $lv;
- }
- }
- $GLOBALS['locVersions'] = array_reverse($result);
- }
- return $GLOBALS['locVersions'];
-}
-
-?>
Modified: phplib/session.php
==============================================================================
--- phplib/session.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/session.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -163,13 +163,13 @@
if ($skin && session_isValidSkin($skin)) {
return $skin;
} else {
- $skins = pref_getServerPreference('skins');
+ $skins = Config::get('global.skins');
return $skins[0];
}
}
function session_setSkin($skin) {
- $skins = pref_getServerPreference('skins');
+ $skins = Config::get('global.skins');
$defaultSkin = $skins[0];
if ($skin == $defaultSkin) {
// Clear the cookie instead of setting it to the default skin.
@@ -180,16 +180,7 @@
}
function session_isValidSkin($skin) {
- return in_array($skin, pref_getServerPreference('skins'));
-}
-
-/**
- * Returns an array of the skin-specific preferences defined in the section skin-{$skin}.
- * Returns an empty array if the section is not defined. Never returns false/null.
- **/
-function session_getSkinPreferences($skin) {
- $prefs = pref_getServerPreference("skin-{$skin}");
- return $prefs ? $prefs : array();
+ return in_array($skin, Config::get('global.skins'));
}
function session_setSourceCookie($source) {
Modified: phplib/util.php
==============================================================================
--- phplib/util.php Mon Oct 21 10:58:30 2013 (r1025)
+++ phplib/util.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -25,8 +25,6 @@
// smarty < session_start/end : smarty caches the person's nickname.
util_defineRootPath();
util_defineWwwRoot();
- // At this point the server preferences are loaded (when
- // util_requireOtherFiles() includes serverPreferences.php)
util_requireOtherFiles();
util_defineConstants();
db_init();
@@ -91,7 +89,6 @@
require_once("$root/phplib/smarty/Smarty.class.php");
require_once("$root/phplib/idiorm/idiorm.php");
require_once("$root/phplib/idiorm/paris.php");
- require_once("$root/phplib/serverPreferences.php");
require_once("$root/phplib/db.php");
require_once("$root/phplib/logging.php");
require_once("$root/phplib/session.php");
@@ -163,7 +160,7 @@
//Limits
define('DEFAULT_LIMIT_FULLTEXT', 500);
- define('LIMIT_FULLTEXT_DISPLAY', pref_getSectionPreference('limits', 'limitFulltextSearch', DEFAULT_LIMIT_FULLTEXT));
+ define('LIMIT_FULLTEXT_DISPLAY', Config::get('limits.limitFulltextSearch', DEFAULT_LIMIT_FULLTEXT));
}
function util_getAllStatuses() {
@@ -299,7 +296,7 @@
}
function util_assertNotMirror() {
- if (pref_isMirror()) {
+ if (Config::get('global.mirror')) {
SmartyWrap::displayWithoutSkin('common/mirror_message.ihtml');
exit;
}
Modified: tools/freezeLocVersion.php
==============================================================================
--- tools/freezeLocVersion.php Mon Oct 21 10:58:30 2013 (r1025)
+++ tools/freezeLocVersion.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -1,14 +1,14 @@
<?php
require_once __DIR__ . '/../phplib/util.php';
-$lvs = array_reverse(pref_getLocVersions());
+$lvs = array_reverse(Config::getLocVersions());
if (count($lvs) < 2) {
die("ERROR: You need at least two LOC versions in dex.conf: " .
"one that indicates the version to be frozen and " .
"one to indicate the next current version.\n");
}
-$locDbPrefix = pref_getLocPrefix();
+$locDbPrefix = Config::get('global.mysql_loc_prefix');
if (!$locDbPrefix) {
die("ERROR: You forgot to define mysql_loc_prefix in dex.conf.\n");
}
Modified: tools/rebuildScrabbleForms.php
==============================================================================
--- tools/rebuildScrabbleForms.php Mon Oct 21 10:58:30 2013 (r1025)
+++ tools/rebuildScrabbleForms.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -12,7 +12,7 @@
$opts = getopt('a');
$allVersions = array_key_exists('a', $opts);
-foreach (pref_getLocVersions() as $version) {
+foreach (Config::getLocVersions() as $version) {
if (!$version->freezeTimestamp || $allVersions) {
log_scriptLog("dumping version {$version->name}");
LocVersion::changeDatabase($version->name);
Modified: wwwbase/ajax/bookmarkAdd.php
==============================================================================
--- wwwbase/ajax/bookmarkAdd.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/ajax/bookmarkAdd.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -15,7 +15,7 @@
}
$bookmarks = UserWordBookmarkDisplayObject::getByUser($userId);
-if (count($bookmarks) < pref_getMaxBookmarks()) {
+if (count($bookmarks) < Config::get('global.maxBookmarks')) {
$existing = Model::factory('UserWordBookmark')->where('userId', $userId)->where('definitionId', $definitionId)->find_one();
if (!$existing) {
@@ -29,7 +29,7 @@
$response['status'] = 'success';
} else {
$response['status'] = 'error';
- $response['msg'] = 'Ați depășit limita de cuvinte favorite. Limita este ' . pref_getMaxBookmarks() . ' cuvinte favorite.';
+ $response['msg'] = 'Ați depășit limita de cuvinte favorite. Limita este ' . Config::get('global.maxBookmarks') . ' cuvinte favorite.';
}
echo json_encode($response);
Modified: wwwbase/ajax/fetchCrawlerStatus.php
==============================================================================
--- wwwbase/ajax/fetchCrawlerStatus.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/ajax/fetchCrawlerStatus.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -4,14 +4,8 @@
* alyn.cti at gmail.com
*/
require_once '../../phplib/util.php';
-require_once '../../phplib/serverPreferences.php';
-require_once '../../phplib/db.php';
-require_once '../../phplib/idiorm/idiorm.php';
-require_once '../../phplib/idiorm/paris.php';
-
class FetchCrawlerStatus {
-
function getStatusPerHttpCode($domain = null) {
Modified: wwwbase/auth/parola-uitata.php
==============================================================================
--- wwwbase/auth/parola-uitata.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/auth/parola-uitata.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -32,7 +32,7 @@
SmartyWrap::assign('homePage', util_getFullServerUrl());
SmartyWrap::assign('token', $pt->token);
$body = SmartyWrap::fetch('email/resetPassword.ihtml');
- $ourEmail = pref_getContactEmail();
+ $ourEmail = Config::get('global.contact');
$result = mail($email, "Schimbarea parolei pentru DEX online", $body, "From: DEX online <$ourEmail>\r\nReply-To: $ourEmail");
// Display a confirmation even for incorrect addresses.
Modified: wwwbase/diacritice.php
==============================================================================
--- wwwbase/diacritice.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/diacritice.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -1,18 +1,13 @@
<?php
require_once '../phplib/util.php';
-require_once '../phplib/serverPreferences.php';
-require_once '../phplib/db.php';
-require_once '../phplib/idiorm/idiorm.php';
-require_once '../phplib/idiorm/paris.php';
-
require_once 'Crawler/AppLog.php';
require_once 'Crawler/MemoryManagement.php';
db_init();
-$logFile = pref_getSectionPreference('crawler', 'diacritics_log');
+$logFile = Config::get('crawler.diacritics_log');
class DiacriticsFixer {
@@ -44,11 +39,11 @@
function __construct() {
crawlerLog("INSIDE " . __FILE__ . ' - ' . __CLASS__ . '::' . __FUNCTION__ . '() - ' . 'line '.__LINE__ );
- self::$diacritics = pref_getSectionPreference("crawler", "diacritics");
- self::$nonLowerDiacritics = pref_getSectionPreference("crawler", "non_lower_diacritics");
+ self::$diacritics = Config::get("crawler.diacritics");
+ self::$nonLowerDiacritics = Config::get("crawler.non_lower_diacritics");
self::$nonUpperDiacritics = mb_strtoupper(self::$nonLowerDiacritics);
- self::$paddingNumber = pref_getSectionPreference('crawler', 'diacritics_padding_length');
- self::$paddingChar = pref_getSectionPreference('crawler', 'padding_char');
+ self::$paddingNumber = Config::get('crawler.diacritics_padding_length');
+ self::$paddingChar = Config::get('crawler.padding_char');
$this->selectCount = 0;
}
@@ -103,9 +98,9 @@
public function fix($text) {
crawlerLog("INSIDE " . __FILE__ . ' - ' . __CLASS__ . '::' . __FUNCTION__ . '() - ' . 'line '.__LINE__ );
- if (mb_strlen($text) > pref_getSectionPreference('crawler', 'diacritics_buffer_limit')) {
+ if (mb_strlen($text) > Config::get('crawler.diacritics_buffer_limit')) {
return "Dimensiune text prea mare, limita este de " .
- pref_getSectionPreference('crawler', 'diacritics_buffer_limit') . ' de caractere';
+ Config::get('crawler.diacritics_buffer_limit') . ' de caractere';
}
$this->processText($text);
return $this->text2Html($this->resultText);
Modified: wwwbase/doneaza-euplatesc.php
==============================================================================
--- wwwbase/doneaza-euplatesc.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/doneaza-euplatesc.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -5,8 +5,8 @@
**/
require_once("../phplib/util.php");
-$mid = pref_getSectionPreference('euplatesc', 'euPlatescMid');
-$key = pref_getSectionPreference('euplatesc', 'euPlatescKey');
+$mid = Config::get('euplatesc.euPlatescMid');
+$key = Config::get('euplatesc.euPlatescKey');
require_once("../phplib/euplatesc.php");
?>
Modified: wwwbase/doneaza.php
==============================================================================
--- wwwbase/doneaza.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/doneaza.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -2,7 +2,7 @@
require_once("../phplib/util.php");
$user = session_getUser();
-$haveEuPlatescCredentials = pref_getSectionPreference('euplatesc', 'euPlatescMid') && pref_getSectionPreference('euplatesc', 'euPlatescKey');
+$haveEuPlatescCredentials = Config::get('euplatesc.euPlatescMid') && Config::get('euplatesc.euPlatescKey');
SmartyWrap::assign('page_title', 'Sprijină dexonline!');
SmartyWrap::assign('suggestHiddenSearchForm', true);
Modified: wwwbase/modele-flexiune.php
==============================================================================
--- wwwbase/modele-flexiune.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/modele-flexiune.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -7,7 +7,7 @@
$modelType = util_getRequestParameter('modelType');
$modelNumber = util_getRequestParameter('modelNumber');
-$locVersions = pref_getLocVersions();
+$locVersions = Config::getLocVersions();
$modelType = ModelType::get_by_code($modelType); // Use the ModelType object from this point on
if ($locVersion && $modelType && $modelNumber) {
Modified: wwwbase/preferinte.php
==============================================================================
--- wwwbase/preferinte.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/preferinte.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -23,7 +23,7 @@
SmartyWrap::assign('detailsVisible', $detailsVisible);
SmartyWrap::assign('userPrefs', $userPrefs);
SmartyWrap::assign('skin', $skin);
-SmartyWrap::assign('availableSkins', pref_getServerPreference('skins'));
+SmartyWrap::assign('availableSkins', Config::get('global.skins'));
SmartyWrap::assign('privilegeNames', $PRIV_NAMES);
SmartyWrap::assign('widgets', $widgets);
SmartyWrap::assign('userHasAvatar', util_userHasAvatar());
Modified: wwwbase/scrabble-flexiune.php
==============================================================================
--- wwwbase/scrabble-flexiune.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/scrabble-flexiune.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -3,7 +3,7 @@
$form = util_getRequestParameter('form');
$locVersion = util_getRequestParameter('locVersion');
-$locVersions = pref_getLocVersions();
+$locVersions = Config::getLocVersions();
if ($locVersion && $form) {
LocVersion::changeDatabase($locVersion);
Modified: wwwbase/scrabble-forme.php
==============================================================================
--- wwwbase/scrabble-forme.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/scrabble-forme.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -2,7 +2,7 @@
require_once("../phplib/util.php");
SmartyWrap::assign('page_title', 'Liste de forme pentru Scrabble');
-SmartyWrap::assign('locVersions', pref_getLocVersions());
+SmartyWrap::assign('locVersions', Config::getLocVersions());
SmartyWrap::displayCommonPageWithSkin('scrabble-forme.ihtml');
?>
Modified: wwwbase/scrabble-loc.php
==============================================================================
--- wwwbase/scrabble-loc.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/scrabble-loc.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -39,7 +39,7 @@
}
setlocale(LC_ALL, "ro_RO.utf8");
-SmartyWrap::assign('locVersions', pref_getLocVersions());
+SmartyWrap::assign('locVersions', Config::getLocVersions());
SmartyWrap::displayCommonPageWithSkin('scrabble-loc.ihtml');
function writeLexems($locVersion, $fileName) {
Modified: wwwbase/search.php
==============================================================================
--- wwwbase/search.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/search.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -235,7 +235,7 @@
}
}
-if (pref_getServerPreference('logSearch')) {
+if (Config::get('global.logSearch')) {
$logDefinitions = isset($definitions) ? $definitions : array();
$log = new Log($cuv, $redirectFrom, $searchType, $redirect, $logDefinitions);
$log->logData();
Modified: wwwbase/siteClones.php
==============================================================================
--- wwwbase/siteClones.php Mon Oct 21 10:58:30 2013 (r1025)
+++ wwwbase/siteClones.php Mon Oct 21 12:30:37 2013 (r1026)
@@ -27,7 +27,7 @@
array_pad( array(), 14 ,'') ,$to_search) ;
$urlGoogle = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0";
-$apiKey = pref_getServerPreference('googleSearchApiKey');
+$apiKey = Config::get('global.googleSearchApiKey');
$url = $urlGoogle . "&q=". urlencode($to_search) . "&key=" . $apiKey;
More information about the Dev
mailing list