Merged from MOODLE_14_STABLE. Added option to cache langlist in dataroot/cache/languages. If enabled saves around 10MB of memory and 40 includes (some really large). In HEAD we also get a nice option select in admin->variables.

This commit is contained in:
martinlanghoff 2005-04-11 06:41:08 +00:00
parent e170f66546
commit 6e6053bd18
2 changed files with 28 additions and 0 deletions

View File

@ -118,6 +118,11 @@
}
flush();
if (!empty($CFG->langcache)) {
get_list_of_languages();
}
flush();
if (!empty($CFG->notifyloginfailures)) {
notify_login_failures();
}

View File

@ -4161,6 +4161,20 @@ function get_list_of_languages() {
$languages = array();
if ( (!defined('FULLME') || FULLME !== 'cron')
&& !empty($CFG->langcache) && file_exists($CFG->dataroot .'/cache/languages')) {
// read from cache
$lines = file($CFG->dataroot .'/cache/languages');
foreach ($lines as $line) {
$line = trim($line);
if (preg_match('/^(\w+)\s+(.+)/', $line, $matches)) {
$languages[$matches[1]] = $matches[2];
}
}
unset($lines); unset($line); unset($matches);
return $languages;
}
if (!empty($CFG->langlist)) { // use admin's list of languages
$langlist = explode(',', $CFG->langlist);
foreach ($langlist as $lang) {
@ -4180,6 +4194,15 @@ function get_list_of_languages() {
unset($string);
}
}
if ( defined('FULLME') && FULLME === 'cron' && !empty($CFG->langcache)) {
if ($file = fopen($CFG->dataroot .'/cache/languages', 'w')) {
foreach ($languages as $key => $value) {
fwrite($file, "$key $value\n");
}
fclose($file);
}
}
return $languages;
}