Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.960.2.15 diff -u -r1.960.2.15 moodlelib.php --- lib/moodlelib.php 4 Dec 2007 11:46:12 -0000 1.960.2.15 +++ lib/moodlelib.php 6 Dec 2007 15:45:06 -0000 @@ -5019,7 +5019,7 @@ foreach ($locations as $location) { $locallangfile = $location.$lang.'_local'.'/'.$module.'.php'; //first, see if there's a local file if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5027,7 +5027,7 @@ //if local directory not found, or particular string does not exist in local direcotry $langfile = $location.$lang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5045,14 +5045,14 @@ foreach ($locations as $location) { $langfile = $location.$lang.'/'.$filetocheck; if (file_exists($langfile)) { - if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang")) { + if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang", $a)) { eval($result); if (!empty($parentlang)) { // found it! //first, see if there's a local file for parent $locallangfile = $location.$parentlang.'_local'.'/'.$module.'.php'; if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5061,7 +5061,7 @@ //if local directory not found, or particular string does not exist in local direcotry $langfile = $location.$parentlang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5076,7 +5076,7 @@ foreach ($locations as $location) { $locallangfile = $location.$defaultlang.'_local/'.$module.'.php'; //first, see if there's a local file if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5086,7 +5086,7 @@ $langfile = $location.$defaultlang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5100,7 +5100,7 @@ foreach ($locations as $location) { $locallangfile = $location.$defaultlang.'_local/'.$module.'.php'; //first, see if there's a local file if (file_exists($locallangfile)) { - if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5110,7 +5110,7 @@ $langfile = $location.$defaultlang.'/'.$module.'.php'; if (file_exists($langfile)) { - if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { + if ($result = get_string_from_file($identifier, $langfile, "\$resultstring", $a)) { eval($result); return $resultstring; } @@ -5128,17 +5128,19 @@ * @param string $identifier ? * @param string $langfile ? * @param string $destination ? + * @param mixed $a Arbitrary parameter to get_string, used only for expressions * @return string|false ? * @staticvar array $strings Localized strings * @access private * @todo Finish documenting this function. */ -function get_string_from_file($identifier, $langfile, $destination) { +function get_string_from_file($identifier, $langfile, $destination, $a) { static $strings; // Keep the strings cached in memory. if (empty($strings[$langfile])) { $string = array(); + $string19 =& $string; include ($langfile); $strings[$langfile] = $string; } else { @@ -5148,8 +5150,28 @@ if (!isset ($string[$identifier])) { return false; } + + // When the string is actually an array, it should be an associative array + // where the keys are PHP expressions and values are language strings as + // normal. Expressions are tested in order and for the first matching one, + // the language string is returned. + if(is_array($string[$identifier])) { + $selectedstring=null; + foreach($string[$identifier] as $expression=>$value) { + if($expression==='' || eval("return $expression;")) { + $selectedstring=$value; + break; + } + } + if($selectedstring===null) { + debugging("No matching expression for language string $identifier"); + return false; + } + } else { + $selectedstring=$string[$identifier]; + } - return $destination .'= sprintf("'. $string[$identifier] .'");'; + return $destination .'= sprintf("'. $selectedstring .'");'; } /**