45 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
46 error_reporting(E_ALL);
54 if ((php_sapi_name() ==
'cli')) {
55 if (isset($_SERVER[
'argv'][1])) {
56 $SYSTEM_ROOT = $_SERVER[
'argv'][1];
58 $err_msg =
"You need to supply the path to the System Root as the first argument\n";
62 <div style="background-color: red; color: white; font-weight: bold;">
63 You can only run the '.$_SERVER[
'argv'][0].
' script from the command line
68 if (empty($SYSTEM_ROOT)) {
73 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
74 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
82 require_once
'Console/Getopt.php';
87 $con =
new Console_Getopt;
88 $args = $con->readPHPArgv();
90 $options = $con->getopt($args, $shortopt, $longopt);
92 if (is_array($options[0])) {
93 $opt_list = get_console_list($options[0]);
94 $locale_list = $opt_list[
'locale'];
99 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
101 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
104 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
105 echo
"Failed login in as root user\n";
110 require_once $SYSTEM_ROOT.
'/install/install.inc';
111 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
112 require_once
'XML/Tree.php';
114 if (empty($opt_list[
'dir'])) {
115 $opt_list[
'dir'] = SQ_SYSTEM_ROOT.
'/data/temp/locale_backup';
118 $file_list = Array();
119 $folder_list = Array(realpath($opt_list[
'dir']));
121 while(!empty($folder_list)) {
122 $folder = array_pop($folder_list);
123 $d = @opendir($folder);
127 while (
false !== ($entry = readdir($d))) {
128 if (($entry ==
'..') || ($entry ==
'.') || ($entry ==
'CVS'))
continue;
129 $file = $folder.
'/'.$entry;
132 if (is_dir($file) && $opt_list[
'recurse']) {
133 array_push($folder_list, $file);
138 if (substr($entry,-4) ==
'.xml') {
139 process_file(realpath($SYSTEM_ROOT), $file, $opt_list[
'force']);
163 function get_console_list($options)
172 foreach ($options as $option) {
174 if (!isset($option[0]))
continue;
178 if (!isset($option[1]))
continue;
180 $parts = explode(
'-', $option[1]);
183 if ((count($parts) == 2) && strlen($parts[1])) {
184 $types = explode(
',', $parts[1]);
186 $types = Array(
'all');
189 $list[
'locale'][$parts[0]] = $types;
193 if (!isset($option[1]))
continue;
194 $list[
'dir'] = $option[1];
198 $list[
'recurse'] =
true;
202 $list[
'force'] =
true;
220 function process_strings_file($path, $file)
222 bam(
'STRINGS '.$file);
224 $root = $xml_object->getTreeFromFile();
237 function process_internal_messages_file($path, $file)
239 bam(
'MESSAGES '.$file);
241 $root = $xml_object->getTreeFromFile();
254 function process_errors_file($path, $file)
256 bam(
'ERRORS '.$file);
258 $root = $xml_object->getTreeFromFile();
260 assert_equals($root->name,
'files');
261 echo $locale = $root->attributes[
'locale'];
262 for(reset($root->children); null !== ($file_index = key($root->children)); next($root->children)) {
263 $file_tag =& $root->children[$file_index];
264 $file_name = $path.
'/'.$file_tag->attributes[
'source'].
'/'.$locale.
'/lang_errors.xml';
267 create_directory($path.
'/'.$file_tag->attributes[
'source'].
'/'.$locale);
268 string_to_file($file_tag->children[0]->get(), $file_name);
283 function process_file($path, $file, $force)
285 $file_contents = file_get_contents($file);
286 preg_match(
'|<files locale="([^"]*)">.*</file>|s', $file_contents, $match);
290 $locale = str_replace(
'@',
'/', $locale);
291 $locale = str_replace(
'_',
'/', $locale);
295 preg_match_all(
'|<file source="([^"]*)" name="([^"]*)">(.*)</file>|Us', $file_contents, $matches, PREG_SET_ORDER);
296 foreach($matches as $match) {
297 $file_name = $path.
'/'.$match[1].
'/'.$locale.
'/'.$match[2];
298 $file_str =
'<?xml version="1.0" ?>'.
"\n".$match[3];
300 if (!file_exists($file_name)) {
308 echo
'Overwrite file '.hide_system_root($file_name).
'?';
309 $overwrite_confirm =
'';
310 while((strlen($overwrite_confirm) == 0) ||
311 ((strtolower($overwrite_confirm{0}) !=
'y') && strtolower($overwrite_confirm{0}) !=
'n')) {
312 $overwrite_confirm = rtrim(fgets(STDIN, 4094));
314 if (strtolower($overwrite_confirm{0}) ==
'y') {
321 create_directory($path.
'/'.$match[1].
'/'.$locale);
322 string_to_file($file_str, $file_name);
323 echo
'Wrote '.hide_system_root($file_name).
"\n";