Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
hipo_job_export_assets_to_xml.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
19 
20 
36 {
37 
38 
39  public $import_action_outputs = Array();
40 
46  function HIPO_Job_Export_Assets_To_Xml($code_name='')
47  {
48  $this->uses_trans = FALSE;
49  $this->HIPO_Job($code_name);
50 
51  }//end constructor
52 
53 
60  function getCodeName()
61  {
62  return 'HIPO_Job_Export_Assets_To_Xml-'.md5($this->_running_vars['root_node_mapping'].$this->_running_vars['export_path']);
63 
64  }//end getCodeName()
65 
66 
73  function getHipoName()
74  {
75  return translate('tool_export_assets_to_xml_hipo_name');
76 
77  }//end getHipoName()
78 
79 
87  function getInitialStepData()
88  {
89  return Array(
90  Array(
91  'name' => translate('tool_export_assets_to_xml_hipo_name'),
92  'function_call' => Array(
93  'process_function' => 'processExportAsset',
94  ),
95  'running_mode' => 'server',
96  'auto_step' => TRUE,
97  'allow_cancel' => TRUE,
98  'percent_done' => 0,
99  'complete' => FALSE,
100  'message' => '',
101  'header_set' => FALSE,
102  ),
103  );
104 
105  }//end getInitialStepData()
106 
107 
114  function freestyle()
115  {
116  $step_data['complete'] = FALSE;
117  while(!$step_data['complete']) {
118  if($this->processExportAsset($step_data, '')) {
119  return FALSE;
120  }
121  }
122 
123  return TRUE;
124 
125  }//end freestyle()
126 
127 
134  function prepare()
135  {
136  // 5 components
137  $this->_running_vars['sections'] = Array('create', 'attribute', 'metadata', 'link', 'permission');
138  // a temp array to record all imported asset ids
139  $this->_running_vars['asset_id_map'] = Array();
140 
141  return parent::prepare();
142 
143  }//end prepare()
144 
145 
155  function processExportAsset(&$step_data, $prefix)
156  {
157  $path = $this->_running_vars['export_path'];
158  $asset_infos = $this->_running_vars['root_node_mapping'];
159  $initial_link_type = SQ_LINK_TYPE_1;
160  $action = array_shift($this->_running_vars['sections']);
161  ob_start();
162  if (!$step_data['header_set']) {
163  echo "<?xml version=\"1.0\" encoding=\"".SQ_CONF_DEFAULT_CHARACTER_SET."\"?>\n";
164  $step_data['header_set'] = TRUE;
165  }
166  switch ($action) {
167  case 'create':
168  echo "<actions>\n";
169  foreach($asset_infos as $asset_info) {
170  $asset_from_to_id = explode(':',$asset_info);
171  if(!isset($asset_from_to_id[0]) || !isset($asset_from_to_id[1])) trigger_error("Failed to parse second argument\n", E_USER_ERROR);
172  $this->printCreateXML($asset_from_to_id[0], $asset_from_to_id[1], $initial_link_type);
173  }
174  $step_data['percent_done'] = 20;
175  $step_data['complete'] = FALSE;
176  break;
177  case 'attribute':
178  foreach($asset_infos as $asset_info) {
179  $asset_from_to_id = explode(':',$asset_info);
180  if(!isset($asset_from_to_id[0])) trigger_error("Failed to parse second argument\n", E_USER_ERROR);
181  $this->printAttributeXML($asset_from_to_id[0]);
182  }
183  $step_data['percent_done'] = 40;
184  $step_data['complete'] = FALSE;
185  break;
186  case 'metadata':
187  foreach($asset_infos as $asset_info) {
188  $asset_from_to_id = explode(':',$asset_info);
189  if(!isset($asset_from_to_id[0])) trigger_error("Failed to parse second argument\n", E_USER_ERROR);
190  $this->printMetadataXML($asset_from_to_id[0]);
191  }
192  $step_data['percent_done'] = 60;
193  $step_data['complete'] = FALSE;
194  break;
195  case 'link':
196  foreach($asset_infos as $asset_info) {
197  $asset_from_to_id = explode(':',$asset_info);
198  if(!isset($asset_from_to_id[0])) trigger_error("Failed to parse second argument\n", E_USER_ERROR);
199  $this->printNoticeLinksXML($asset_from_to_id[0]);
200  }
201  $step_data['percent_done'] = 80;
202  $step_data['complete'] = FALSE;
203  break;
204  case 'permission':
205  foreach($asset_infos as $asset_info) {
206  $asset_from_to_id = explode(':',$asset_info);
207  if(!isset($asset_from_to_id[0])) trigger_error("Failed to parse second argument\n", E_USER_ERROR);
208  $this->printPermissionXML($asset_from_to_id[0]);
209  }
210  echo "</actions>\n\n";
211  $step_data['percent_done'] = 100;
212  $step_data['complete'] = TRUE;
213  break;
214  }
215 
216  $output = ob_get_clean();
217 
218  file_put_contents($path.'/export.xml', $output, FILE_APPEND | LOCK_EX);
219 
220 
221  return TRUE;
222 
223  }//end processExportAsset()
224 
225 
226 
227 
228 
242  function printCreateXML($asset_id, $parent, $link_type, $value='', $is_dependant=0, $is_exclusive=0) {
243 
244 
245  $asset = &$GLOBALS['SQ_SYSTEM']->am->getAsset($asset_id);
246  if (is_null($asset)) exit();
247 
248  // system assets are not allowed to be exported.
249  if ($this->replace_system_assetid($asset->id) != NULL) trigger_error("Can not export system asset!\n", E_USER_ERROR);
250 
251 
252  $action_code = $this->getAssetType($asset).'_'.$asset->id;
253 
254  $this->_running_vars['asset_id_map'][$asset->id] = $action_code;
255 
256  echo "<action>\n";
257  echo " <action_id>create_".$action_code."</action_id>\n";
258 
259  if ($GLOBALS['SQ_SYSTEM']->am->isTypeDecendant($this->getAssetType($asset), 'file')) {
260  $file_path = $this->_saveFileAsset($asset);
261  echo " <action_type>create_file_asset</action_type>\n";
262  echo " <file_path>".$file_path."</file_path>\n";
263  } else {
264  echo " <action_type>create_asset</action_type>\n";
265  }
266 
267  echo " <type_code>".$this->getAssetType($asset)."</type_code>\n";
268  echo " <link_type>".$link_type."</link_type>\n";
269  echo " <parentid>".$parent."</parentid>\n";
270  echo " <value>".$value."</value>\n";
271  echo " <is_dependant>".$is_dependant."</is_dependant>\n";
272  echo " <is_exclusive>".$is_exclusive."</is_exclusive>\n";
273  echo "</action>\n\n";
274 
275 
276  // then, if it has web paths, we add those
277  $paths = $asset->getWebPaths();
278  foreach ($paths as $path) {
279 
280  echo "<action>\n";
281  echo " <action_id>add_".$action_code."_path</action_id>\n";
282  echo " <action_type>add_web_path</action_type>\n";
283  echo " <asset>[[output://create_".$action_code.".assetid]]</asset>\n";
284  echo " <path>".$path."</path>\n";
285  echo "</action>\n\n";
286  }
287 
288 
289  // Then, if it has dependant children, we add those too
290  $dependants = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, TRUE);
291  foreach ($dependants as $link_info) {
292  if (!strpos($link_info['minorid'], ':')) {
293  $parent = '[[output://create_'.$action_code.'.assetid]]';
294 
295  // If the asset already exists, let's link to it; otherwise, create it.
296  if (array_key_exists($link_info['minorid'], $this->_running_vars['asset_id_map'])) {
297  $this->printLinkXML($parent, $link_info, $action_code);
298  } else {
299  $this->printCreateXML($link_info['minorid'], $parent, $link_info['link_type'], $link_info['value'], $link_info['is_dependant'], $link_info['is_exclusive']);
300  }
301 
302  }
303  }
304 
305  // Now let's do the non-dependant children, shall we?
306  $children = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, 0);
307  foreach ($children as $link_info) {
308  if (!strpos($link_info['minorid'], ':')) {
309  $parent = '[[output://create_'.$action_code.'.assetid]]';
310 
311  if (array_key_exists($link_info['minorid'], $this->_running_vars['asset_id_map'])) {
312  $this->printLinkXML($parent, $link_info, $action_code);
313  } else {
314  $this->printCreateXML($link_info['minorid'], $parent, $link_info['link_type'], $link_info['value'], $link_info['is_dependant'], $link_info['is_exclusive']);
315  }
316 
317  }
318  }
319 
320 
321  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
322 
323  }//end printXML
324 
335  function printLinkXML($parent, $link_info, $action_code) {
336 
337  // if we created the asset, get it from array, otherwise, if it's a system asset, we have to use system asset name.
338  if (isset($this->_running_vars['asset_id_map'][$link_info['minorid']])){
339  $remap_id = "[[output://create_".$this->_running_vars['asset_id_map'][$link_info['minorid']].".assetid]]";
340  }
341  else {
342  //before we use asset id, we should make sure if it's a system asset, we use system asset name instead of id.
343  //because new system may have different system assets ids.
344  $system_asset_name = $this->replace_system_assetid($link_info['minorid']);
345  $system_asset_name == NULL ? $remap_id = $link_info['minorid'] : $remap_id = "[[system://".$system_asset_name."]]" ;
346  }
347 
348  echo "<action>\n";
349  echo " <action_id>link_".$action_code."</action_id>\n";
350  echo " <action_type>create_link</action_type>\n";
351  echo " <asset>".$remap_id."</asset>\n";
352  echo " <assetid>".$parent."</assetid>\n";
353  echo " <is_major>0</is_major>\n";
354  echo " <link_type>".$link_info['link_type']."</link_type>\n";
355  echo " <value>".$link_info['value']."</value>\n";
356  echo " <is_dependant>".$link_info['is_dependant']."</is_dependant>\n";
357  echo " <is_exclusive>".$link_info['is_exclusive']."</is_exclusive>\n";
358  echo "</action>\n\n";
359 
360  }// end printLinkXML()
361 
362 
371  function printAttributeXML($asset_id) {
372 
373  $assets_done = Array();
374 
375  $asset = &$GLOBALS['SQ_SYSTEM']->am->getAsset($asset_id);
376  if (is_null($asset)) exit();
377 
378  // print some attributes
379  foreach ($asset->vars as $attr_name => $attr_info) {
380  $attr = $asset->getAttribute($attr_name);
381  $value = $attr->getContent();
382  // unserilize it, we want clean script
383  if($this->isSerialized($value) && !empty($value)){
384  $value = var_export(unserialize($value),TRUE);
385  }
386  // if the value is an assetid attribute, we should match it with asset_id_map first
387  if (preg_match("/assetid/",$attr_name) && isset($this->_running_vars['asset_id_map'][$value])){
388  $value = "[[output://create_".$this->_running_vars['asset_id_map'][$value].".assetid]]";
389  }
390  $assets_done[$asset->id] = TRUE;
391 
392  if (!empty($value)) {
393  echo "<action>\n";
394  echo " <action_id>set_".$this->_running_vars['asset_id_map'][$asset_id].'_'.$attr_name."</action_id>\n";
395  echo " <action_type>set_attribute_value</action_type>\n";
396  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
397  echo " <attribute>".$attr_name."</attribute>\n";
398  if ($attr_name == 'html') { $value = $this->_parseValue($value); }
399  echo " <value><![CDATA[".$value."]]></value>\n";
400  echo "</action>\n\n";
401  }
402  }
403 
404  // Then, if it has dependant children, we add those too
405  $dependants = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, TRUE);
406  foreach ($dependants as $link_info) {
407  if (!strpos($link_info['minorid'], ':')) {
408  if (!array_key_exists($link_info['minorid'], $assets_done)) {
409  $this->printAttributeXML($link_info['minorid']);
410  }
411  }
412  }
413 
414  // Now let's do the non-dependant children, shall we?
415  $children = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, 0);
416  foreach ($children as $link_info) {
417  if (!strpos($link_info['minorid'], ':')) {
418  if (!array_key_exists($link_info['minorid'], $assets_done)) {
419  $this->printAttributeXML($link_info['minorid']);
420  }
421  }
422  }
423 
424  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
425 
426  }//end printAttributeXML()
427 
428 
437  function printNoticeLinksXML($asset_id) {
438 
439  $assets_done = Array();
440 
441  $notice_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset_id, SQ_LINK_NOTICE, '', FALSE, 'major');
442 
443  foreach ($notice_links as $notice_link) {
444  // if we created the asset, get it from array, otherwise, if it's a system asset, we have to use system asset name.
445  if (isset($this->_running_vars['asset_id_map'][$asset_id])){
446  $remap_id = "[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]" ;
447  }
448  else {
449  //before we use asset id, we should make sure if it's a system asset, we use system asset name instead of id.
450  //because new system may have different system assets ids.
451  $system_asset_name = $this->replace_system_assetid($asset_id);
452  $system_asset_name == NULL ? $remap_id = $asset_id : $remap_id = "[[system://".$system_asset_name."]]" ;
453  }
454  $this->printLinkXML($remap_id, $notice_link, 'notice_'.$asset_id.'_to_'.$notice_link['minorid']);
455 
456  }//end foreach
457 
458  $assets_done[$asset_id] = TRUE;
459 
460  // Then, if it has dependant children, we add those too
461  $dependants = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, TRUE);
462  foreach ($dependants as $link_info) {
463  if (!strpos($link_info['minorid'], ':')) {
464  if (!array_key_exists($link_info['minorid'], $assets_done)) {
465  $this->printNoticeLinksXML($link_info['minorid']);
466  }
467  }
468  }
469 
470  // Now let's do the non-dependant children, shall we?
471  $children = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, 0);
472  foreach ($children as $link_info) {
473  if (!strpos($link_info['minorid'], ':')) {
474  if (!array_key_exists($link_info['minorid'], $assets_done)) {
475  $this->printNoticeLinksXML($link_info['minorid']);
476  }
477  }
478  }
479 
480 
481  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
482 
483  }//end printNoticeLinksXML()
484 
485 
486 
495  function printPermissionXML($asset_id) {
496 
497  $assets_done = Array();
498 
499  // Now, some permissions
500  $read_permissions = $GLOBALS['SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_READ, NULL, FALSE, FALSE, TRUE, TRUE);
501  foreach ($read_permissions as $permission_id => $permission_granted) {
502  // if the asset is created by this script, use asset_id_map
503  if (isset($this->_running_vars['asset_id_map'][$permission_id])){
504  $remap_id = "[[output://create_".$this->_running_vars['asset_id_map'][$permission_id].".assetid]]" ;
505  }
506  else {
507  //if it's a system asset, we use system asset name instead of id.
508  //because new system may have different system assets ids.
509  $system_asset_name = $this->replace_system_assetid($permission_id);
510  $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id = "[[system://".$system_asset_name."]]" ;
511  }
512 
513 
514 
515  // if the action is to deny a previous permission, make sure we will remove the permission first
516  // and if there is no existing permission to remove, fail silently
517  if($permission_granted == 0) {
518  echo "<action>\n";
519  echo " <action_id>set_permission_".$asset_id."_read_".$permission_id."</action_id>\n";
520  echo " <action_type>set_permission</action_type>\n";
521  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
522  echo " <permission>1</permission>\n";
523  echo " <mute_error>1</mute_error>\n";
524  echo " <granted>-1</granted>\n";
525  echo " <userid>".$remap_id."</userid>\n";
526  echo "</action>\n";
527  }
528  echo "<action>\n";
529  echo " <action_id>set_permission_".$asset_id."_read_".$permission_id."</action_id>\n";
530  echo " <action_type>set_permission</action_type>\n";
531  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
532  echo " <permission>1</permission>\n";
533  echo " <granted>".$permission_granted."</granted>\n";
534  echo " <userid>".$remap_id."</userid>\n";
535  echo "</action>\n";
536 
537  }//end foreach
538 
539  $write_permissions = $GLOBALS['SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_WRITE, NULL, FALSE, FALSE, TRUE, TRUE);
540  foreach ($write_permissions as $permission_id => $permission_granted) {
541 
542  // if the asset is created by this script, use asset_id_map
543  if (isset($this->_running_vars['asset_id_map'][$permission_id])){
544  $remap_id = "[[output://create_".$this->_running_vars['asset_id_map'][$permission_id].".assetid]]" ;
545  }
546  else {
547  //if it's a system asset, we use system asset name instead of id.
548  //because new system may have different system assets ids.
549  $system_asset_name = $this->replace_system_assetid($permission_id);
550  $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id = "[[system://".$system_asset_name."]]" ;
551  }
552 
553  // if the action is to deny a previous permission, make sure we will remove the permission first
554  // and if there is no existing permission to remove, fail silently
555  if($permission_granted == 0) {
556  echo "<action>\n";
557  echo " <action_id>set_permission_".$asset_id."_write_".$permission_id."</action_id>\n";
558  echo " <action_type>set_permission</action_type>\n";
559  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
560  echo " <mute_error>1</mute_error>\n";
561  echo " <permission>2</permission>\n";
562  echo " <granted>-1</granted>\n";
563  echo " <userid>".$remap_id."</userid>\n";
564  echo "</action>\n";
565  }
566  echo "<action>\n";
567  echo " <action_id>set_permission_".$asset_id."_write_".$permission_id."</action_id>\n";
568  echo " <action_type>set_permission</action_type>\n";
569  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
570  echo " <permission>2</permission>\n";
571  echo " <granted>".$permission_granted."</granted>\n";
572  echo " <userid>".$remap_id."</userid>\n";
573  echo "</action>\n";
574 
575  }//end foreach
576 
577  $admin_permissions = $GLOBALS['SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_ADMIN, NULL, FALSE, FALSE, TRUE, TRUE);
578  foreach ($admin_permissions as $permission_id => $permission_granted) {
579 
580  if (isset($this->_running_vars['asset_id_map'][$permission_id])){
581  $remap_id = "[[output://create_".$this->_running_vars['asset_id_map'][$permission_id].".assetid]]" ;
582  }
583  else {
584  $system_asset_name = $this->replace_system_assetid($permission_id);
585  $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id = "[[system://".$system_asset_name."]]" ;
586  }
587 
588  // if the action is to deny a previous permission, make sure we will remove the permission first
589  // and if there is no existing permission to remove, fail silently
590  if($permission_granted == 0) {
591  echo "<action>\n";
592  echo " <action_id>set_permission_".$asset_id."_admin_".$permission_id."</action_id>\n";
593  echo " <action_type>set_permission</action_type>\n";
594  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
595  echo " <mute_error>1</mute_error>\n";
596  echo " <permission>3</permission>\n";
597  echo " <granted>-1</granted>\n";
598  echo " <userid>".$remap_id."</userid>\n";
599  echo "</action>\n";
600  }
601  echo "<action>\n";
602  echo " <action_id>set_permission_".$asset_id."_admin_".$permission_id."</action_id>\n";
603  echo " <action_type>set_permission</action_type>\n";
604  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
605  echo " <permission>3</permission>\n";
606  echo " <granted>".$permission_granted."</granted>\n";
607  echo " <userid>".$remap_id."</userid>\n";
608  echo "</action>\n";
609 
610  }//end foreach
611 
612  $assets_done[$asset_id] = TRUE;
613 
614  // Then, if it has dependant children, we add those too
615  $dependants = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, TRUE);
616  foreach ($dependants as $link_info) {
617  if (!strpos($link_info['minorid'], ':')) {
618  if (!array_key_exists($link_info['minorid'], $assets_done)) {
619  $this->printPermissionXML($link_info['minorid']);
620  }
621  }
622  }
623 
624  // Now let's do the non-dependant children, shall we?
625  $children = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, 0);
626  foreach ($children as $link_info) {
627  if (!strpos($link_info['minorid'], ':')) {
628  if (!array_key_exists($link_info['minorid'], $assets_done)) {
629  $this->printPermissionXML($link_info['minorid']);
630  }
631  }
632  }
633 
634 
635  }//end printPermissionXML()
636 
637 
646  function printMetadataXML($asset_id) {
647 
648  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
649  $assets_done = Array();
650 
651  $asset = &$GLOBALS['SQ_SYSTEM']->am->getAsset($asset_id);
652  if (is_null($asset)) exit();
653 
654  foreach($mm->getSchemas($asset_id) as $schema_id => $granted) {
655  $schema_info = $mm->getAssetSchemaInfo($asset_id, $schema_id);
656  echo "<action>\n";
657  echo " <action_id>set_".$this->_running_vars['asset_id_map'][$asset_id]."_metadata_schema_".$schema_id."</action_id>\n";
658  echo " <action_type>set_metadata_schema</action_type>\n";
659  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
660  echo " <schemaid>".(isset($this->_running_vars['asset_id_map'][$schema_id]) ? "[[output://create_".$this->_running_vars['asset_id_map'][$schema_id].".assetid]]" : $schema_id)."</schemaid>\n";
661  echo " <granted>".$schema_info['granted']."</granted>\n";
662  echo " <cascades>".$schema_info['cascades']."</cascades>\n";
663  echo "</action>\n\n";
664 
665  $metadata = $mm->getMetadata($asset_id, $schema_id);
666  foreach ($metadata as $field_id => $field_info) {
667  echo "<action>\n";
668  echo " <action_id>set_".$this->_running_vars['asset_id_map'][$asset_id]."_metadata_field_".$field_id."</action_id>\n";
669  echo " <action_type>set_metadata_value</action_type>\n";
670  echo " <asset>[[output://create_".$this->_running_vars['asset_id_map'][$asset_id].".assetid]]</asset>\n";
671  echo " <fieldid>".(isset($this->_running_vars['asset_id_map'][$field_id]) ? "[[output://create_".$this->_running_vars['asset_id_map'][$field_id].".assetid]]" : $field_id)."</fieldid>\n";
672  echo " <value><![CDATA[".$field_info[0]['value']."]]></value>\n";
673  echo "</action>\n\n";
674  } // end foreach metadata
675  } // end foreach schema
676 
677  // Then, if it has dependant children, we add those too
678  $dependants = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, TRUE);
679  foreach ($dependants as $link_info) {
680  if (!strpos($link_info['minorid'], ':')) {
681  if (!array_key_exists($link_info['minorid'], $assets_done)) {
682  $this->printMetadataXML($link_info['minorid']);
683  }
684  }
685  }
686 
687  // Now let's do the non-dependant children, shall we?
688  $children = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT, '', FALSE, 'major', NULL, 0);
689  foreach ($children as $link_info) {
690  if (!strpos($link_info['minorid'], ':')) {
691  if (!array_key_exists($link_info['minorid'], $assets_done)) {
692  $this->printMetadataXML($link_info['minorid']);
693  }
694  }
695  }
696 
697  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
698 
699  }//end printMetadataXML()
700 
701 
710  private function _saveFileAsset(&$asset) {
711 
712  $path = $this->_running_vars['export_path'];
713  $file_info = $asset->getExistingFile();
714  $file_type = $this->getAssetType($asset);
715  $export_path = $path.'/export/'.$file_type.'/'.$file_info['filename'];
716 
717  // check to see if an export/ directory exists. If not, create it.
718  if (!file_exists($path.'/export/')) {
719  mkdir($path.'/export', 0775);
720  }
721 
722  // echeck to see if the type_code directory exists
723  if (!file_exists($path.'/export/'.$file_type.'/')) {
724  mkdir($path.'/export/'.$file_type, 0775);
725  }
726 
727  if (copy($file_info['path'], $export_path)) {
728  return 'export/'.$file_type.'/'.$file_info['filename'];
729  } else {
730  die('Could not copy file');
731  }
732 
733 
734  }//end _saveFileAsset()
735 
736 
745  function _parseValue($value) {
746  $shadow_reg = '|.\/?a=(\d+:\w*)|';
747  $normal_reg = '|.\/?a=(\d+)|';
748  $shadow_matches = Array();
749  $normal_matches = Array();
750 
751  preg_match_all($shadow_reg, $value, $shadow_matche);
752  preg_match_all($normal_reg, $value, $normal_matches);
753 
754  if(isset($shadow_matches[1])) $shadow_matches = $shadow_matches[1];
755  if(isset($normal_matches[1])) $normal_matches = $normal_matches[1];
756  $replace_assetids = Array();
757  foreach ($shadow_matches as $data) {
758  $replace_assetids[] = $data;
759  }
760  foreach ($normal_matches as $data) {
761  $replace_assetids[] = $data;
762  }
763  $replace_assetids = array_unique($replace_assetids);
764 
765  foreach ($replace_assetids as $replace_assetid) {
766  if (isset($this->_running_vars['asset_id_map'][$replace_assetid])) {
767  $value = preg_replace('|.\/?a='.$replace_assetid.'|', '?a=[[output://create_'.$this->_running_vars['asset_id_map'][$replace_assetid].'.assetid]]', $value);
768  }
769  }
770 
771  return $value;
772 
773  }// end _parseValue()
774 
775 
783  function getAssetType(&$asset)
784  {
785  $class = get_class($asset);
786  return $class;
787 
788  }//end getAssetType()
789 
790 
799  function replace_system_assetid($assetid){
800  foreach($GLOBALS['SQ_SYSTEM']->am->_system_assetids as $asset_name => $asset_id){
801  if($assetid == $asset_id) {
802  return $asset_name;
803  }
804  }
805  return NULL;
806  }
807 
808 
817  function isSerialized($str) {
818  return ($str == serialize(false) || @unserialize($str) !== false);
819  }
820 
821 
822 
823 }//end class
824 
825 ?>