28 ini_set(
'memory_limit', -1);
29 error_reporting(E_ALL);
37 if ((php_sapi_name() ==
'cli')) {
38 if (isset($_SERVER[
'argv'][1])) {
39 $SYSTEM_ROOT = $_SERVER[
'argv'][1];
41 $err_msg =
"ERROR: You need to supply the path to the System Root as the first argument\n";
45 <div style="background-color: red; color: white; font-weight: bold;">
46 You can only run the '.$_SERVER[
'argv'][0].
' script from the command line
51 if (empty($SYSTEM_ROOT)) {
52 $err_msg .=
"Usage: php install/step_03.php <PATH_TO_MATRIX>\n";
57 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
58 $err_msg =
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
59 $err_msg .=
"Usage: php install/step_03.php <PATH_TO_MATRIX>\n";
66 require_once
'Console/Getopt.php';
69 $longopt = Array(
'locale=');
71 $con =
new Console_Getopt;
72 $args = $con->readPHPArgv();
74 $options = $con->getopt($args, $shortopt, $longopt);
76 if (is_array($options[0])) {
77 $locale_list = get_console_list($options[0]);
82 if (empty($locale_list)) {
83 echo
"\nWARNING: You did not specify a --locale parameter. This is okay but be aware that all locales will be compiled, which may take a while if you have multiple locales on your system\n\n";
90 define(
'SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
91 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
94 require_once $SYSTEM_ROOT.
'/core/include/deja_vu.inc';
96 if ($deja_vu->enabled()) $deja_vu->forgetAll();
100 require_once $SYSTEM_ROOT.
'/install/install.inc';
101 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
104 if (version_compare(PHP_VERSION, SQ_REQUIRED_PHP_VERSION,
'<')) {
105 trigger_error(
'<i>'.SQ_SYSTEM_LONG_NAME.
'</i> requires PHP Version '.SQ_REQUIRED_PHP_VERSION.
'.<br/> You may need to upgrade.<br/> Your current version is '.PHP_VERSION, E_USER_ERROR);
109 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
112 if (!regenerate_configs()) {
113 trigger_error(
'Config Generation Failed', E_USER_ERROR);
117 $string_locales = Array();
118 $error_locales = Array();
119 $message_locales = Array();
124 $asset_screen_dir = SQ_DATA_PATH.
'/private/asset_types/asset/localised_screens';
125 create_directory($asset_screen_dir);
128 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypes();
132 'type_code' =>
'asset',
133 'dir' =>
'core/include/asset_edit',
134 'name' =>
'Base Asset',
136 array_unshift($asset_types, $base_asset);
141 $global_strings = Array(
144 'name' =>
'Global Strings',
146 array_unshift($asset_types, $global_strings);
148 $locale_names = array_keys($locale_list);
149 foreach ($locale_names as $locale) {
150 list($country,$lang,$variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale);
151 if (!in_array($country, $locale_names)) {
152 $locale_list[$country] = $locale_list[$locale];
156 if (!in_array($country.
'_'.$lang, $locale_names)) {
157 $locale_list[$country.
'_'.$lang] = $locale_list[$locale];
160 if (!empty($variant)) {
161 if (!in_array($country.
'_'.$lang.
'@'.$variant, $locale_names)) {
162 $locale_list[$country.
'_'.$lang.
'@'.$variant] = $locale_list[$locale];
168 foreach ($asset_types as $asset_type) {
170 $type_code = $asset_type[
'type_code'];
172 $local_screen_dir = SQ_DATA_PATH.
'/private/asset_types/'.$type_code.
'/localised_screens';
176 $base_path = SQ_SYSTEM_ROOT.
'/'.$asset_type[
'dir'].
'/locale';
177 $dirs_to_read = Array($base_path);
179 while (!empty($dirs_to_read)) {
180 $dir_read = array_shift($dirs_to_read);
182 $d = @opendir($dir_read);
187 $locale_name = str_replace($base_path.
'/',
'', $dir_read);
188 if (($slash_pos = strpos($locale_name,
'/')) !== FALSE) {
189 $locale_name{$slash_pos} =
'_';
190 if (($slash_pos = strpos($locale_name,
'/')) !== FALSE) {
191 $locale_name{$slash_pos} =
'@';
195 while (FALSE !== ($entry = readdir($d))) {
196 if (($entry{0} ==
'.') || ($entry ==
'CVS')) {
200 if (is_dir($dir_read.
'/'.$entry)) {
201 $dirs_to_read[] = $dir_read.
'/'.$entry;
204 if (preg_match(
'|^lang\_((static_)?screen\_.*)\.xml$|', $entry, $matches)) {
205 if (!empty($locale_list) && (!in_array($locale_name, array_keys($locale_list))
206 || (!in_array(
'all', $locale_list[$locale_name])
207 && !in_array(
'screens', $locale_list[$locale_name])))) {
211 if (!isset($screens[$locale_name])) {
212 $screens[$locale_name] = Array();
215 $screens[$locale_name][] = Array(
217 'screen' => $matches[1],
219 }
else if (preg_match(
'|^lang\_strings\.xml$|', $entry, $matches)) {
220 list($country,$lang,$variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale_name);
221 if (!in_array($country, $string_locales)) {
222 $string_locales[] = $country;
226 if (!in_array($country.
'_'.$lang, $string_locales)) {
227 $string_locales[] = $country.
'_'.$lang;
230 if (!empty($variant)) {
231 if (!in_array($country.
'_'.$lang.
'@'.$variant, $string_locales)) {
232 $string_locales[] = $country.
'_'.$lang.
'@'.$variant;
236 }
else if (preg_match(
'|^lang\_errors\.xml$|', $entry, $matches)) {
237 list($country,$lang,$variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale_name);
238 if (!in_array($country, $error_locales)) {
239 $error_locales[] = $country;
243 if (!in_array($country.
'_'.$lang, $error_locales)) {
244 $error_locales[] = $country.
'_'.$lang;
247 if (!empty($variant)) {
248 if (!in_array($country.
'_'.$lang.
'@'.$variant, $error_locales)) {
249 $error_locales[] = $country.
'_'.$lang.
'@'.$variant;
253 }
else if (preg_match(
'|^lang\_messages\.xml$|', $entry, $matches)) {
254 list($country,$lang,$variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale_name);
255 if (!in_array($country, $message_locales)) {
256 $message_locales[] = $country;
260 if (!in_array($country.
'_'.$lang, $message_locales)) {
261 $message_locales[] = $country.
'_'.$lang;
264 if (!empty($variant)) {
265 if (!in_array($country.
'_'.$lang.
'@'.$variant, $message_locales)) {
266 $message_locales[] = $country.
'_'.$lang.
'@'.$variant;
278 $all_screens = Array();
279 $d = @opendir(SQ_SYSTEM_ROOT.
'/'.$asset_type[
'dir']);
282 while (FALSE !== ($entry = readdir($d))) {
283 if (preg_match(
'|^edit\_interface\_((static_)?screen\_.*).xml$|', $entry, $matches)) {
284 $all_screens[] = $matches[1];
292 if (!empty($all_screens) && !empty($screens)) {
295 echo
'Compiling localised edit interfaces...'.
"\n";
297 echo $asset_type[
'type_code'].
' ('.$asset_type[
'name'].
')';
300 if (!empty($screens)) {
301 foreach ($screens as $locale => $locale_screens) {
303 foreach ($locale_screens as $screen_type) {
305 if (!file_exists($local_screen_dir)) {
306 create_directory($local_screen_dir);
310 if (strpos($screen_type[
'screen'],
'static_') === 0) {
311 $screen_xml = build_localised_static_screen($type_code, $screen_type[
'screen'], $locale);
313 $screen_xml = build_localised_screen($type_code, $screen_type[
'screen'], $locale);
316 string_to_file($screen_xml->asXML(), $local_screen_dir.
'/'.$screen_type[
'screen'].
'.'.$locale);
322 if (!empty($all_screens) && !empty($screens)) {
329 foreach ($string_locales as $locale) {
330 if (!empty($locale_list) && (!in_array($locale, array_keys($locale_list))
331 || (!in_array(
'all', $locale_list[$locale])
332 && !in_array(
'strings', $locale_list[$locale])))) {
336 echo
'Compiling strings for locale '.$locale.
"\n";
337 build_locale_string_file($locale);
341 foreach ($error_locales as $locale) {
342 if (!empty($locale_list) && (!in_array($locale, array_keys($locale_list))
343 || (!in_array(
'all', $locale_list[$locale])
344 && !in_array(
'errors', $locale_list[$locale])))) {
348 echo
'Compiling localised errors for locale '.$locale.
"\n";
349 build_locale_error_file($locale);
353 foreach ($message_locales as $locale) {
354 if (!empty($locale_list) && (!in_array($locale, array_keys($locale_list))
355 || (!in_array(
'all', $locale_list[$locale])
356 && !in_array(
'messages', $locale_list[$locale])))) {
360 echo
'Compiling localised internal messages for locale '.$locale.
"\n";
361 build_locale_internal_messages_file($locale);
364 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
366 foreach ($exs as $str) {
381 function get_console_list($options)
385 foreach ($options as $option) {
387 if (!isset($option[0]) || !isset($option[1])) {
391 if ($option[0] !=
'--locale')
continue;
394 $parts = explode(
'-', $option[1]);
397 if (count($parts) == 2 && strlen($parts[1])) {
398 $types = explode(
',', $parts[1]);
400 $types = Array(
'all');
403 $list[$parts[0]] = $types;