43 error_reporting(E_ALL);
44 ini_set(
'memory_limit',
'1024M');
45 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
47 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
48 if (empty($SYSTEM_ROOT)) {
49 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
53 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
54 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
58 $asset_infos = (isset($_SERVER[
'argv'][2])) ? explode(
',',$_SERVER[
'argv'][2]) : Array();
59 if (empty($asset_infos)) {
60 echo
"ERROR: You need to supply the asset id for the asset you want to export and parent asset it will link to as the second argument with format 3:75,4:46 (assetid 3 links to assetid 75, assetid 4 links to asset id 46)\n";
64 $initial_link_type = (isset($_SERVER[
'argv'][3])) ? $_SERVER[
'argv'][3] :
'';
65 if (empty($initial_link_type)) {
66 echo
"ERROR: You need to supply the initial link type as the third argument\n";
70 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
71 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
74 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
75 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
76 echo
"Failed logging in as root user\n";
80 $asset_id_map = Array();
82 echo
"<?xml version=\"1.0\" encoding=\"".SQ_CONF_DEFAULT_CHARACTER_SET.
"\"?>\n";
85 foreach($asset_infos as $asset_info) {
86 $asset_from_to_id = explode(
':',$asset_info);
87 if(!isset($asset_from_to_id[0]) || !isset($asset_from_to_id[1])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
88 printCreateXML($asset_from_to_id[0], $asset_from_to_id[1], $initial_link_type);
90 foreach($asset_infos as $asset_info) {
91 $asset_from_to_id = explode(
':',$asset_info);
92 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
93 printAttributeXML($asset_from_to_id[0]);
95 foreach($asset_infos as $asset_info) {
96 $asset_from_to_id = explode(
':',$asset_info);
97 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
98 printMetadataXML($asset_from_to_id[0]);
100 foreach($asset_infos as $asset_info) {
101 $asset_from_to_id = explode(
':',$asset_info);
102 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
103 printNoticeLinksXML($asset_from_to_id[0]);
105 foreach($asset_infos as $asset_info) {
106 $asset_from_to_id = explode(
':',$asset_info);
107 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
108 printPermissionXML($asset_from_to_id[0]);
111 echo
"</actions>\n\n";
122 function printCreateXML($asset_id, $parent, $link_type, $value=
'', $is_dependant=0, $is_exclusive=0) {
124 global $asset_id_map;
126 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
127 if (is_null($asset)) exit();
130 if (replace_system_assetid($asset->id) != NULL) trigger_error(
"Can not export system asset!\n", E_USER_ERROR);
133 $action_code = getAssetType($asset).
'_'.$asset->id;
135 echo_headline(
'CREATING ASSET: '.$asset->name);
136 $asset_id_map[$asset->id] = $action_code;
139 echo
" <action_id>create_".$action_code.
"</action_id>\n";
141 if ($GLOBALS[
'SQ_SYSTEM']->am->isTypeDecendant(getAssetType($asset),
'file')) {
142 $file_path = _saveFileAsset($asset);
143 echo
" <action_type>create_file_asset</action_type>\n";
144 echo
" <file_path>".$file_path.
"</file_path>\n";
146 echo
" <action_type>create_asset</action_type>\n";
149 echo
" <type_code>".getAssetType($asset).
"</type_code>\n";
150 echo
" <link_type>".$link_type.
"</link_type>\n";
151 echo
" <parentid>".$parent.
"</parentid>\n";
152 echo
" <value>".$value.
"</value>\n";
153 echo
" <is_dependant>".$is_dependant.
"</is_dependant>\n";
154 echo
" <is_exclusive>".$is_exclusive.
"</is_exclusive>\n";
155 echo
"</action>\n\n";
159 $paths = $asset->getWebPaths();
160 foreach ($paths as $path) {
163 echo
" <action_id>add_".$action_code.
"_path</action_id>\n";
164 echo
" <action_type>add_web_path</action_type>\n";
165 echo
" <asset>[[output://create_".$action_code.
".assetid]]</asset>\n";
166 echo
" <path>".$path.
"</path>\n";
167 echo
"</action>\n\n";
170 $dependants = Array();
171 if (getAssetType($asset) !=
'Design_Customisation' && getAssetType($asset) !=
'Design' && getAssetType($asset) !=
'Design_Css') {
173 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
174 }
else if (getAssetType($asset) ==
'Design' || getAssetType($asset) ==
'Design_Css') {
182 $parse_file = $asset->data_path.
'/parse.txt';
183 if (is_file($parse_file)) _updateParseFileForDesign($asset_id_map[$asset_id], $parse_file);
185 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'', FALSE,
'major', NULL, TRUE);
187 }
else if (getAssetType($asset) ==
'Design_Customisation') {
191 $dependants = $asset->getCustomisedAreas();
194 $dependants = array_merge($dependants, $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'design_customisation'));
197 foreach ($dependants as $link_info) {
198 if (!strpos($link_info[
'minorid'],
':')) {
199 $parent =
'[[output://create_'.$action_code.
'.assetid]]';
202 if (array_key_exists($link_info[
'minorid'], $asset_id_map)) {
203 printLinkXML($parent, $link_info, $action_code);
205 printCreateXML($link_info[
'minorid'], $parent, $link_info[
'link_type'], $link_info[
'value'], $link_info[
'is_dependant'], $link_info[
'is_exclusive']);
212 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
213 foreach ($children as $link_info) {
214 if (!strpos($link_info[
'minorid'],
':')) {
215 $parent =
'[[output://create_'.$action_code.
'.assetid]]';
217 if (array_key_exists($link_info[
'minorid'], $asset_id_map)) {
218 printLinkXML($parent, $link_info, $action_code);
220 printCreateXML($link_info[
'minorid'], $parent, $link_info[
'link_type'], $link_info[
'value'], $link_info[
'is_dependant'], $link_info[
'is_exclusive']);
227 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
231 function printLinkXML($parent, $link_info, $action_code) {
233 global $asset_id_map;
236 if (isset($asset_id_map[$link_info[
'minorid']])){
237 $remap_id =
"[[output://create_".$asset_id_map[$link_info[
'minorid']].
".assetid]]";
242 $system_asset_name = replace_system_assetid($link_info[
'minorid']);
243 $system_asset_name == NULL ? $remap_id = $link_info[
'minorid'] : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
247 echo
" <action_id>link_".$action_code.
"</action_id>\n";
248 echo
" <action_type>create_link</action_type>\n";
249 echo
" <asset>".$remap_id.
"</asset>\n";
250 echo
" <assetid>".$parent.
"</assetid>\n";
251 echo
" <is_major>0</is_major>\n";
252 echo
" <link_type>".$link_info[
'link_type'].
"</link_type>\n";
253 echo
" <value>".$link_info[
'value'].
"</value>\n";
254 echo
" <is_dependant>".$link_info[
'is_dependant'].
"</is_dependant>\n";
255 echo
" <is_exclusive>".$link_info[
'is_exclusive'].
"</is_exclusive>\n";
256 echo
"</action>\n\n";
260 function printAttributeXML($asset_id) {
262 global $asset_id_map;
264 $assets_done = Array();
266 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
267 if (is_null($asset)) exit();
270 foreach ($asset->vars as $attr_name => $attr_info) {
271 $attr = $asset->getAttribute($attr_name);
272 $value = $attr->getContent();
275 if(isSerialized($value) && !empty($value)){
276 $value = var_export(unserialize($value),TRUE);
279 if (preg_match(
"/assetid/",$attr_name) && isset($asset_id_map[$value])){
280 $value =
"[[output://create_".$asset_id_map[$value].
".assetid]]";
282 $assets_done[$asset->id] = TRUE;
284 if (!empty($value) && !((getAssetType($asset) ==
'Design' || getAssetType($asset) ==
'Design_Css') && $attr_name ==
'contents')) {
288 if (strtolower(SQ_CONF_DEFAULT_CHARACTER_SET) !=
'utf-8') {
291 for ($i = 0; $i < strlen($value); ++$i) {
292 $ord = ord($value[$i]);
294 $result .=
'&#'.$ord.
';';
296 $result .= $value[$i];
300 if ($result !==
'') $value = $result;
301 $value = preg_replace(
'/(\r\n)+/',
'<br/>' ,$value);
305 echo
" <action_id>set_".$asset_id_map[$asset_id].
'_'.$attr_name.
"</action_id>\n";
306 echo
" <action_type>set_attribute_value</action_type>\n";
307 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
308 echo
" <attribute>".$attr_name.
"</attribute>\n";
309 $value = _parseValue($value, $attr_name,
'set_'.$asset_id_map[$asset_id].
'_'.$attr_name);
311 echo
" <value><![CDATA["._escapeCDATA($value).
"]]></value>\n";
312 echo
"</action>\n\n";
316 $dependants = Array();
317 if (getAssetType($asset) !=
'Design_Customisation' && getAssetType($asset) !=
'Design' && getAssetType($asset) !=
'Design_Css') {
319 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
320 }
else if (getAssetType($asset) ==
'Design' || getAssetType($asset) ==
'Design_Css') {
321 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'', FALSE,
'major', NULL, TRUE);
322 }
else if (getAssetType($asset) ==
'Design_Customisation') {
326 $dependants = $asset->getCustomisedAreas();
329 $dependants = array_merge($dependants, $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'design_customisation'));
332 foreach ($dependants as $link_info) {
333 if (!strpos($link_info[
'minorid'],
':')) {
334 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
335 printAttributeXML($link_info[
'minorid']);
341 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
342 foreach ($children as $link_info) {
343 if (!strpos($link_info[
'minorid'],
':')) {
344 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
345 printAttributeXML($link_info[
'minorid']);
350 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
354 function printNoticeLinksXML($asset_id) {
356 global $asset_id_map;
358 $assets_done = Array();
360 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_LINK_NOTICE,
'', FALSE,
'major');
361 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
363 foreach ($notice_links as $notice_link) {
364 if (strpos($notice_link[
'minorid'],
':'))
continue;
366 if (isset($asset_id_map[$asset_id])){
367 $remap_id =
"[[output://create_".$asset_id_map[$asset_id].
".assetid]]" ;
372 $system_asset_name = replace_system_assetid($asset_id);
373 $system_asset_name == NULL ? $remap_id = $asset_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
375 printLinkXML($remap_id, $notice_link,
'notice_'.$asset_id.
'_to_'.$notice_link[
'minorid']);
379 $assets_done[$asset_id] = TRUE;
381 $dependants = Array();
382 if (getAssetType($asset) !=
'Design_Customisation' && getAssetType($asset) !=
'Design') {
384 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
385 }
else if (getAssetType($asset) ==
'Design') {
386 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'', FALSE,
'major', NULL, TRUE);
387 }
else if (getAssetType($asset) ==
'Design_Customisation') {
391 $dependants = $asset->getCustomisedAreas();
394 $dependants = array_merge($dependants, $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'design_customisation'));
397 foreach ($dependants as $link_info) {
398 if (!strpos($link_info[
'minorid'],
':')) {
399 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
400 printNoticeLinksXML($link_info[
'minorid']);
406 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
407 foreach ($children as $link_info) {
408 if (!strpos($link_info[
'minorid'],
':')) {
409 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
410 printNoticeLinksXML($link_info[
'minorid']);
416 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
420 function printPermissionXML($asset_id) {
422 global $asset_id_map;
424 $assets_done = Array();
425 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
428 $read_permissions = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_READ, NULL, FALSE, FALSE, TRUE, TRUE);
429 foreach ($read_permissions as $permission_id => $permission_granted) {
431 if (isset($asset_id_map[$permission_id])){
432 $remap_id =
"[[output://create_".$asset_id_map[$permission_id].
".assetid]]" ;
437 $system_asset_name = replace_system_assetid($permission_id);
438 $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
445 if($permission_granted == 0) {
447 echo
" <action_id>set_permission_".$asset_id.
"_read_".$permission_id.
"</action_id>\n";
448 echo
" <action_type>set_permission</action_type>\n";
449 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
450 echo
" <permission>1</permission>\n";
451 echo
" <mute_error>1</mute_error>\n";
452 echo
" <granted>-1</granted>\n";
453 echo
" <userid>".$remap_id.
"</userid>\n";
457 echo
" <action_id>set_permission_".$asset_id.
"_read_".$permission_id.
"</action_id>\n";
458 echo
" <action_type>set_permission</action_type>\n";
459 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
460 echo
" <permission>1</permission>\n";
461 echo
" <granted>".$permission_granted.
"</granted>\n";
462 echo
" <userid>".$remap_id.
"</userid>\n";
467 $write_permissions = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_WRITE, NULL, FALSE, FALSE, TRUE, TRUE);
468 foreach ($write_permissions as $permission_id => $permission_granted) {
471 if (isset($asset_id_map[$permission_id])){
472 $remap_id =
"[[output://create_".$asset_id_map[$permission_id].
".assetid]]" ;
477 $system_asset_name = replace_system_assetid($permission_id);
478 $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
483 if($permission_granted == 0) {
485 echo
" <action_id>set_permission_".$asset_id.
"_write_".$permission_id.
"</action_id>\n";
486 echo
" <action_type>set_permission</action_type>\n";
487 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
488 echo
" <permission>2</permission>\n";
489 echo
" <mute_error>1</mute_error>\n";
490 echo
" <granted>-1</granted>\n";
491 echo
" <userid>".$remap_id.
"</userid>\n";
495 echo
" <action_id>set_permission_".$asset_id.
"_write_".$permission_id.
"</action_id>\n";
496 echo
" <action_type>set_permission</action_type>\n";
497 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
498 echo
" <permission>2</permission>\n";
499 echo
" <granted>".$permission_granted.
"</granted>\n";
500 echo
" <userid>".$remap_id.
"</userid>\n";
505 $admin_permissions = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_ADMIN, NULL, FALSE, FALSE, TRUE, TRUE);
506 foreach ($admin_permissions as $permission_id => $permission_granted) {
508 if (isset($asset_id_map[$permission_id])){
509 $remap_id =
"[[output://create_".$asset_id_map[$permission_id].
".assetid]]" ;
512 $system_asset_name = replace_system_assetid($permission_id);
513 $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
518 if($permission_granted == 0) {
520 echo
" <action_id>set_permission_".$asset_id.
"_admin_".$permission_id.
"</action_id>\n";
521 echo
" <action_type>set_permission</action_type>\n";
522 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
523 echo
" <permission>3</permission>\n";
524 echo
" <mute_error>1</mute_error>\n";
525 echo
" <granted>-1</granted>\n";
526 echo
" <userid>".$remap_id.
"</userid>\n";
530 echo
" <action_id>set_permission_".$asset_id.
"_admin_".$permission_id.
"</action_id>\n";
531 echo
" <action_type>set_permission</action_type>\n";
532 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
533 echo
" <permission>3</permission>\n";
534 echo
" <granted>".$permission_granted.
"</granted>\n";
535 echo
" <userid>".$remap_id.
"</userid>\n";
540 $assets_done[$asset_id] = TRUE;
542 $dependants = Array();
543 if (getAssetType($asset) !=
'Design_Customisation' && getAssetType($asset) !=
'Design') {
545 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
546 }
else if (getAssetType($asset) ==
'Design') {
547 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'', FALSE,
'major', NULL, TRUE);
548 }
else if (getAssetType($asset) ==
'Design_Customisation') {
552 $dependants = $asset->getCustomisedAreas();
555 $dependants = array_merge($dependants, $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'design_customisation'));
558 foreach ($dependants as $link_info) {
559 if (!strpos($link_info[
'minorid'],
':')) {
560 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
561 printPermissionXML($link_info[
'minorid']);
567 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
568 foreach ($children as $link_info) {
569 if (!strpos($link_info[
'minorid'],
':')) {
570 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
571 printPermissionXML($link_info[
'minorid']);
591 function _saveFileAsset(&$asset, $file=Array())
593 if (!is_null($asset)) {
594 $file_info = $asset->getExistingFile();
595 if (empty($file_info)) {
596 trigger_error(
'File not found in data directory for the file asset #'.$asset->id, E_USER_ERROR);
598 $file_type = getAssetType($asset);
599 $assetid = $asset->id;
602 $file_type = $file[
'type'];
603 $assetid = substr($file_info[
'filename'], 0 ,strpos($file_info[
'filename'],
'_'));
606 $export_path =
'export/'.$file_type.
'/'.$assetid.
'/'.$file_info[
'filename'];
609 if (!file_exists(
'export/')) {
610 mkdir(
"export", 0775);
614 if (!file_exists(
'export/'.$file_type.
'/')) {
615 mkdir(
'export/'.$file_type, 0775);
619 mkdir(
'export/'.$file_type.
'/'.$assetid, 0775);
621 if (copy($file_info[
'path'], $export_path)) {
624 die(
'Could not copy file');
642 function _parseValue($value, $attribute_name, $actionid)
644 global $asset_id_map;
646 $assetid_mapped = Array();
648 $shadow_reg =
'|.\/?a=(\d+:\w*)|';
649 $normal_reg =
'|.\/?a=(\d+)|';
650 $shadow_matches = Array();
651 $normal_matches = Array();
653 preg_match_all($shadow_reg, $value, $shadow_matches);
654 preg_match_all($normal_reg, $value, $normal_matches);
656 if(isset($shadow_matches[1])) $shadow_matches = $shadow_matches[1];
657 if(isset($normal_matches[1])) $normal_matches = $normal_matches[1];
658 $replace_assetids = Array();
659 foreach ($shadow_matches as $data) {
660 $replace_assetids[] = $data;
662 foreach ($normal_matches as $data) {
663 $replace_assetids[] = $data;
666 foreach ($replace_assetids as $replace_assetid) {
667 if (isset($asset_id_map[$replace_assetid])) {
668 $value = preg_replace(
'|.\/?a='.$replace_assetid.
'|',
'?a=[[output://create_'.$asset_id_map[$replace_assetid].
'.assetid]]', $value);
669 $assetid_mapped[] = $replace_assetid;
673 $globals_processed = FALSE;
676 $kywrd_reg_global_shdw =
'|%globals_asset_[a-z]+:(\d+:\w*)%|';
677 $kywrd_reg_global_real =
'|%globals_asset_[a-z]+:(\d+)%|';
678 preg_match_all($kywrd_reg_global_shdw, $value, $globals_match);
679 preg_match_all($kywrd_reg_global_real, $value, $globals_match_2);
681 if(isset($globals_match[1]))$globals_match = $globals_match[1];
682 if(isset($globals_match_2[1]))$globals_match_2 = $globals_match_2[1];
684 $replace_globals_assetids = Array();
685 foreach ($globals_match as $data) {
686 $replace_globals_assetids[] = $data;
688 foreach ($globals_match_2 as $data) {
689 $replace_globals_assetids[] = $data;
692 foreach ($replace_globals_assetids as $replace_globals_assetid) {
693 if (isset($asset_id_map[$replace_globals_assetid])) {
694 $value = preg_replace(
'|%globals_asset_([a-z]+):'.$replace_globals_assetid.
'%|',
695 '%globals_asset_$1:[[output://create_'.$asset_id_map[$replace_globals_assetid].
'.assetid]]',
697 $assetid_mapped[] = $replace_globals_assetid;
698 $globals_processed = TRUE;
705 if (!$globals_processed && $attribute_name !=
'html' && $attribute_name !=
'quiz_answers' && $attribute_name !=
'statuses') {
706 preg_match_all(
'/\'([0-9]+)\'/', $value, $assetid_match);
707 if (isset($assetid_match[1])) {
708 foreach (array_unique($assetid_match[1]) as $assetid) {
714 if ($assetid !=
'0' && array_key_exists($assetid, $asset_id_map) && $GLOBALS[
'SQ_SYSTEM']->am->assetExists($assetid)) {
715 $value = preg_replace(
'/'.$assetid.
'/',
'[[output://create_'.$asset_id_map[$assetid].
'.assetid]]', $value);
716 $assetid_mapped[] = $assetid;
722 if(!empty($assetid_mapped)) {
724 echo_text(
"\n\n\nWARNING : Matrix has found following Assetid(s) appearing in attribute value and mapped. This should be reviewed !!!\n");
728 $mapped_str = implode(
'", "', $assetid_mapped);
729 $echo_str =
'"'.$mapped_str.
'" for Action ID "'.$actionid.
'" to set attribute "'.$attribute_name.
'"'.
"\n";
730 echo_text($echo_str);
738 function printMetadataXML($asset_id) {
740 global $asset_id_map;
742 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
743 $assets_done = Array();
745 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
746 if (is_null($asset)) exit();
748 foreach($mm->getSchemas($asset_id) as $schema_id => $granted) {
749 $schema_info = $mm->getAssetSchemaInfo($asset_id, $schema_id);
751 echo
" <action_id>set_".$asset_id_map[$asset_id].
"_metadata_schema_".$schema_id.
"</action_id>\n";
752 echo
" <action_type>set_metadata_schema</action_type>\n";
753 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
754 echo
" <schemaid>".(isset($asset_id_map[$schema_id]) ?
"[[output://create_".$asset_id_map[$schema_id].
".assetid]]" : $schema_id).
"</schemaid>\n";
755 echo
" <granted>".$schema_info[
'granted'].
"</granted>\n";
756 echo
" <cascades>".$schema_info[
'cascades'].
"</cascades>\n";
757 echo
"</action>\n\n";
759 $metadata = $mm->getMetadata($asset_id, $schema_id);
760 foreach ($metadata as $field_id => $field_info) {
761 $field_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($mm->getFieldAssetIdFromName($asset_id, $field_info[0][
'name']));
762 if($field_asset->type() ==
'metadata_field_text') {
763 $value = $field_info[0][
'value'];
764 if (strtolower(SQ_CONF_DEFAULT_CHARACTER_SET) !=
'utf-8') {
767 for ($i = 0; $i < strlen($value); ++$i) {
768 $ord = ord($value[$i]);
770 $result .=
'&#'.$ord.
';';
772 $result .= $value[$i];
775 if ($result !==
'') $value = $result;
776 $value = preg_replace(
'/(\r\n)+/',
'<br/>' ,$value);
778 $field_info[0][
'value']= $value;
782 echo
" <action_id>set_".$asset_id_map[$asset_id].
"_metadata_field_".$field_id.
"</action_id>\n";
783 echo
" <action_type>set_metadata_value</action_type>\n";
784 echo
" <asset>[[output://create_".$asset_id_map[$asset_id].
".assetid]]</asset>\n";
785 echo
" <fieldid>".(isset($asset_id_map[$field_id]) ?
"[[output://create_".$asset_id_map[$field_id].
".assetid]]" : $field_id).
"</fieldid>\n";
786 echo
" <value><![CDATA["._escapeCDATA($field_info[0][
'value']).
"]]></value>\n";
787 echo
"</action>\n\n";
791 $dependants = Array();
792 if (getAssetType($asset) !=
'Design_Customisation' && getAssetType($asset) !=
'Design') {
794 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
795 }
else if (getAssetType($asset) ==
'Design') {
796 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'', FALSE,
'major', NULL, TRUE);
797 }
else if (getAssetType($asset) ==
'Design_Customisation') {
801 $dependants = $asset->getCustomisedAreas();
804 $dependants = array_merge($dependants, $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_BACKEND_NAV,
'design_customisation'));
807 foreach ($dependants as $link_info) {
808 if (!strpos($link_info[
'minorid'],
':')) {
809 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
810 printMetadataXML($link_info[
'minorid']);
816 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
817 foreach ($children as $link_info) {
818 if (!strpos($link_info[
'minorid'],
':')) {
819 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
820 printMetadataXML($link_info[
'minorid']);
825 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
837 function getAssetType(&$asset)
839 $class = get_class($asset);
852 function echo_headline($s)
854 fwrite(STDERR,
"--------------------------------------\n$s\n--------------------------------------\n");
867 function echo_text($s)
869 fwrite(STDERR,
"$s\n");
881 function replace_system_assetid($assetid)
883 foreach($GLOBALS[
'SQ_SYSTEM']->am->_system_assetids as $asset_name => $asset_id){
884 if($assetid == $asset_id) {
901 function isSerialized($str)
903 return ($str == serialize(
false) || @unserialize($str) !==
false);
916 function _escapeCDATA($value)
918 return preg_replace(
'|(<\!\[CDATA\[.*?)\]\]>|ms',
'$1]]]]><![CDATA[>', $value);
931 function _updateParseFileForDesign($design_id, $parse_file_path)
934 'filename' => $design_id.
'_parse.txt',
935 'path' => $parse_file_path,
936 'type' =>
'txt_file',
943 $new_file_path = _saveFileAsset($null_asset, $file_info);
945 if ($new_file_path !=
'') {
947 echo
" <action_id>set_".$design_id.
"_parse_file</action_id>\n";
948 echo
" <action_type>set_design_parse_file</action_type>\n";
949 echo
" <asset>[[output://create_".$design_id.
".assetid]]</asset>\n";
950 echo
" <file_path>".$new_file_path.
"</file_path>\n";
951 echo
"</action>\n\n";