filemtime($filename)) { return $output_filename; } } // Load the XML lang file. $xml = @simplexml_load_file($filename); if ($xml === false) { \FileHandler::writeFile($output_filename, ''); return false; } // Convert XML to a PHP array. $lang = array(); self::_toArray($xml, $lang, $language); unset($xml); // Save the array as a cache file. $buff = " $value) { if (is_array($value)) { foreach ($value as $subkey => $subvalue) { if (is_array($subvalue)) { foreach ($subvalue as $subsubkey => $subsubvalue) { $buff .= '$lang->' . $key . "['$subkey']['$subsubkey']" . ' = ' . var_export($subsubvalue, true) . ";\n"; } } else { $buff .= '$lang->' . $key . "['$subkey']" . ' = ' . var_export($subvalue, true) . ";\n"; } } } else { $buff .= '$lang->' . $key . ' = ' . var_export($value, true) . ";\n"; } } \FileHandler::writeFile($output_filename, $buff); return $output_filename; } /** * XML to array conversion callback. * * @param array $items * @return void */ protected static function _toArray($items, &$lang, $language) { foreach ($items as $item) { $name = strval($item['name']); if (count($item->item)) { $lang[$name] = array(); self::_toArray($item->item, $lang[$name], $language); } else { foreach ($item->value as $value) { $attribs = $value->attributes('xml', true); if (strval($attribs['lang']) === $language) { $lang[$name] = strval($value); break; } } } } } }