37 function regenerate_configs()
41 require_once SQ_LIB_PATH.
'/db_install/db_install.inc';
44 require_once SQ_INCLUDE_PATH.
'/system_config.inc';
46 if (!$cfg->save(Array(), FALSE))
return FALSE;
49 require_once SQ_INCLUDE_PATH.
'/external_tools_config.inc';
51 if (!$cfg->save(Array(), FALSE))
return FALSE;
54 require_once SQ_SYSTEM_ROOT.
'/core/server/squiz_server_config.inc';
56 if (!$squiz_server_cfg->save(Array(), FALSE)) {
61 require_once SQ_INCLUDE_PATH.
'/apache_config.inc';
63 if (!$apache_cfg->save(Array(), FALSE))
return FALSE;
66 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_config.inc';
68 if (!$hipo_cfg->save(Array(), FALSE))
return FALSE;
71 require_once SQ_INCLUDE_PATH.
'/messaging_service_config.inc';
73 if (!$ms_cfg->save(Array(), FALSE))
return FALSE;
76 require_once SQ_INCLUDE_PATH.
'/password_rules_config.inc';
78 if (!$pwd_cfg->save(Array(), FALSE))
return FALSE;
81 require_once SQ_INCLUDE_PATH.
'/proxy_authentication_config.inc';
83 if (!$pa_cfg->save(Array(), FALSE))
return FALSE;
88 $db_tables = get_database_tables();
90 if ((in_array(
'sq_ctx_def', $db_tables) === TRUE) && ($query_found === TRUE)) {
91 require_once SQ_INCLUDE_PATH.
'/context_config.inc';
93 $current = $context_cfg->load();
94 if (!$context_cfg->save(Array(
'contexts' => $current), FALSE)) {
110 function uninstall_asset_types()
113 $all_asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
117 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
120 $package_asset_types = Array();
123 $packages_installed = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
125 if (!empty($packages_installed)) {
126 foreach ($packages_installed as $package_array) {
127 $package = $package_array[
'code_name'];
130 if ($package ==
'__core__') {
131 require_once SQ_CORE_PACKAGE_PATH.
'/package_manager_core.inc';
133 $package_asset_types = array_merge($package_asset_types, array_keys($pm->assets));
136 $package_path = SQ_PACKAGES_PATH.
'/'.$package.
'/package_manager_'.$package.
'.inc';
137 if (file_exists($package_path)) {
138 require_once $package_path;
139 $class =
'package_manager_'.$package;
141 $package_asset_types = array_merge($package_asset_types, array_keys($pm->assets));
149 $asset_types = array_diff($asset_types, $package_asset_types);
153 if (!empty($asset_types)) {
159 foreach (array_diff($all_asset_types,$asset_types) as $asset_type) {
160 $asc = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($asset_type, FALSE, TRUE);
161 $deleted_parents = array_intersect($asset_types, $asc);
164 if (count($deleted_parents) > 0) {
165 trigger_error(
'One or more of the parents for the asset type \''.$asset_type.
'\' no longer exists in the system. The system may be broken until you restore the necessary files of the parent asset type to their proper location.
'."\n".'\
''.$asset_type.
'\' depends on:
'.implode(',
', $deleted_parents), E_USER_WARNING);
170 // failed dependency tests => bail
172 trigger_error('Asset hierarchy would be corrupted, uninstall not committed
', E_USER_WARNING);
176 $GLOBALS['SQ_SYSTEM
']->changeDatabaseConnection('db2
');
177 $GLOBALS['SQ_SYSTEM
']->doTransaction('BEGIN
');
178 $db = MatrixDAL::getDb();
180 // now actually delete the types
181 foreach ($asset_types as $asset_type) {
184 $sql = 'DELETE FROM sq_ast_typ WHERE type_code = :type_code
';
185 $query = MatrixDAL::preparePdoQuery($sql);
186 MatrixDAL::bindValueToPdo($query, 'type_code
', $asset_type);
187 MatrixDAL::execPdoQuery($query);
188 } catch (Exception $e) {
189 throw new Exception('Unable to
delete type code
'.$asset_type.' due to the following database error:
'.$e->getMessage());
193 // remove the inherited types
195 $sql = 'DELETE FROM sq_ast_typ_inhd
196 WHERE type_code = :type_code
197 OR inhd_type_code = :inhd_type_code
';
199 $query = MatrixDAL::preparePdoQuery($sql);
200 MatrixDAL::bindValueToPdo($query, 'type_code
', $asset_type);
201 MatrixDAL::bindValueToPdo($query, 'inhd_type_code
', $asset_type);
202 MatrixDAL::execPdoQuery($query);
203 } catch (Exception $e) {
204 throw new Exception('Unable to
delete inherited type code
'.$asset_type.' due to the following database error:
'.$e->getMessage());
207 // remove the attributes
209 $sql = 'DELETE FROM sq_ast_attr WHERE type_code = :type_code
';
211 $query = MatrixDAL::preparePdoQuery($sql);
212 MatrixDAL::bindValueToPdo($query, 'type_code
', $asset_type);
213 MatrixDAL::execPdoQuery($query);
214 } catch (Exception $e) {
215 throw new Exception('Unable to
delete attribute with type code
'.$asset_type.' due to the following database error:
'.$e->getMessage());
219 $GLOBALS['SQ_SYSTEM
']->doTransaction('COMMIT
');
220 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
222 // report if we did uninstall some asset types
223 if (!empty($asset_types)) {
224 $ms = $GLOBALS['SQ_SYSTEM
']->getMessagingService();
226 'type_code_list
' => implode("\n", $asset_types),
228 $message = $ms->newMessage(Array(), 'install.asset_type.uninstall
', $msg_reps);
232 }//end if asset types not empty
234 // clear the type cache
235 @unlink(SQ_DATA_PATH.'/
private/db/asset_types.inc
');
239 }//end uninstall_asset_types()
248 function uninstall_packages()
250 // If the package manager doesn't exist
for a package, it does not exist.
252 $packages_installed = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
254 if (!empty($packages_installed)) {
255 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
256 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
257 $db = $GLOBALS[
'SQ_SYSTEM']->db;
259 foreach ($packages_installed as $package_array) {
260 $package = $package_array[
'code_name'];
263 if ($package ==
'__core__')
continue;
266 $dir =
'packages/'.$package;
267 $exists = file_exists(SQ_SYSTEM_ROOT.
'/'.$dir.
'/package_manager_'.$package.
'.inc');
271 $sql =
'DELETE FROM sq_pkg WHERE code_name = :package_name';
277 if (file_exists(SQ_DATA_PATH.
'/private/asset_map/'.$package.
'.xml')) {
278 if (!unlink(SQ_DATA_PATH.
'/private/asset_map/'.$package.
'.xml')) {
279 trigger_error(
'Could not delete the asset map file for "'.$package.
'"', E_USER_WARNING);
280 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
284 trigger_error(
'Package file does not exist, it must have been deleted before', E_USER_NOTICE);
287 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
288 $message_body =
'Uninstalled '.$package;
290 'package' => $package,
292 $message = $ms->newMessage(Array(),
'install.package.uninstall', $msg_reps);
299 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
300 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
318 function install_core($package_list=Array())
325 if (count($package_list) > 0) {
326 if (!isset($package_list[
'core'])) {
329 $assets = $package_list[
'core'];
331 if (!is_array($assets)) $assets = Array();
334 require_once SQ_CORE_PACKAGE_PATH.
'/package_manager_core.inc';
336 $result = $pm->updatePackageDetails($assets);
338 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
342 $message = $ms->newMessage(Array(),
'install.package.'.($result ?
'success' :
'fail'), $msg_reps);
345 if (!$result) exit(1);
347 $result = $pm->installSystemAssets();
351 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
354 'num_assets' => $result,
356 $message = $ms->newMessage(Array(),
'install.system_assets.'.($result != -1 ?
'success' :
'fail'), $msg_reps);
360 if ($result == -1) exit(1);
364 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
365 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user);
378 function get_package_list()
381 $d = dir(SQ_PACKAGES_PATH);
383 while (FALSE !== ($entry = $d->read())) {
384 if ($entry ==
'.' || $entry ==
'..') {
388 if ($entry !=
'CVS' && is_dir(SQ_PACKAGES_PATH.
'/'.$entry)) {
389 $packages[] = $entry;
413 function install_packages($package_assets=Array())
416 $d = dir(SQ_PACKAGES_PATH);
418 $deferred_packages = Array();
421 $limit_packages = count($package_assets);
422 $packages = get_package_list();
424 foreach ($packages as $package) {
426 if ($limit_packages) {
427 if (!isset($package_assets[$package])) {
428 echo
"\nSkipping package $package \n";
431 $assets = $package_assets[$package];
433 if (!is_array($assets)) $assets = Array();
436 $result = install_package($package, $assets);
437 if (is_array($result)) {
438 $deferred_packages[$package] = $result;
442 return count($deferred_packages) ? $deferred_packages : TRUE;
459 function install_package($package, $package_assets=Array())
461 require_once SQ_PACKAGES_PATH.
'/'.$package.
'/package_manager_'.$package.
'.inc';
462 require_once SQ_LIB_PATH.
'/db_install/db_install.inc';
463 $class =
'package_manager_'.$package;
465 $result = $pm->updatePackageDetails($package_assets);
467 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
469 if (is_array($result)) {
471 'package' => $package,
473 $message = $ms->newMessage(Array(),
'install.package.deferred', $msg_reps);
478 $message_body = strtoupper($package).
' PACKAGE '.(($result) ?
'DONE SUCCESSFULLY' :
'FAILED');
480 'package' => $package,
482 $message = $ms->newMessage(Array(),
'install.package.'.($result ?
'success' :
'fail'), $msg_reps);
485 if (!$result) exit(1);
486 $result = $pm->installSystemAssets();
489 'package' => $package,
490 'num_assets' => $result,
492 $message_body = strtoupper($package).
' SYSTEM ASSET CREATION '.(($result == -1) ?
'FAILED' : (
': '.$result.
' NEW ASSETS CREATED'));
493 $message = $ms->newMessage(Array(),
'install.system_assets.'.($result ?
'success' :
'fail'), $msg_reps);
497 if ($result == -1) exit(1);
515 function install_deferred($packages)
517 $deferred = install_packages($packages);
519 if ($deferred === TRUE)
return TRUE;
522 if ($deferred == $packages)
return $deferred;
525 return install_deferred($deferred);
536 function install_authentication_types()
539 $auth_types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants(
'authentication');
542 $auth_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'authentication_folder');
543 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($auth_folder->id, SQ_LINK_TYPE_1,
'authentication', FALSE);
544 $installed_auth_types = Array();
545 foreach ($links as $link_data) {
546 $installed_auth_types[] = $link_data[
'minor_type_code'];
550 $folder_link = Array(
551 'asset' => &$auth_folder,
552 'link_type' => SQ_LINK_TYPE_1,
555 foreach ($auth_types as $type_code) {
556 if (in_array($type_code, $installed_auth_types)) {
559 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
560 $auth =
new $type_code();
562 if (!$auth->create($folder_link)) {
563 trigger_error(
'AUTHENTICATION TYPE "'.strtoupper($type_code).
'" NOT CREATED', E_USER_WARNING);
565 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
567 'auth_type_name' => strtoupper($type_code),
568 'assetid' => $auth->id,
570 $message = $ms->newMessage(Array(),
'install.authentication', $msg_reps);
587 function generate_global_preferences()
590 $packages = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
592 $preferences = Array();
593 if (is_file(SQ_DATA_PATH.
'/private/conf/preferences.inc')) {
594 include SQ_DATA_PATH.
'/private/conf/preferences.inc';
597 foreach ($packages as $package) {
599 if ($package[
'code_name'] ==
'__core__') {
600 require_once SQ_CORE_PACKAGE_PATH.
'/package_manager_core.inc';
601 $class =
'package_manager_core';
603 require_once SQ_PACKAGES_PATH.
'/'.$package[
'code_name'].
'/package_manager_'.$package[
'code_name'].
'.inc';
604 $class =
'package_manager_'.$package[
'code_name'];
608 $pm->installUserPreferences($preferences);
611 $str =
'<'.
'?php $preferences = '.var_export($preferences, TRUE).
'; ?'.
'>';
612 if (!string_to_file($str, SQ_DATA_PATH.
'/private/conf/preferences.inc')) {
616 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
617 $message = $ms->newMessage(Array(),
'install.prefs', Array());
631 function generate_lang_char_map()
633 $lang_char_map = Array(
682 $str =
'<'.
'?php $lang_char_map = '.var_export($lang_char_map, TRUE).
'; ?'.
'>';
683 if (!string_to_file($str, SQ_DATA_PATH.
'/private/conf/lang_char_map.inc')) {
698 function cache_asset_types()
700 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypes();
701 foreach ($asset_types as $type_code => $details) {
702 $asset_types[$type_code][
'ancestor_types'] = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($type_code, FALSE, TRUE);
704 $output =
'<'.
'?php'.
"\n".
' $asset_types = ';
705 $output .= var_export($asset_types, TRUE);
706 $output .=
"\n?".
'>';
708 if (!string_to_file($output, SQ_DATA_PATH.
'/private/db/asset_types.inc')) {
709 trigger_error(
'Could not cache the asset types', E_USER_ERROR);
712 pre_echo(
'ASSET TYPES CACHED');
723 function install_event_listeners()
726 $packages = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
728 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
729 $em->writeStaticEventsCacheFile();
731 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
732 $message = $ms->newMessage(Array(),
'install.event_listeners', Array());
746 function generate_performance_config()
749 $str .=
"#Constants for performance timeline chart\n";
750 $str .=
"define('PERFORMANCE_TIME_PRINT_PRECISION', 2);\n";
751 $str .=
"define('PERFORMANCE_PERCENTAGE_PRINT_PRECISION', 8);\n";
753 $performance_config = Array(
754 'page_asset_listing' => Array(
755 'report' =>
'http://www.squizlabs.com/squiz-matrix/matrix-performance-report-asset-listing-page',
759 $str .=
'$performance_config = '.var_export($performance_config, TRUE).
";\n";
761 if (!string_to_file($str, SQ_DATA_PATH.
'/private/conf/performance_config.inc')) {
776 function generate_file_bridge_config()
778 if(is_file(SQ_DATA_PATH.
'/private/conf/file_bridge.inc'))
return TRUE;
781 $str .=
"#path of file bridge\n";
782 $str .=
"define('FILE_BRIDGE_PATH', SQ_DATA_PATH.'/public');\n";
784 if (!string_to_file($str, SQ_DATA_PATH.
'/private/conf/file_bridge.inc')) {
800 function generate_import_tools_manager_config()
802 if(is_file(SQ_DATA_PATH.
'/private/conf/import_tools_manager.inc'))
return TRUE;
803 $structured_import_dir =
'';
804 $bulk_file_import_dir =
'';
805 if( $GLOBALS[
'SQ_SYSTEM']->am->installed(
'import_tools_manager')) {
806 $itm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'import_tools_manager');
807 $structured_import_dir = $itm->attr(
'import_dir');
808 $bulk_file_import_dir = $itm->attr(
'bulk_file_import_dir');
814 $str .=
"#path of structured file import directory \n";
815 $str .=
"define('STRUCTURED_FILE_IMPORT_DIR', '$structured_import_dir');\n";
817 $str .=
"#path of bulk file import directory \n";
818 $str .=
"define('BULK_FILE_IMPORT_DIR', '$bulk_file_import_dir');\n";
821 if (!string_to_file($str, SQ_DATA_PATH.
'/private/conf/import_tools_manager.inc')) {
837 function minify_css_files()
839 pre_echo(
'Minify JS Files');
841 require_once SQ_SYSTEM_ROOT.
'/scripts/ees_minify/jsmin.php';
843 $file = SQ_SYSTEM_ROOT.
'/core/lib/js/matrix.min.js';
845 $source_files = Array (
846 SQ_SYSTEM_ROOT.
'/fudge/var_serialise/var_serialise.js',
847 SQ_SYSTEM_ROOT.
'/core/lib/js/general.js',
848 SQ_SYSTEM_ROOT.
'/core/lib/js/debug.js',
849 SQ_SYSTEM_ROOT.
'/core/lib/js/layer_handler.js',
850 SQ_SYSTEM_ROOT.
'/core/lib/html_form/html_form.js',
851 SQ_SYSTEM_ROOT.
'/core/lib/js/detect.js',
852 SQ_SYSTEM_ROOT.
'/core/assets/bodycopy/bodycopy/js/bodycopy_edit_divs.js',
853 SQ_SYSTEM_ROOT.
'/core/assets/metadata/metadata_fields/metadata_field_select/js/metadata_field_select.js',
854 SQ_SYSTEM_ROOT.
'/core/assets/metadata/metadata_fields/metadata_field_multiple_text/js/metadata_field_multiple_text.js',
855 SQ_SYSTEM_ROOT.
'/core/assets/metadata/metadata_fields/metadata_field_hierarchy/js/metadata_field_hierarchy.js',
860 foreach ($source_files as $source) {
861 echo
'processing '.$source.
"\n";
862 $string .= JSMin::minify(file_get_contents($source));
864 $result = file_put_contents($file, $string);
866 if($result === FALSE) {
867 trigger_error (
"FAILED TO GENREATE MINIFIED JS FILES FOR EES");
871 echo $file.
" is completed.\n";
885 function format_deferred_packages($packages)
888 foreach ($packages as $package => $types) {
889 $out .=
"\n".$package.
":\n";
890 foreach ($types as $type) {
891 $out .=
"\t".$type.
"\n";
909 function find_asset_type_dirs($asset_type)
911 if ($asset_type !=
'asset') {
912 $asset_dir = SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset_type,
'dir');
914 $asset_dirs = Array($asset_dir);
915 $parent_type = $asset_type;
916 while (($parent_type = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($parent_type,
'parent_type')) !=
'asset') {
917 $asset_dirs[] = SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($parent_type,
'dir');
920 $asset_dirs = Array();
938 function find_edit_interface_file($asset_type, $file_name)
940 $file_name =
'edit_interface_'.$file_name.
'.xml';
943 $asset_dirs = find_asset_type_dirs($asset_type);
944 array_push($asset_dirs, SQ_INCLUDE_PATH.
'/asset_edit');
945 for ($i = 0; $i < count($asset_dirs); $i++) {
946 if (file_exists($asset_dirs[$i].
'/'.$file_name)) {
947 $file = $asset_dirs[$i].
'/'.$file_name;
953 trigger_error($file_name.
' not found for Asset Type "'.$asset_type.
'"', E_USER_WARNING);
976 function find_edit_interface_language_files($asset_type, $file_name, $locale)
978 $file_name =
'lang_'.$file_name.
'.xml';
981 $asset_dirs = find_asset_type_dirs($asset_type);
982 array_push($asset_dirs, SQ_INCLUDE_PATH.
'/asset_edit');
984 list($lang, $country, $variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale);
986 $lang_dirs = Array(strtolower($lang));
987 if (!empty($country)) {
988 array_unshift($lang_dirs, strtolower($lang).
'/'.strtoupper($country));
990 if (!empty($variant)) {
991 array_unshift($lang_dirs, strtolower($lang).
'/'.strtoupper($country).
'/'.$variant);
995 for ($i = 0; $i < count($lang_dirs); $i++) {
996 for ($j = 0; $j < count($asset_dirs); $j++) {
997 if (file_exists($asset_dirs[$j].
'/locale/'.$lang_dirs[$i].
'/'.$file_name)) {
998 $files[] = $asset_dirs[$j].
'/locale/'.$lang_dirs[$i].
'/'.$file_name;
1018 function build_localised_screen($asset_type, $screen, $locale)
1020 $ei_file = find_edit_interface_file($asset_type, $screen);
1024 $to_cache =
new SimpleXMLElement($ei_file, LIBXML_NOCDATA, TRUE);
1025 }
catch (Exception $e) {
1026 throw new Exception(
'Could not open edit interface file "'.$ei_file.
'": '.$e->getMessage());
1029 if (count($to_cache->section) <= 0) {
1030 return serialize($to_cache);
1033 $lang_files = find_edit_interface_language_files($asset_type, $screen, $locale);
1035 foreach ($lang_files as $lang_file) {
1038 $lang_root =
new SimpleXMLElement($lang_file, LIBXML_NOCDATA, TRUE);
1039 }
catch (Exception $e) {
1040 throw new Exception(
'Could not open edit interface localisation file "'.$lang_file.
'": '.$e->getMessage());
1044 $section_found = FALSE;
1046 foreach ($lang_root->section as $xml_section) {
1048 foreach ($to_cache->section as $this_section) {
1049 if (strcmp(((
string)$this_section->attributes()->name), ((
string)$xml_section->attributes()->name)) === 0) {
1050 $section_found = TRUE;
1056 if (!$section_found)
continue;
1058 foreach ($xml_section->children() as $xml_field) {
1059 switch ($xml_field->getName()) {
1060 case 'display_name':
1062 if (!isset($this_section->attributes()->{
'display_name'})) {
1063 $this_section->attributes()->{
'display_name'} = (string)$xml_field;
1069 if (!isset($this_section->attributes()->note)) {
1070 $this_section->addChild($xml_field->getName(), (string)$xml_field);
1080 if (!isset($xml_field->attributes()->attribute)) {
1082 foreach ($xml_field->children() as $child_field) {
1083 if ($child_field->getName() ==
'function_call') {
1084 $xml_paint_field = $child_field;
1090 $field_found = FALSE;
1091 foreach ($this_section->children() as $this_field) {
1092 if (isset($this_field->{
'function_call'}->{
'paint_function'})) {
1093 $paint_field = $this_field->{
'function_call'}->{
'paint_function'};
1094 if (strcmp((
string)$paint_field->attributes()->name, (string)$xml_paint_field->paint_function->attributes()->name) == 0) {
1095 $field_found = TRUE;
1102 if (!$field_found)
continue;
1106 $has_display_name = FALSE;
1109 foreach ($this_field->children() as $sub_field) {
1110 if ($sub_field->getName() ==
'display_name') {
1111 $has_display_name = TRUE;
1114 if ($sub_field->getName() ==
'note') $has_note = TRUE;
1117 foreach ($xml_field->children() as $xml_sub_field) {
1122 switch ($xml_sub_field->getName()) {
1123 case 'display_name':
1125 $this_field->addChild($xml_sub_field->getName(), (string)$xml_sub_field);
1134 $attr_name = $xml_field->attributes()->attribute;
1136 $field_found = FALSE;
1137 foreach ($this_section->children() as $this_field) {
1138 if ((
string)$this_field->attributes()->attribute === (string)$attr_name) {
1139 $field_found = TRUE;
1145 if (!$field_found)
continue;
1150 $has_display_name = FALSE;
1153 foreach ($this_field->children() as $sub_field) {
1154 if ($sub_field->getName() ==
'display_name') {
1155 $has_display_name = TRUE;
1158 if ($sub_field->getName() ==
'note') $has_note = TRUE;
1161 foreach ($xml_field->children() as $xml_sub_field) {
1162 switch ($xml_sub_field->getName()) {
1163 case 'display_name':
1164 if (!$has_display_name) {
1165 $this_field->addChild($xml_sub_field->getName(), (string)$xml_sub_field);
1171 $note_value = (string)$xml_sub_field;
1173 if ((stripos($note_value,
"<li>") !== FALSE)
1174 || (stripos($note_value,
"</li>") !== FALSE)
1175 || (stripos($note_value,
"<ul>") !== FALSE)
1176 || (stripos($note_value,
"</ul>") !== FALSE)
1177 || (stripos($note_value,
"<br />") !== FALSE)) {
1178 $note_value = htmlentities($note_value);
1181 $this_field->addChild($xml_sub_field->getName(), $note_value);
1215 function build_localised_static_screen($asset_type, $screen, $locale)
1217 $ei_file = find_edit_interface_file($asset_type, $screen);
1220 $to_cache =
new SimpleXMLElement($ei_file, LIBXML_NOCDATA, TRUE);
1221 }
catch (Exception $e) {
1222 throw new Exception(
'Could not open edit interface file "'.$ei_file.
'": '.$e->getMessage());
1225 if (count($to_cache->section) <= 0) {
1229 $lang_files = find_edit_interface_language_files($asset_type, $screen, $locale);
1231 foreach ($lang_files as $lang_file) {
1235 $lang_root =
new SimpleXMLElement($lang_file, LIBXML_NOCDATA, TRUE);
1236 }
catch (Exception $e) {
1237 throw new Exception(
'Could not open edit interface localisation file "'.$lang_file.
'": '.$e->getMessage());
1241 foreach ($lang_root->children() as $xml_section) {
1243 $section_found = FALSE;
1244 foreach ($to_cache->children() as $this_section) {
1246 if ((
string)$this_section->attributes()->name === (string)$xml_section->attributes()->name) {
1247 $section_found = TRUE;
1253 if (!$section_found)
continue;
1256 foreach ($xml_section->children() as $xml_field) {
1258 switch ($xml_field->getName()) {
1259 case 'display_name':
1261 if (is_null($this_section->attributes()->{
'display_name'})) {
1262 $this_section->attributes()->{
'display_name'} = (string)$xml_field;
1268 if (is_null($this_section->attributes()->note)) {
1269 $this_section->addChild($xml_field->getName(), (string)$xml_field);
1279 if (is_null($xml_field->attributes()->code)) {
1280 throw new Exception(
'Failed to parse static localised screen file "'.$lang_file.
'": static screen sections need a code for each field.');
1283 $code_name = $xml_field->attributes()->code;
1285 $field_found = FALSE;
1286 foreach ($this_section->children() as $this_field) {
1287 if ((
string)$this_field->attributes()->code === (string)$code_name) {
1288 $field_found = TRUE;
1294 if (!$field_found)
continue;
1299 $has_display_name = FALSE;
1302 foreach ($this_field->children() as $sub_field) {
1303 if ($sub_field->getName() ==
'display_name') {
1304 $has_display_name = TRUE;
1307 if ($sub_field->getName() ==
'note') $has_note = TRUE;
1310 foreach ($xml_field->children() as $xml_sub_field) {
1311 switch ($xml_sub_field->getName()) {
1312 case 'display_name':
1313 if (!$has_display_name) {
1314 $this_field->addChild($xml_sub_field->getName(), (string)$xml_sub_field);
1321 $this_field->addChild($xml_sub_field->getName(), (string)$xml_sub_field);
1356 function find_string_language_files($asset_dirs, $locale, $file=
'strings')
1358 $file_name =
'lang_'.$file.
'.xml';
1362 list($lang, $country, $variant) = $GLOBALS[
'SQ_SYSTEM']->lm->getLocaleParts($locale);
1364 $lang_dirs = Array(strtolower($lang));
1365 if (!empty($country)) {
1366 array_unshift($lang_dirs, strtolower($lang).
'/'.strtoupper($country));
1368 if (!empty($variant)) {
1369 array_unshift($lang_dirs, strtolower($lang).
'/'.strtoupper($country).
'/'.$variant);
1373 for ($i = 0; $i < count($lang_dirs); $i++) {
1374 for ($j = 0; $j < count($asset_dirs); $j++) {
1375 if (file_exists($asset_dirs[$j].
'/locale/'.$lang_dirs[$i].
'/'.$file_name)) {
1376 $files[] = $asset_dirs[$j].
'/locale/'.$lang_dirs[$i].
'/'.$file_name;
1394 function build_locale_string_file($locale)
1396 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypes();
1397 $packages = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
1399 $files_to_parse = Array(
1401 'packages' => Array(),
1402 'assets' => Array(),
1408 $asset_dirs = Array(SQ_SYSTEM_ROOT.
'/core');
1409 $files_to_parse[
'core'] = find_string_language_files($asset_dirs, $locale);
1413 foreach ($packages as $package) {
1414 $package_name = $package[
'code_name'];
1416 if ($package_name ==
'__core__') {
1417 $asset_dirs = Array(SQ_CORE_PACKAGE_PATH);
1419 $asset_dirs = Array(SQ_PACKAGES_PATH.
'/'.$package_name);
1422 $files_to_parse[
'packages'][$package_name] = find_string_language_files($asset_dirs, $locale);
1426 foreach ($asset_types as $asset_type) {
1427 $type_code = $asset_type[
'type_code'];
1428 $asset_dirs = find_asset_type_dirs($type_code);
1430 $files_to_parse[
'assets'][$type_code] = find_string_language_files($asset_dirs, $locale);
1434 $js_strings = Array();
1435 $java_strings = Array();
1437 foreach ($files_to_parse[
'core'] as $file) {
1439 list($ex_strings, $ex_js_strings, $ex_java_strings) = extract_strings_from_xml($file,
'strings',
'string',
'source');
1440 $strings = array_merge($strings, $ex_strings);
1441 $js_strings = array_merge($js_strings, $ex_js_strings);
1442 $java_strings = array_merge($java_strings, $ex_java_strings);
1445 if (!empty($strings)) {
1446 create_directory(SQ_DATA_PATH.
'/private/system/core');
1447 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/system/core/strings.'.$locale);
1450 foreach ($files_to_parse[
'packages'] as $package_name => $files) {
1452 foreach ($files as $file) {
1453 list($ex_strings, $ex_js_strings, $ex_java_strings) = extract_strings_from_xml($file,
'strings',
'string',
'source');
1454 $strings = array_merge($strings, $ex_strings);
1455 $js_strings = array_merge($js_strings, $ex_js_strings);
1456 $java_strings = array_merge($java_strings, $ex_java_strings);
1459 if ($package_name ==
'__core__') {
1460 $package_dir = Array(SQ_CORE_PACKAGE_PATH);
1462 $package_dir = Array(SQ_PACKAGES_PATH.
'/'.$package_name);
1464 if (!empty($strings)) {
1465 create_directory(SQ_DATA_PATH.
'/private/packages/'.$package_name);
1466 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/packages/'.$package_name.
'/strings.'.$locale);
1470 foreach ($files_to_parse[
'assets'] as $type_code => $files) {
1472 foreach ($files as $file) {
1473 list($ex_strings, $ex_js_strings, $ex_java_strings) = extract_strings_from_xml($file,
'strings',
'string',
'source');
1474 $strings = array_merge($strings, $ex_strings);
1475 $js_strings = array_merge($js_strings, $ex_js_strings);
1476 $java_strings = array_merge($java_strings, $ex_java_strings);
1479 $asset_dir = $asset_types[$type_code][
'dir'];
1480 if (!empty($strings)) {
1481 create_directory(SQ_DATA_PATH.
'/private/asset_types/'.$type_code);
1482 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/asset_types/'.$type_code.
'/strings.'.$locale);
1487 if (!empty($js_strings)) {
1488 create_directory(SQ_DATA_PATH.
'/public/system/core');
1490 $js_file =
'SQ_CURRENT_LOCALE = "'.$locale.
'";'.
"\n".
1491 'translated_strings["'.$locale.
'"] = new Array();'.
"\n";
1493 foreach ($js_strings as $string_code => $string) {
1494 $string = str_replace(
"\n",
'\\n', $string);
1495 $string = str_replace(
'"',
'\\"', $string);
1496 $js_file .=
'translated_strings["'.$locale.
'"]["'.$string_code.
'"] = "'.$string.
'";'.
"\n";
1499 string_to_file($js_file, SQ_DATA_PATH.
'/public/system/core/js_strings.'.$locale.
'.js');
1505 if (!empty($java_strings)) {
1506 create_directory(SQ_DATA_PATH.
'/private/system/core');
1509 foreach ($java_strings as $string_code => $string) {
1511 $string = preg_replace(
'|%s|',
'{0}', $string);
1514 while (preg_match(
'|%(\d*)\\$s|', $string, $match, PREG_OFFSET_CAPTURE)) {
1516 $new_arg =
'{'.((int)$match[1][0]-1).
'}';
1517 $string = substr_replace($string, $new_arg, $match[0][1], strlen($match[1][0]) + 3);
1520 $java_file .= $string_code.
' = '.$string.
"\n";
1523 string_to_file($java_file, SQ_DATA_PATH.
'/private/system/core/java_strings_'.$locale.
'.properties');
1540 function build_locale_error_file($locale)
1542 $packages = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
1544 $files_to_parse = Array(
1546 'packages' => Array(),
1552 $asset_dirs = Array(SQ_SYSTEM_ROOT.
'/core');
1553 $files_to_parse[
'core'] = find_string_language_files($asset_dirs, $locale,
'errors');
1556 foreach ($packages as $package) {
1557 $package_name = $package[
'code_name'];
1559 if ($package_name ==
'__core__') {
1560 $asset_dirs = Array(SQ_CORE_PACKAGE_PATH);
1562 $asset_dirs = Array(SQ_PACKAGES_PATH.
'/'.$package_name);
1565 $files_to_parse[
'packages'][$package_name] = find_string_language_files($asset_dirs, $locale,
'errors');
1570 foreach ($files_to_parse[
'core'] as $file) {
1571 $strings = array_merge(array_get_index($strings,
'core', Array()), extract_errors_from_xml($file,
'errors',
'error',
'code'));
1574 if (!empty($strings)) {
1575 create_directory(SQ_DATA_PATH.
'/private/system/core');
1576 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/system/core/errors.'.$locale);
1579 foreach ($files_to_parse[
'packages'] as $package_name => $files) {
1581 foreach ($files as $file) {
1582 $strings = array_merge($strings, extract_errors_from_xml($file,
'errors',
'error',
'code'));
1585 if ($package_name ==
'__core__') {
1586 $package_dir = Array(SQ_CORE_PACKAGE_PATH);
1588 $package_dir = Array(SQ_PACKAGES_PATH.
'/'.$package_name);
1590 if (!empty($strings)) {
1591 create_directory(SQ_DATA_PATH.
'/private/packages/'.$package_name);
1592 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/packages/'.$package_name.
'/errors.'.$locale);
1607 function build_locale_internal_messages_file($locale)
1609 $packages = $GLOBALS[
'SQ_SYSTEM']->getInstalledPackages();
1611 $files_to_parse = Array(
1613 'packages' => Array(),
1619 $asset_dirs = Array(SQ_SYSTEM_ROOT.
'/core');
1620 $files_to_parse[
'core'] = find_string_language_files($asset_dirs, $locale,
'messages');
1623 foreach ($packages as $package) {
1624 $package_name = $package[
'code_name'];
1626 if ($package_name ==
'__core__') {
1627 $asset_dirs = Array(SQ_CORE_PACKAGE_PATH);
1629 $asset_dirs = Array(SQ_PACKAGES_PATH.
'/'.$package_name);
1632 $files_to_parse[
'packages'][$package_name] = find_string_language_files($asset_dirs, $locale,
'messages');
1637 $message_types = array();
1639 foreach ($files_to_parse[
'core'] as $file) {
1640 $msgs = extract_internal_messages($file);
1641 $message_types = array_merge($message_types, array_keys($msgs));
1642 $strings = array_merge(array_get_index($strings,
'core', Array()), $msgs);
1644 if (!empty($strings)) {
1645 create_directory(SQ_DATA_PATH.
'/private/system/core');
1646 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/system/core/internal_messages.'.$locale);
1650 foreach ($files_to_parse[
'packages'] as $package_name => $files) {
1652 foreach ($files as $file) {
1653 $msgs = extract_internal_messages($file);
1654 $message_types = array_merge($message_types, array_keys($msgs));
1655 $strings = array_merge($strings, $msgs);
1658 if ($package_name ==
'__core__') {
1659 $package_dir = Array(SQ_CORE_PACKAGE_PATH);
1661 $package_dir = Array(SQ_PACKAGES_PATH.
'/'.$package_name);
1663 if (!empty($strings)) {
1664 create_directory(SQ_DATA_PATH.
'/private/packages/'.$package_name);
1665 string_to_file(serialize($strings), SQ_DATA_PATH.
'/private/packages/'.$package_name.
'/internal_messages.'.$locale);
1669 sort($message_types);
1670 $message_type_string =
"<?php\n";
1671 $message_type_string .=
'$message_types = '.var_export($message_types,
true).
";\n";
1672 $message_type_string .=
'return $message_types;'.
"\n";
1674 $message_type_string .=
"?".
">";
1675 string_to_file($message_type_string, SQ_DATA_PATH.
'/private/system/core/internal_message_types.inc');
1691 function extract_child_nodes_from_xml($file, $root_element, $child_element, $key_attribute)
1693 $extracted_strings = Array();
1696 $doc =
new DOMDocument();
1698 $xpath =
new DOMXPath($doc);
1699 }
catch (Exception $e) {
1700 throw new Exception(
'Could not open XML file "'.$file.
'": '.$e->getMessage());
1703 $root_nodes = $xpath->query(
'/'.$root_element);
1705 if ((count($root_nodes) !== 1) && $root_nodes->item(0)->nodeName !== $root_element) {
1706 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - expecting "'.$root_element.
'" as document element, found "'.$root->nodeName.
'"');
1709 $root = $root_nodes->item(0);
1715 $non_child_elements = $xpath->evaluate(
'count(./*[name() != "'.$child_element.
'"])', $root);
1716 $missing_attributes = $xpath->evaluate(
'count(./*[name() = "'.$child_element.
'" and not(@'.$key_attribute.
')])', $root);
1718 if (($non_child_elements > 0) || ($missing_attributes > 0)) {
1720 $msg =
'XML file "'.$file.
'" does not appear to be valid.';
1721 if ($non_child_elements > 0) {
1722 $msg .=
' Found '.$non_child_elements.
' element(s) not of the expected type "'.$child_element.
'".';
1724 if ($missing_attributes > 0) {
1725 $msg .=
' Found '.$missing_attributes.
' element(s) of type "'.$child_element.
'" that do not contain the required attribute "'.$key_attribute.
'".';
1727 throw new Exception($msg);
1732 $child_nodes = $xpath->query(
'./'.$child_element, $root);
1733 return $child_nodes;
1753 function extract_strings_from_xml($file, $root_element, $child_element, $key_attribute)
1755 $extracted_strings = Array();
1756 $js_strings = Array();
1757 $java_strings = Array();
1759 $children = extract_child_nodes_from_xml($file, $root_element, $child_element, $key_attribute);
1761 foreach ($children as $string_node) {
1762 if ($string_node->nodeName !== $child_element) {
1763 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - expecting node "'.$child_element.
'", found "'.$string_node->nodeName.
'"');
1767 if (!$string_node->hasAttribute($key_attribute)) {
1768 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - missing attribute "'.$key_attribute.
'" in string node');
1772 $source_code = $string_node->getAttribute($key_attribute);
1773 $translation = $string_node->nodeValue;
1776 if (isset($extracted_strings[$source_code])) {
1777 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - detected duplicate code "'.$source_code.
'"');
1778 return Array(Array(), Array(), Array());
1779 }
else if (empty($translation)) {
1780 throw new Exception(
'Skipping translation for code "'.$source_code.
'" as the translation appears to be empty');
1781 }
else if (preg_match_all(
'|[^%]%s|', $translation, $matches) > 1) {
1782 throw new Exception(
'Skipping translation for code "'.$source_code.
'"; it has multiple occurrences of unpositioned "%s" - use positioned replacements (eg. "%1$s") when you have more than one');
1785 $extracted_strings[$source_code] = $translation;
1787 if ($string_node->hasAttribute(
'js') && ($string_node->getAttribute(
'js') == 1)) {
1788 $js_strings[$source_code] = $extracted_strings[$source_code];
1790 if ($string_node->hasAttribute(
'java') && ($string_node->getAttribute(
'java') == 1)) {
1791 $java_strings[$source_code] = $extracted_strings[$source_code];
1797 return Array($extracted_strings, $js_strings, $java_strings);
1817 function extract_errors_from_xml($file, $root_element, $child_element, $key_attribute)
1819 $extracted_strings = Array();
1821 $children = extract_child_nodes_from_xml($file, $root_element, $child_element, $key_attribute);
1823 foreach ($children as $string_node) {
1824 if ($string_node->nodeName != $child_element) {
1825 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - expecting node "'.$child_element.
'", found "'.$string_node->nodeName.
'"');
1829 if (!$string_node->hasAttribute($key_attribute)) {
1830 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - missing attribute "'.$key_attribute.
'" in string node');
1834 $source_code = $string_node->getAttribute($key_attribute);
1835 $translation = html_entity_decode($string_node->nodeValue);
1838 if (isset($extracted_strings[$source_code])) {
1839 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - detected duplicate code "'.$source_code.
'"');
1840 return Array(Array(), Array(), Array());
1841 }
else if (empty($translation)) {
1842 throw new Exception(
'Skipping translation for code "'.$source_code.
'" as the translation appears to be empty');
1843 }
else if (preg_match_all(
'|%s|', $translation, $matches) > 1) {
1844 throw new Exception(
'Skipping translation for code "'.$source_code.
'"; it has multiple occurrences of unpositioned "%s" - use positioned replacements (eg. "%1$s") when you have more than one');
1846 $extracted_strings[$source_code] = $translation;
1851 return $extracted_strings;
1869 function extract_internal_messages($file)
1871 $root_element =
'messages';
1872 $child_element =
'message';
1873 $key_attribute =
'type';
1874 $extracted_messages = Array();
1876 $children = extract_child_nodes_from_xml($file, $root_element, $child_element, $key_attribute);
1878 foreach ($children as $string_node) {
1879 if ($string_node->nodeName != $child_element) {
1880 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - expecting node "'.$child_element.
'", found "'.$string_node->nodeName.
'"');
1884 if (!$string_node->hasAttribute($key_attribute)) {
1885 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - missing attribute "'.$key_attribute.
'" in string node');
1889 $source_code = $string_node->getAttribute($key_attribute);
1890 $translation = Array();
1892 foreach ($string_node->childNodes as $sub_node) {
1893 $sub_node_name = $sub_node->nodeName;
1894 if (($sub_node_name ==
'subject') || ($sub_node_name ==
'body')) {
1895 $translation[$sub_node_name] = html_entity_decode($sub_node->nodeValue);
1899 if (!isset($translation[
'subject']) || !isset($translation[
'body'])) {
1901 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - internal message type "'.$source_code.
'" does not seem to have a subject and body');
1902 }
else if (isset($extracted_messages[$source_code])) {
1904 throw new Exception(
'XML file "'.$file.
'" does not appear to be valid - detected duplicate message type "'.$source_code.
'"');
1906 }
else if (empty($translation)) {
1907 throw new Exception(
'Skipping translation for code "'.$source_code.
'" as the translation appears to be empty');
1909 $extracted_messages[$source_code][
'subject'] = $translation[
'subject'];
1910 $extracted_messages[$source_code][
'body'] = $translation[
'body'];
1915 return $extracted_messages;
1935 function generate_install_key($create_key_file=FALSE)
1937 $host = php_uname(
'n');
1938 $ip = gethostbyname($host);
1939 $install_key = md5($host.
'-'.$ip.
'-'.SQ_SYSTEM_ROOT);
1941 if ($create_key_file) {
1942 require_once SQ_INCLUDE_PATH.
'/system_config.inc';
1945 if (!$cfg->save(Array(
'SQ_LICENCE_INSTALL_KEY' => $install_key), FALSE, FALSE)) {
1952 return $install_key;
1963 function install_dal_core_queries()
1965 $old_path = ini_get(
'include_path');
1966 ini_set(
'include_path', SQ_LIB_PATH);
1967 require_once SQ_LIB_PATH.
'/MatrixDAL/MatrixDALBaker.inc';
1970 ini_set(
'include_path', $old_path);
1982 function install_dal_package_queries($name)
1984 $old_path = ini_get(
'include_path');
1985 ini_set(
'include_path', SQ_LIB_PATH);
1986 require_once SQ_LIB_PATH.
'/MatrixDAL/MatrixDALBaker.inc';
1988 if ($queries_found) {
1991 ini_set(
'include_path', $old_path);