2) { // we have some stuff we need to sprintf array_shift($variables); array_shift($variables); //shift off the first two. } else { $variables = array(); } $lang = current_language(); if ($section == '') { $section = 'mahara'; } // Define the locations of language strings for this section $libroot = get_config('libroot'); $docroot = get_config('docroot'); $locations = array(); if ($section == 'mahara' || $section != 'langconfig') { $locations[] = $libroot.'lang/'; } else { $extras = array('artefacts','auth'); // more later.. foreach ($extras as $tocheck) { if (strpos($section,$tocheck.'.') === 0) { $pluginname = substr($section,strlen($tocheck)); $locations[] = $docroot.$tocheck.'/'.$pluginname.'/lang/'; } } } // First check all the normal locations for the string in the current language foreach ($locations as $location) { //if local directory not found, or particular string does not exist in local direcotry $langfile = $location.$lang.'/'.$section.'.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile)) { return format_langstring($result,$variables); } } } // If the preferred language was English (utf8) we can abort now // saving some checks beacuse it's the only "root" lang if ($lang == 'en.utf8') { return '[['. $identifier .']]'; } // Is a parent language defined? If so, try to find this string in a parent language file foreach ($locations as $location) { $langfile = $location.$lang.'/langconfig.php'; if (file_exists($langfile)) { if ($parentlang = get_string_from_file('parentlanguage', $langfile)) { $langfile = $location.$parentlang.'/'.$section.'.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile)) { return format_langstring($result,$variables); } } } } } /// Our only remaining option is to try English foreach ($locations as $location) { //if local_en not found, or string not found in local_en $langfile = $location.'en.utf8/'.$module.'.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile)) { return format_langstring($result,$variables); } } } return '[['.$identifier.']]'; // Last resort } /** * This function is only used from {@link get_string()}. * * @internal Only used from get_string, not meant to be public API * @param string $identifier ? * @param string $langfile ? * @param string $destination ? * @return string|false ? * @staticvar array $strings Localized strings * @access private * @todo Finish documenting this function. */ function get_string_from_file($identifier, $langfile) { static $strings; // Keep the strings cached in memory. if (empty($strings[$langfile])) { $string = array(); include ($langfile); $strings[$langfile] = $string; } else { $string = &$strings[$langfile]; } if (!isset ($string[$identifier])) { return false; } return $string[$identifier]; } /** * This function makes the return value of ini_get consistent if you are * setting server directives through the .htaccess file in apache. * Current behavior for value set from php.ini On = 1, Off = [blank] * Current behavior for value set from .htaccess On = On, Off = Off * Contributed by jdell @ unr.edu * * @param string $ini_get_arg setting to look for * @return bool */ function ini_get_bool($ini_get_arg) { $temp = ini_get($ini_get_arg); if ($temp == '1' or strtolower($temp) == 'on') { return true; } return false; } /* * This function returns a value from $CFG * or null if it is not found * * @param string $key config setting to look for * @return mixed */ function get_config($key) { global $CFG; if (array_key_exists($key,$CFG)) { return $CFG->$key; } return null; } /** * This function prints an array or object * wrapped inside

 * 
 * @param $mixed value to print
 */
function print_object($mixed) {
    echo '
';
    print_r($mixed);
    echo '
'; } /** * This function returns the current * language to use, either for a given user * or sitewide, or the default * * @return string */ function current_language() { global $USER, $CFG; if (!empty($USER->lang)) { return $USER->lang; } if (!empty($CFG->lang)) { return $CFG->lang; } return 'en.utf8'; } /** * Helper function to sprintf language strings * with a variable number of arguments * * @param string $string raw string to use * @param array $args arguments to sprintf */ function format_langstring($string,$args) { return call_user_func_array('sprintf',array_merge(array($string),$args)); } /** * Helper function to figure out whether an array is an array or a hash * @param array $array array to check * @return bool true if the array is a hash */ function is_hash($array) { if (!is_array($array)) { return false; } $diff = array_diff_assoc($array,array_values($array)); return !empty($diff); } ?>