Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_menu_type.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
55  public function _getAllowedLinks()
56  {
57  return Array(
58  SQ_LINK_TYPE_1 => Array(),
59  SQ_LINK_TYPE_2 => Array(),
60  SQ_LINK_TYPE_3 => Array(),
61  SQ_LINK_NOTICE => Array('design_area_menu_type' => Array('card' => 'M', 'exclusive' => FALSE)),
62  );
63 
64  }//end _getAllowedLinks()
65 
66 
76  public function setAttrValue($name, $value)
77  {
78  // if they are trying to set an asset position dependent setting
79  if (substr($name, 0, 9) == 'settings.') {
80  // The name is in the form 'settings.[var_name].[setting type]'
81  // where setting type is either 'normal', 'heirarchy' or 'current'
82  $split = explode('.', $name);
83  if (count($split) != 3) {
84  trigger_localised_error('CORE0173', E_USER_WARNING, $name);
85  return FALSE;
86  }
87  switch ($split[2]) {
88  case 'normal' :
89  case 'hierarchy' :
90  case 'current' :
91  $new_value = $this->vars['settings']['value'];
92  if (!is_array($new_value)) $new_value = Array();
93  if (!isset($new_value[$split[1]])) {
94  $new_value[$split[1]] = Array();
95  }
96  $new_value[$split[1]][$split[2]] = $value;
97  $name = 'settings';
98  $value = $new_value;
99  break;
100 
101  default :
102  trigger_localised_error('CORE0174', E_USER_WARNING, $split[2]);
103  return FALSE;
104  }// end switch
105 
106  // if they are trying to set a level, so some validation
107  } else if ($name == 'level') {
108  switch (strtolower($value)) {
109  case 'top':
110  $value = 0;
111  break;
112  case 'sub':
113  $value = 1;
114  break;
115  case 'current':
116  $value = -1;
117  break;
118  case 'children':
119  $value = -2;
120  break;
121  default :
122  $value = (int) $value;
123  }// end switch
124  } else if (($name == 'unwanted_asset_types') && is_scalar($value)) {
125  $sub_menu_link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, 'design_area_menu_type', FALSE, 'sub_menu');
126  // Update sub menu attributes too
127  if (!empty($sub_menu_link)) {
128  $smenu = $GLOBALS['SQ_SYSTEM']->am->getAsset($sub_menu_link['minorid'], $sub_menu_link['minor_type_code'], TRUE);
129  $smenu->setAttrValue('unwanted_asset_types', $value);
130  $smenu->saveAttributes();
131  }//end foreach
132 
133  } else if (($name == 'wanted_asset_types') && is_scalar($value)) {
134  $sub_menu_link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, 'design_area_menu_type', FALSE, 'sub_menu');
135  // Update sub menu attributes too
136  if (!empty($sub_menu_link)) {
137  $smenu = $GLOBALS['SQ_SYSTEM']->am->getAsset($sub_menu_link['minorid'], $sub_menu_link['minor_type_code'], TRUE);
138  $smenu->setAttrValue('wanted_asset_types', $value);
139  $smenu->saveAttributes();
140  }//end foreach
141 
142  }// end if
143 
144  if (($name == 'unwanted_asset_types' || $name == 'wanted_asset_types') && is_scalar($value)) {
145 
146  $value = preg_split('/[ ,]+/', (string)$value);
147  foreach ($value as $type_code) {
148  if (!$GLOBALS['SQ_SYSTEM']->am->installed($type_code)) {
149  trigger_localised_error('CORE0145', E_USER_WARNING, $type_code);
150  return FALSE;
151  }
152  }// end foreach
153  }
154 
155 
156  return parent::setAttrValue($name, $value);
157 
158  }//end setAttrValue()
159 
160 
169  public function attr($name)
170  {
171  // if they are trying to set an asset position dependent setting
172  if (substr($name, 0, 9) == 'settings.') {
173  // The name is in the form 'settings.[var_name].[setting type]'
174  $split = explode('.', $name);
175  if (count($split) == 3) {
176  $settings = $this->attr('settings'); // do this so that any var references will be taken into account
177  if (isset($settings[$split[1]][$split[2]])) {
178  return $settings[$split[1]][$split[2]];
179  }
180  }// end if
181  }// end if
182 
183  // if we hit this, just send it upwards
184  return parent::attr($name);
185 
186  }//end attr()
187 
188 
195  public function getVarReferences()
196  {
197  $var_refs = parent::getVarReferences();
198  $sub_menu = $this->getSubMenu();
199  if (!is_null($sub_menu)) {
200  $sub_var_refs = $sub_menu->getVarReferences();
201  for (reset($sub_var_refs); NULL !== ($id_name = key($sub_var_refs)); next($sub_var_refs)) {
202  if (!isset($var_refs[$id_name])) {
203  $var_refs[$id_name] = Array();
204  }
205  foreach ($sub_var_refs[$id_name] as $var) {
206  if (in_array($var, $var_refs[$id_name])) continue;
207  $var_refs[$id_name][] = $var;
208  }// end foreach
209  }// end foreach
210  }// end if
211 
212  return $var_refs;
213 
214  }//end getVarReferences()
215 
216 
225  public function setVarReferenceValues(Array $var_ref_values)
226  {
227  $settings = $this->attr('settings');
228  $settings_changed = FALSE;
229  foreach ($this->vars['var_references']['value'] as $var_name => $info) {
230  // if this is a setting and it is available in the var_ref_values
231  if (substr($var_name, 0, 9) == 'settings.' && isset($var_ref_values[$info['id_name']][$info['var']])) {
232  // The name is in the form 'settings.[var_name].[setting type]'
233  $split = explode('.', $var_name);
234  if (count($split) == 3) {
235  if (!isset($settings[$split[1]])) {
236  $settings[$split[1]] = Array();
237  }
238  $settings[$split[1]][$split[2]] = $var_ref_values[$info['id_name']][$info['var']];
239  $settings_changed = TRUE;
240  }// end if
241  }// end if
242  }// end foreach
243 
244  if ($settings_changed) {
245  $this->_tmp['var_reference_values']['settings'] = $settings;
246  }
247 
248  // send our custom array to the parent fn
249  parent::setVarReferenceValues($var_ref_values);
250  $sub_menu = $this->getSubMenu();
251  if (!is_null($sub_menu)) {
252  // now send the original array to the sub
253  $sub_menu->setVarReferenceValues($var_ref_values);
254  }// end if
255 
256  }//end setVarReferenceValues()
257 
258 
265  public function getSubMenuLink()
266  {
267  if (empty($this->_tmp['sub_menu_link']) ||(!isset($this->_tmp['sub_menu_link']))) {
268  $this->_tmp['sub_menu_link'] = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, 'design_area_menu_type', FALSE, 'sub_menu');
269  }
270  return $this->_tmp['sub_menu_link'];
271 
272  }//end getSubMenuLink()
273 
274 
281  public function &getSubMenu()
282  {
283  $link = $this->getSubMenuLink();
284  if (empty($link)) {
285  $null = NULL;
286  return $null;
287  } else {
288  $smenu = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code'], TRUE);
289  return $smenu;
290  }
291 
292  }//end getSubMenu()
293 
294 
301  public function &getParentMenu()
302  {
303  if (!isset($this->_tmp['parent_menu_link'])) {
304  $this->_tmp['parent_menu_link'] = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, 'design_area_menu_type', FALSE, 'sub_menu', 'minor');
305  }
306  if (empty($this->_tmp['parent_menu_link'])) {
307  $null = NULL;
308  return $null;
309  } else {
310  $pmenu = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_tmp['parent_menu_link']['majorid'], $this->_tmp['parent_menu_link']['major_type_code'], TRUE) ;
311  return $pmenu;
312  }
313 
314  }//end getParentMenu()
315 
316 
325  public function linksUpdated()
326  {
327  parent::linksUpdated();
328  unset($this->_tmp['sub_menu_link']);
329  unset($this->_tmp['parent_menu_link']);
330 
331  }//end linksUpdated()
332 
333 
342  public function settingExists($name)
343  {
344  $settings = $this->attr('settings'); // do like this to take into account var refs
345  return !empty($settings[$name]);
346 
347  }//end settingExists()
348 
349 
359  public function printInitCode()
360  {
361  // Print output that is only required once per parse file (shared by all menu DAs)
362  echo '<', '?php
363  ';
364  $this->printStaticInitOutput();
365  echo '
366  ?', '>
367  ';
368 
369  parent::printInitCode();
370 
371  }//end printInitCode()
372 
373 
380  protected function _printInitCode()
381  {
382  echo '<', '?php
383  ';
384  $parent_menu = $this->getParentMenu();
385  // if we aren't a sub menu
386  if (is_null($parent_menu)) {
387  $this->printInitOutput();
388  echo '
389  if (!empty($ASSET_LINEAGE) && !empty($ASSET_LINEAGE[$'.$this->attr('id_name').'_level])) {
390  ';
391  $this->printDataCollection();
392  $this->_tmp['parent_assetid_name'] = '$ASSET_LINEAGE[$'.$this->attr('id_name').'_level][\'assetid\']';
393  } else {
394  $this->_tmp['parent_assetid_name'] = '$'.$parent_menu->attr('id_name').'_row[\'assetid\']';
395  }// end if
396 
397  echo '
398  $'.$this->attr('id_name').'_settings = '.var_export($this->_getSettingsArray(), TRUE).';
399  ';
400 
401  // if we aren't a sub menu
402  if (is_null($parent_menu)) {
403  echo '
404  }// end if found in ASSET_LINEAGE
405  ';
406  }// end if
407 
408  echo '
409  ?', '>';
410 
411  return TRUE;
412 
413  }//end _printInitCode()
414 
415 
426  protected function _printPaintingCode()
427  {
428  echo '
429  <?php
430  if (isset('.$this->_tmp['parent_assetid_name'].') && !empty($GLOBALS[\'MENU_DATA\']['.$this->_safeStringLiteral($this->attr('id_name')).']['.$this->_tmp['parent_assetid_name'].'])) {
431  ?', '>
432  ';
433 
434  parent::_printPaintingCode();
435 
436  echo '
437  <', '?php
438  }// end if subs '.$this->attr('id_name').'
439  ?>
440  ';
441 
442  }//end _printPaintingCode()
443 
444 
453  public function printStaticInitOutput()
454  {
455  // Stuff that is only needed once per design file
456  if (empty($GLOBALS['SQ_'.__CLASS__.__FUNCTION__.'_RUN_'.$GLOBALS['DESIGN_BEING_GENERATED']->id])) {
457  echo '
458  $db = MatrixDAL::getDb();
459 
460  require_once SQ_FUDGE_PATH.\'/db_extras/db_extras.inc\';
461  require_once SQ_CORE_PACKAGE_PATH.\'/designs/design_areas/menu/design_area_menu_type/menu_get_assets.inc\';
462 
463  $GLOBALS[\'MENU_DATA\'] = Array();
464 
465  ';
466  $GLOBALS['SQ_'.__CLASS__.__FUNCTION__.'_RUN_'.$GLOBALS['DESIGN_BEING_GENERATED']->id] = TRUE;
467  }//end if
468 
469  $sub_menu = $this->getSubMenu();
470  if (!is_null($sub_menu)) {
471  $sub_menu->printStaticInitOutput();
472  }
473 
474  }//end printStaticInitOutput()
475 
476 
483  public function printInitOutput()
484  {
485  $level = (int) $this->attr('level');
486  $parent_menu = $this->getParentMenu();
487  if (!is_null($parent_menu)) {
488  // we are a sub menu
489  if ($level == 0) {
490  // we dont have a specific level to print (or they want to print the top level - thats wierd)
491  // so dynamically get the level to print based on our parent's level at runtime
492  $level = NULL;
493  echo '
494  $'.$this->attr('id_name').'_level = $'.$parent_menu->attr('id_name').'_level + 1;';
495  }
496  }
497 
498  if (!is_null($level)) {
499  if ($level < 0) {
500  echo '
501  $'.$this->attr('id_name').'_level = (count($ASSET_LINEAGE) -2) + '.(-1 * ($level + 1)).';';
502  } else {
503  echo '
504  $'.$this->attr('id_name').'_level = '.$level.';';
505  }
506  }
507 
508  $sub_menu = $this->getSubMenu();
509  if (!is_null($sub_menu)) $sub_menu->printInitOutput();
510 
511  }//end printInitOutput()
512 
513 
521  public function printDataCollection()
522  {
524 
525  // the _assetids array holds all assetids that the sub level (if any) will printing kids of
526  // if the show_subs is only on_current the asset for the kids level in the asset lineage is used
527  echo '
528  $'.$this->attr('id_name').'_assetids = Array(); // menu_get_assets(majorids);
529  $'.$this->attr('id_name').'_urls = $am->getAssetURL($'.$this->attr('id_name').'_assetids);
530 
531  ';
532 
533  $sub_menu = $this->getSubMenu();
534  if (!is_null($sub_menu)) {
535  $sub_menu->printDataCollection();
536  }
537 
538  }//end printDataCollection()
539 
540 
552  public function printVar($var, Array $args, $value_prefix='', $value_suffix='')
553  {
554  // if they are trying to set an asset position dependent setting
555  if (substr($var, 0, 9) == 'settings.') {
556  // The name is in the form 'settings.[var_name].[setting type]'
557  list(,$setting_name) = explode('.', $var, 2);
558  if ($setting_name && $this->settingExists($setting_name)) {
559 
560  // we got php code ? OK, we need to use a switch statement
561  if ($this->_settingHasPHPCode($setting_name)) {
562  $settings = $this->attr('settings');
563  echo '<', '?php switch ($'.$this->attr('id_name').'_current_setting){ ';
564  foreach ($settings[$setting_name] as $case => $value) {
565  echo 'case \''.addslashes($case).'\' : ?','>', $value, '<','?php break; ';
566  }
567  echo '}// end switch ?', '>';
568 
569  // no php code ? cool, we can read from the array
570  } else {
571  echo '<', '?php echo $'.$this->attr('id_name').'_settings[\''.$setting_name.'\'][$'.$this->attr('id_name').'_current_setting]; ?', '>';
572 
573  }// end if
574 
575 
576  }// end if
577  } else {
578 
579  // if we are not in the asset looping section then we need to print the details of
580  // our parent asset - if we are not a sub menu there is nothing we can do
581  if (empty($this->_tmp['outputting_asset_section'])) {
582  $parent_menu = $this->getParentMenu();
583  // if we aren't a sub menu, there is nothing we can do
584  if (is_null($parent_menu)) {
585  $id_name = '';
586  } else {
587  $id_name = $parent_menu->attr('id_name');
588  }
589  // otherwise we are in the asset section and we want to print our data
590  } else {
591  $id_name = $this->attr('id_name');
592 
593  }
594 
595  switch ($var) {
596  case 'assetid' :
597  if ($id_name) {
598  echo '<', '?php echo $'.$id_name.'_row[\'assetid\']; ?', '>';
599  }
600  break;
601 
602  case 'asset_link' :
603  if ($id_name) {
604  echo '<', '?php echo $'.$id_name.'_urls[$'.$id_name.'_row[\'assetid\']].((SQ_LIMBO_EDITING) ? \'/\'.SQ_CONF_LIMBO_SUFFIX.\'?SQ_BACKEND_PAGE=main\' : \'\'); ?', '>';
605  }
606  break;
607 
608  case 'asset_short_name' :
609  if ($id_name) {
610  echo '<', '?php echo ', $this->_escapeVar($value_prefix.'htmlspecialchars($'.$id_name.'_row[\'short_name\'])'.$value_suffix, $args), '; ?', '>';
611  }
612  break;
613 
614  case 'asset_name' :
615  if ($id_name) {
616  echo '<', '?php echo ', $this->_escapeVar($value_prefix.'htmlspecialchars($'.$id_name.'_row[\'name\'])'.$value_suffix, $args), '; ?', '>';
617  }
618  break;
619 
620  case 'asset_name_linked' :
621  case 'asset_short_name_linked' :
622  if ($id_name) {
623 
624  $name_var = substr($var, 0, -7);
625 
626  if ($this->attr('self_link')) {
627  echo '<a href="', $this->printVar('asset_link', Array()), '">', $this->printVar($name_var, Array(), $value_prefix, $value_suffix), '</a>';
628  } else {
629  echo '<', '?php ', "\n";
630  echo ' if ($'.$id_name.'_current_setting == \'current\') { ', "\n";
631  echo '?', '>', $this->printVar($name_var, Array(), $value_prefix, $value_suffix), '<', '?php ', "\n";
632  echo '} else { ', "\n";
633  echo '?', '><a href="', $this->printVar('asset_link', Array()), '">', $this->printVar($name_var, Array(), $value_prefix, $value_suffix), '</a><', '?php ', "\n";
634  echo '}// end if ?', '>';
635  }// end if
636 
637  }// end if
638  break;
639 
640  case 'asset_thumbnail' :
641  if ($id_name) {
642  echo '<', '?php ';
643  echo '$thumbnail = NULL;'."\n";
644  echo '$thumbnail_asset = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($'.$id_name.'_row[\'assetid\']);'."\n";
645  echo 'if ($thumbnail_asset->useSystemVersion()) {'."\n";
646  echo ' $notice_links = unserialize(file_to_string($thumbnail_asset->data_path.\'/.sq_notice_links\'));'."\n";
647  echo ' foreach ($notice_links as $link) {'."\n";
648  echo ' if ($link[\'value\'] == \'thumbnail\') {'."\n";
649  echo ' $thumbnail = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($link[\'minorid\']);'."\n";
650  echo ' break;'."\n";
651  echo ' }'."\n";
652  echo ' }'."\n";
653  echo '} else {'."\n";
654  echo ' $link = $GLOBALS[\'SQ_SYSTEM\']->am->getLink($'.$id_name.'_row[\'assetid\'], SQ_LINK_NOTICE, \'image\', FALSE, \'thumbnail\');'."\n";
655  echo ' if (!empty($link)) {'."\n";
656  echo ' $thumbnail = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($link[\'minorid\']);'."\n";
657  echo ' }'."\n";
658  echo '}'."\n";
659  echo 'if ($thumbnail) echo $thumbnail->printImageTag(\'\', \'\', TRUE);'."\n";
660  echo '?', '>';
661  }
662  break;
663 
664  case 'asset_thumbnail_url' :
665  if ($id_name) {
666  echo '<', '?php ';
667  echo '$thumbnail = NULL;'."\n";
668  echo '$thumbnail_asset = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($'.$id_name.'_row[\'assetid\']);'."\n";
669  echo 'if ($thumbnail_asset->useSystemVersion()) {'."\n";
670  echo ' $notice_links = unserialize(file_to_string($thumbnail_asset->data_path.\'/.sq_notice_links\'));'."\n";
671  echo ' foreach ($notice_links as $link) {'."\n";
672  echo ' if ($link[\'value\'] == \'thumbnail\') {'."\n";
673  echo ' $thumbnail = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($link[\'minorid\']);'."\n";
674  echo ' break;'."\n";
675  echo ' }'."\n";
676  echo ' }'."\n";
677  echo '} else {'."\n";
678  echo ' $link = $GLOBALS[\'SQ_SYSTEM\']->am->getLink($'.$id_name.'_row[\'assetid\'], SQ_LINK_NOTICE, \'image\', FALSE, \'thumbnail\');'."\n";
679  echo ' if (!empty($link)) {'."\n";
680  echo ' $thumbnail = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($link[\'minorid\']);'."\n";
681  echo ' }'."\n";
682  echo '}'."\n";
683  echo 'if ($thumbnail) echo $thumbnail->getURL($'.$id_name.'_row[\'name\']);'."\n";
684  echo '?', '>';
685  }
686  break;
687 
688  case (preg_match('/^asset_/i', $var) ? $var : !$var):
689  echo '<', '?php ';
690  echo '$keyword = \'',$var, '\';';
691  echo '$ROW_ASSET = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($'.$id_name.'_row[\'assetid\']);';
692  echo 'if (!is_null($ROW_ASSET)) {';
693  echo '$replacement = '.$this->_escapeVar('$ROW_ASSET->getKeywordReplacement($keyword)', $args).';';
694  echo 'if ($replacement == $keyword) {';
695  echo ' echo \'\';';
696  echo '} else {';
697  echo ' echo $replacement;';
698  echo '}';
699  echo '$GLOBALS[\'SQ_SYSTEM\']->am->forgetAsset($ROW_ASSET);';
700  echo '} else {';
701  echo ' echo \'\';';
702  echo '}';
703  echo '?', '>';
704  break;
705 
706  default :
707  parent::printVar($var, $args);
708  }//end switch
709  }//end else
710 
711  }//end printVar()
712 
713 
722  public function _settingHasPHPCode($setting_name)
723  {
724  $settings = $this->attr('settings');
725  // OK we need out find out if any of the values for this setting have PHP code that needs to be
726  $has_php_code = FALSE;
727  foreach ($settings[$setting_name] as $case => $value) {
728  // we know that this will be the long format because only our design areas have put this in
729  if (strpos($value, '<'.'?php') !== FALSE) return TRUE;
730  }
731 
732  }//end _settingHasPHPCode()
733 
734 
741  public function _getSettingsArray()
742  {
743  $settings = $this->attr('settings');
744  // OK we need out find out if any of the values for this setting have PHP code that needs to be
745  $names = array_keys($settings);
746  foreach ($names as $setting_name) {
747  // we don't want any of the settings that need to be processed
748  if ($this->_settingHasPHPCode($setting_name)) {
749  unset($settings[$setting_name]);
750  }
751  }// end if
752 
753  return $settings;
754 
755  }//end _getSettingsArray()
756 
757 
767  public function getProtectedAttrs()
768  {
769  $res = parent::getProtectedAttrs();
770  $res[] = 'asset_contents';
771  $res[] = 'divider_contents';
772  $res[] = 'settings';
773  return $res;
774 
775  }//end getProtectedAttrs()
776 
777 
786  protected function _printContentItemCode(Array $element)
787  {
788  switch (array_get_index($element, 'operation')) {
789  case 'asset' :
790  if ($divider_contents = $this->attr('divider_contents')) {
791  ob_start();
792  foreach ($divider_contents as $item) {
793  $this->_printContentItemCode($item);
794  }
795  $divider = ob_get_contents();
796  ob_end_clean();
797  } else {
798  $divider = '';
799  }
800 
801  // should we start with a divider ?
802  if ($this->attr('prefix_with_divider')) echo $divider;
803 
804  echo '<', '?php
805 
806  $'.$this->attr('id_name').'_lineage_assetid = (empty($ASSET_LINEAGE[$'.$this->attr('id_name').'_level + 1])) ? 0 : $ASSET_LINEAGE[$'.$this->attr('id_name').'_level + 1][\'assetid\'];
807  $'.$this->attr('id_name').'_lineage_setting = (count($ASSET_LINEAGE) - 1 == $'.$this->attr('id_name').'_level + 1) ? \'current\' : \'hierarchy\';
808 
809  ';
810  $parent_menu = $this->getParentMenu();
811  // if we aren't a sub menu
812  if (is_null($parent_menu)) {
813  $this->_tmp['parent_assetid_name'] = '$ASSET_LINEAGE[$'.$this->attr('id_name').'_level][\'assetid\']';
814 
815  echo '
816  $'.$this->attr('id_name').'_base_url = (empty($ASSET_LINEAGE[$'.$this->attr('id_name').'_level])) ? \'\' : current_protocol().\'://\'.$ASSET_LINEAGE[$'.$this->attr('id_name').'_level][\'url\'];
817  $'.$this->attr('id_name').'_urls = $am->getAssetURL(array_keys($GLOBALS[\'MENU_DATA\']['.$this->_safeStringLiteral($this->attr('id_name')).'][$ASSET_LINEAGE[$'.$this->attr('id_name').'_level][\'assetid\']]), $'.$this->attr('id_name').'_base_url);
818  ';
819 
820  } else {
821  $this->_tmp['parent_assetid_name'] = '$'.$parent_menu->attr('id_name').'_row[\'assetid\']';
822 
823  echo '
824  $'.$this->attr('id_name').'_base_url = $'.$parent_menu->attr('id_name').'_urls[$'.$parent_menu->attr('id_name').'_row[\'assetid\']];
825  $'.$this->attr('id_name').'_urls = $am->getAssetURL(array_keys($GLOBALS[\'MENU_DATA\']['.$this->_safeStringLiteral($this->attr('id_name')).'][$'.$parent_menu->attr('id_name').'_row[\'assetid\']]), $'.$this->attr('id_name').'_base_url);
826  ';
827 
828  }// end if
829 
830  // if there is a divider to deal with and
831  // if there is not divider at the end we these vars
832  if ($divider != '' && !$this->attr('suffix_with_divider')) {
833  echo '
834 
835  $'.$this->attr('id_name').'_i = -1;
836  $'.$this->attr('id_name').'_total = count($GLOBALS[\'MENU_DATA\']['.$this->_safeStringLiteral($this->attr('id_name')).']['.$this->_tmp['parent_assetid_name'].']);
837  ';
838  }
839 
840  echo '
841 
842  foreach ($GLOBALS[\'MENU_DATA\']['.$this->_safeStringLiteral($this->attr('id_name')).']['.$this->_tmp['parent_assetid_name'].'] as $'.$this->attr('id_name').'_row) {
843  $'.$this->attr('id_name').'_current_setting = ($'.$this->attr('id_name').'_lineage_assetid == $'.$this->attr('id_name').'_row[\'assetid\']) ? $'.$this->attr('id_name').'_lineage_setting : \'normal\';
844  ?', '>';
845 
846  $unwanted_types = $this->attr('unwanted_asset_types');
847  $all_type_codes = Array();
848  foreach ($unwanted_types as $type) {
849  if (!empty($type)) {
850  $all_type_codes = array_merge($all_type_codes, $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type, TRUE));
851  }
852  }
853  $unwanted_types = $all_type_codes;
854 
855  if (!empty($unwanted_types)) {
856  $unwanted_types_literal_array = 'Array("'.implode('", "', $unwanted_types).'")';
857  // We are sub menu
858  echo '<?php if (in_array($'.$this->attr('id_name').'_row[\'type_code\'], '.$unwanted_types_literal_array.')) continue ;?>';
859  }//end if
860 
861  $wanted_types = $this->attr('wanted_asset_types');
862  $all_type_codes = Array();
863  foreach ($wanted_types as $type) {
864  if (!empty($type)) {
865  $all_type_codes = array_merge($all_type_codes, $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type, TRUE));
866  }
867  }
868  $wanted_types = $all_type_codes;
869 
870  if (!empty($wanted_types)) {
871  $wanted_types_literal_array = 'Array("'.implode('", "', $wanted_types).'")';
872  echo '<?php if (!in_array($'.$this->attr('id_name').'_row[\'type_code\'], '.$wanted_types_literal_array.')) continue ;?>';
873  }
874 
875  if ($this_contents = $this->attr('asset_contents')) {
876  $this->_tmp['outputting_asset_section'] = TRUE;
877  foreach ($this_contents as $item) {
878  $this->_printContentItemCode($item);
879  }
880  unset($this->_tmp['outputting_asset_section']);
881  }
882 
883 
884 
885  // if there is a divider to deal with
886  if ($divider != '') {
887 
888  // if there is not divider at the end we need to check that we aren't at the end of the list
889  if (!$this->attr('suffix_with_divider')) {
890  echo '<', '?php
891  $'.$this->attr('id_name').'_i++;
892  if ($'.$this->attr('id_name').'_i != $'.$this->attr('id_name').'_total - 1) {
893  ?','>';
894  }
895 
896  echo $divider;
897 
898  // if there is not divider at the end we need to check that we aren't at the end of the list
899  if (!$this->attr('suffix_with_divider')) {
900  echo '<','?php
901  }// end if
902  ?','>';
903  }
904 
905  }// end if divider
906 
907  echo '<', '?php
908  }// end foreach '.$this->attr('id_name').' data
909  ?', '>';
910 
911  return TRUE;
912 
913  case 'sub' :
914  $sub = $this->getSubMenu();
915  if (is_null($sub)) return TRUE;
916 
917  // See if this menu has a customisation underneath it
918  // If does, use the customised settings in this asset
919  $current_designs = $sub->getDesigns();
920  foreach ($current_designs as $current_design) {
921 
922  if (is_null($current_design)) continue;
923 
924  // Find the current customisations
925  $customisation_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($current_design->id, SQ_LINK_TYPE_2, 'design_customisation', TRUE, 'major', 'customisation');
926  $am =& $GLOBALS['SQ_SYSTEM']->am;
927  foreach ($customisation_links as $link) {
928  $customisation = $am->getAsset($link['minorid'], $link['minor_type_code']);
929  if (is_null($customisation)) continue;
930 
931  // Do something
932  $custom_das = $customisation->getCustomisedAreas();
933  foreach ($custom_das as $custom_da) {
934  if ($custom_da['minorid'] != $sub->id) {
935  $new_da = $am->getAsset($custom_da['minorid'], $custom_da['minor_type_code']);
936  if (is_null($new_da)) continue;
937  if ($new_da->name == $sub->name) {
938  foreach ($new_da->vars as $name => $details) {
939  if (in_array($name, Array('unwanted_asset_types', 'self_link', 'wanted_asset_types'))) {
940  $sub->vars[$name] = $new_da->vars[$name];
941  }
942  }
943  }//end if
944  }//end if
945  }//end foreach
946  }//end foreach
947  }//end foreach
948  return $sub->printAreaCode();
949 
950  default :
951  return parent::_printContentItemCode($element);
952  }//end switch
953 
954  }//end _printContentItemCode()
955 
956 }//end class
957 ?>