[Phpfreechat-svn] SF.net SVN: phpfreechat: [955] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2007-02-15 11:29:18
|
Revision: 955 http://svn.sourceforge.net/phpfreechat/?rev=955&view=rev Author: kerphi Date: 2007-02-15 03:29:18 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Optimizations : - pfcI18N::GetAcceptedLanguage function was very slow - pfcGlobaConfig::pfcGlobalConfig has some useless code which was repeted at each call Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/pfci18n.class.php Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-02-15 11:14:53 UTC (rev 954) +++ trunk/src/pfcglobalconfig.class.php 2007-02-15 11:29:18 UTC (rev 955) @@ -129,47 +129,43 @@ var $debugurl = ""; var $debug = false; var $debugxajax = false; - + // private parameters - var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); - var $_proxies = array(); // will contains proxies to execute on each command (filled in the init step) + var $_sys_proxies = array("lock", "checktimeout", "checknickchange", "auth", "noflood", "censor", "log"); + var $_proxies = array(); // will contains proxies to execute on each command (filled in the init step) var $_dyn_params = array("nick","isadmin","islocked","admins","frozen_channels", "channels", "privmsg", "nickmeta","baseurl"); var $_params_type = array(); function pfcGlobalConfig( $params = array() ) - { - // first of all, save our current state in order to be able to check for variable types later - $this->_saveParamsTypes(); - + { // setup the local for translated messages pfcI18N::Init(isset($params["language"]) ? $params["language"] : ""); - + // check the serverid is really defined if (!isset($params["serverid"])) $this->errors[] = _pfc("'%s' parameter is mandatory by default use '%s' value", "serverid", "md5(__FILE__)"); $this->serverid = $params["serverid"]; - // _getCacheFile needs data_private_path + // setup data_private_path because _getCacheFile needs it if (!isset($params["data_private_path"])) $this->data_private_path = dirname(__FILE__)."/../data/private"; else $this->data_private_path = $params["data_private_path"]; - if (!isset($params["data_public_path"])) - $this->data_public_path = dirname(__FILE__)."/../data/public"; - else - $this->data_public_path = $params["data_public_path"]; - /* - // delete the cache if no proxy.php file is found - if (!file_exists($this->_getProxyFile())) - @unlink($this->_getCacheFile()); - */ - + // check if a cached configuration allready exists // don't load parameters if the cache exists $cachefile = $this->_getCacheFile(); if (!file_exists($cachefile)) { + // first of all, save our current state in order to be able to check for variable types later + $this->_saveParamsTypes(); + + if (!isset($params["data_public_path"])) + $this->data_public_path = dirname(__FILE__)."/../data/public"; + else + $this->data_public_path = $params["data_public_path"]; + // load users container or keep default one if (isset($params["container_type"])) $this->container_type = $params["container_type"]; @@ -212,7 +208,7 @@ // load dynamic parameter even if the config exists in the cache foreach ( $this->_dyn_params as $dp ) if (isset($params[$dp])) - $this->$dp = $params[$dp]; + $this->$dp = $params[$dp]; // 'channels' is now a dynamic parameter, just check if I need to initialize it or not if (is_array($this->channels) && @@ -498,7 +494,7 @@ // load version number from file $this->version = trim(file_get_contents(dirname(__FILE__)."/../version")); - + $this->is_init = (count($this->errors) == 0); } @@ -586,7 +582,7 @@ foreach($pfc_configvar as $key => $val) { // the dynamics parameters must not be cached - if (!in_array($key,$this->_dyn_params)) + if (!isset($this->_dyn_params[$key])) $this->$key = $val; } Modified: trunk/src/pfci18n.class.php =================================================================== --- trunk/src/pfci18n.class.php 2007-02-15 11:14:53 UTC (rev 954) +++ trunk/src/pfci18n.class.php 2007-02-15 11:29:18 UTC (rev 955) @@ -97,37 +97,7 @@ */ function GetAcceptedLanguage($type="main") { - if ($type=="admin"){ - if (isset($GLOBALS["accepted_admin_languages"])) - return $GLOBALS["accepted_admin_languages"]; // restore the cached languages list - $GLOBALS["accepted_admin_languages"] = array(); - $dir_handle = opendir(dirname(__FILE__)."/../i18n"); - while (false !== ($file = readdir($dir_handle))) - { - // skip . and .. generic files - // skip also .svn directory - if ($file == "." || $file == ".." || strpos($file,".")===0) continue; - if (file_exists(dirname(__FILE__)."/../i18n/".$file."/admin.php")) - $GLOBALS["accepted_admin_languages"][] = $file; - } - closedir($dir_handle); - return $GLOBALS["accepted_admin_languages"]; - } - else{ - if (isset($GLOBALS["accepted_languages"])) - return $GLOBALS["accepted_languages"]; // restore the cached languages list - $GLOBALS["accepted_languages"] = array(); - $dir_handle = opendir(dirname(__FILE__)."/../i18n"); - while (false !== ($file = readdir($dir_handle))) - { - // skip . and .. generic files - // skip also .svn directory - if ($file == "." || $file == ".." || strpos($file,".")===0) continue; - $GLOBALS["accepted_languages"][] = $file; - } - closedir($dir_handle); - return $GLOBALS["accepted_languages"]; - } + return /*<GetAcceptedLanguage>*/array('ar_LB','bg_BG','de_DE-formal','el_GR','eo','fr_FR','hy_AM','it_IT','ko_KR','nl_NL', 'pt_BR','ru_RU','sv_SE','uk_RO','zh_CN','ba_BA','bn_BD','de_DE-informal','en_US','es_ES','hu_HU','id_ID','ja_JP','nb_NO','pl_PL','pt_PT','sr_CS','tr_TR','uk_UA','zh_TW');/*</GetAcceptedLanguage>*/ } /** @@ -135,6 +105,24 @@ */ function UpdateMessageRessources() { + // first of all, update the GetAcceptedLanguage list + $i18n_basepath = dirname(__FILE__).'/../i18n'; + $i18n_accepted_lang = array(); + $dh = opendir($i18n_basepath); + while (false !== ($file = readdir($dh))) + { + // skip . and .. generic files, skip also .svn directory + if ($file == "." || $file == ".." || strpos($file,".")===0) continue; + if (file_exists($i18n_basepath.'/'.$file.'/main.php')) $i18n_accepted_lang[] = $file; + } + closedir($dh); + $i18n_accepted_lang_str = "array('" . implode("','", $i18n_accepted_lang) . "');"; + $data = file_get_contents(__FILE__); + $data = preg_replace("/\/\*<GetAcceptedLanguage>\*\/(.*)\/\*<\/GetAcceptedLanguage>\*\//", + "/*<GetAcceptedLanguage>*/$i18n_accepted_lang_str/*</GetAcceptedLanguage>*/", + $data); + + // Now scan the source code in order to find "_pfc" patterns $files = array(); $files = array_merge($files, glob(dirname(__FILE__)."/*.php")); $files = array_merge($files, glob(dirname(__FILE__)."/commands/*.php")); @@ -142,7 +130,6 @@ $files = array_merge($files, glob(dirname(__FILE__)."/proxies/*.php")); $files = array_merge($files, glob(dirname(__FILE__)."/client/*.php")); $files = array_merge($files, glob(dirname(__FILE__)."/../themes/default/*.php")); - $res = array(); foreach ( $files as $src_filename ) { @@ -170,7 +157,7 @@ } $dst_filenames = array(); - foreach(pfcI18N::GetAcceptedLanguage() as $lg) + foreach($i18n_accepted_lang as $lg) $dst_filenames[] = dirname(__FILE__)."/../i18n/".$lg."/main.php"; foreach( $dst_filenames as $dst_filename ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |