Skip to content

Commit

Permalink
Optimizations :
Browse files Browse the repository at this point in the history
- pfcI18N::GetAcceptedLanguage function was very slow
- pfcGlobaConfig::pfcGlobalConfig has some useless code which was repeted at each call


git-svn-id: https://phpfreechat.svn.sourceforge.net/svnroot/phpfreechat/trunk@955 2772adf2-ac07-0410-9d30-e29d8120292e
  • Loading branch information
kerphi committed Feb 15, 2007
1 parent 51ceb63 commit 02f3a69
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 55 deletions.
40 changes: 18 additions & 22 deletions src/pfcglobalconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,47 +129,43 @@ class pfcGlobalConfig
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"];
Expand Down Expand Up @@ -212,7 +208,7 @@ function pfcGlobalConfig( $params = array() )
// 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) &&
Expand Down Expand Up @@ -498,7 +494,7 @@ function init()

// load version number from file
$this->version = trim(file_get_contents(dirname(__FILE__)."/../version"));

$this->is_init = (count($this->errors) == 0);
}

Expand Down Expand Up @@ -586,7 +582,7 @@ function synchronizeWithCache()
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;
}

Expand Down
53 changes: 20 additions & 33 deletions src/pfci18n.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,52 +97,39 @@ function GetDefaultLanguage()
*/
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>*/
}

/**
* Parse the source-code and update the i18n ressources files
*/
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"));
$files = array_merge($files, glob(dirname(__FILE__)."/containers/*.php"));
$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 )
{
Expand Down Expand Up @@ -170,7 +157,7 @@ function UpdateMessageRessources()
}

$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 )
Expand Down

0 comments on commit 02f3a69

Please sign in to comment.