Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_asset_lineage.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 
59  public function printVar($var, Array $args, $value_prefix='', $value_suffix='')
60  {
61  switch ($var) {
62  case 'assetid' :
63  echo '<', '?php echo $ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'assetid\']; ?', '>';
64  break;
65 
66  case 'asset_link' :
67  echo '<', '?php echo $ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'protocol\'].\'://\'.$ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'url\']; ?', '>';
68  break;
69 
70  case 'asset_short_name' :
71  case 'asset_name' :
72  echo '<', '?php echo ', $this->_escapeVar($value_prefix.'htmlspecialchars($ASSET_LINEAGE[$'.$this->attr('id_name').'_i]['.var_export((string) substr($var, 6), TRUE).'])'.$value_suffix, $args), '; ?', '>';
73  break;
74 
75  case 'lineage_level' :
76  echo '<', '?php echo ', '$'.$this->attr('id_name').'_i; ?', '>';
77  break;
78 
79  case (preg_match('/^asset_/i', $var) ? $var : !$var):
80  echo '<', '?php ';
81  echo '$keyword = \'',$var, '\';';
82  echo '$ASSET1 = $GLOBALS[\'SQ_SYSTEM\']->am->getAsset($ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'assetid\']);';
83  echo 'if (!is_null($ASSET1)) {';
84  echo '$replacement = '.$this->_escapeVar('$ASSET1->getKeywordReplacement($keyword)', $args).';';
85  echo 'if ($replacement == $keyword) {';
86  echo ' echo \'\';';
87  echo '} else {';
88  echo ' echo $replacement;';
89  echo '}';
90  echo '$GLOBALS[\'SQ_SYSTEM\']->am->forgetAsset($ASSET1);';
91  echo '} else {';
92  echo ' echo \'\';';
93  echo '}';
94  echo '?', '>';
95  break;
96 
97  default :
98  parent::printVar($var, $args);
99 
100  }// end switch
101 
102  }//end printVar()
103 
104 
113  protected function _printContentItemCode(Array $element)
114  {
115  switch (array_get_index($element, 'operation')) {
116  case 'asset' :
117  // Make lineage working with ?a=xxx
118  echo '<?php
119  if ( isset($_GET[\'a\']) && isset($GLOBALS[\'SQ_SYSTEM\']->frontend_asset) && $_GET[\'a\'] == $GLOBALS[\'SQ_SYSTEM\']->frontend_asset->id){
120  $last_ele_index = count($ASSET_LINEAGE) - 1;
121  $ASSET_LINEAGE[] = array (
122  \'url\' => $ASSET_LINEAGE[$last_ele_index][\'url\'].\'?a=\'.$GLOBALS[\'SQ_SYSTEM\']->frontend_asset->id,
123  \'assetid\' => $GLOBALS[\'SQ_SYSTEM\']->frontend_asset->id,
124  \'name\' => $GLOBALS[\'SQ_SYSTEM\']->frontend_asset->name,
125  \'short_name\' => $GLOBALS[\'SQ_SYSTEM\']->frontend_asset->short_name,
126  \'type_code\' => get_class_lower($GLOBALS[\'SQ_SYSTEM\']->frontend_asset),
127  \'protocol\' => $ASSET_LINEAGE[$last_ele_index][\'protocol\'],
128  \'link_type\' => $ASSET_LINEAGE[$last_ele_index][\'link_type\'],
129  );
130  }
131  ?>';
132 
133  // because the page lineage array contains the site index, all we need to do to have or not have
134  // the home link is start the loop at a different position
135  $start_index = ($this->attr('prefix_with_home_link')) ? 0 : 1;
136 
137  $start_at_level = $this->attr('start_at_level');
138  if (!is_null($start_at_level) && $start_at_level !== '') {
139  $start_index = $start_at_level >= 0 ? $start_at_level : 'max(0, (count($ASSET_LINEAGE) - 1 - '.abs($start_at_level).'))';
140  }//end if
141 
142  $total = 'count($ASSET_LINEAGE)';
143  // because the page lineage array contains the current page, all we need to do to have or not have
144  // the current link is end the loop at a different position
145  if (!$this->attr('suffix_with_current_link')) {
146  $total .= ' - 1';
147  }
148 
149  $levels_to_print = (int) $this->attr('levels_to_print');
150 
151  if (is_int($levels_to_print)) {
152  // if we have pages to print, we just adjust the total count factor
153  if ($levels_to_print > 0) {
154  $total = 'min('.$total.', '.($levels_to_print.' + '.$start_index).')';
155  } else if ($levels_to_print < 0) {
156  // need to minus 1 because the current link is included in the lineage count
157  $start_index = 'max(0, (count($ASSET_LINEAGE) - 1 - '.abs($levels_to_print).'))';
158  }
159  }
160 
161  if ($divider_contents = $this->attr('divider_contents')) {
162  ob_start();
163  foreach ($divider_contents as $item) {
164  $this->_printContentItemCode($item);
165  }
166  $divider = ob_get_contents();
167  ob_end_clean();
168  } else {
169  $divider = '';
170  }
171 
172  if ($divider != '' && $this->attr('prefix_with_divider')) {
173  echo $divider;
174  }
175 
176  echo '<', '?php
177 
178  ';
179 
180  if ($this->attr('reverse_lineage')) {
181  echo 'for ($'.$this->attr('id_name').'_i = '.$total.' - 1, $'.$this->attr('id_name').'_total = '.$total.';
182  $'.$this->attr('id_name').'_i >= '.$start_index.';
183  $'.$this->attr('id_name').'_i--) {
184  ';
185  } else {
186  echo 'for ($'.$this->attr('id_name').'_i = '.$start_index.', $'.$this->attr('id_name').'_total = '.$total.';
187  $'.$this->attr('id_name').'_i < $'.$this->attr('id_name').'_total;
188  $'.$this->attr('id_name').'_i++) {
189  ';
190  }
191 
192  if (!$this->attr('show_hidden_links')) {
193  echo 'if ($ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'link_type\'] != SQ_LINK_TYPE_1) continue;
194  ';
195  }
196 
197  $unwanted_types = $this->attr('unwanted_asset_types');
198  $all_type_codes = Array();
199  foreach ($unwanted_types as $type) {
200  if (!empty($type)) {
201  $all_type_codes = array_merge($all_type_codes, $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type, TRUE));
202  }
203  }
204  $unwanted_types = $all_type_codes;
205 
206  if (!empty($unwanted_types)) {
207  $unwanted_types_literal_array = 'Array("'.implode('", "', $unwanted_types).'")';
208  if ($this->attr('prefix_with_home_link')) {
209  // make the home-link-prefix setting override
210  // the unwanted-types setting
211  echo 'if (($'.$this->attr('id_name').'_i != 0) && in_array($ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'type_code\'], '.$unwanted_types_literal_array.')) continue;
212  ';
213  } else {
214  echo 'if (in_array($ASSET_LINEAGE[$'.$this->attr('id_name').'_i][\'type_code\'], '.$unwanted_types_literal_array.')) continue;
215  ';
216  }
217 
218  }
219 
220  if ($asset_contents = $this->attr('asset_contents')) {
221  echo '?','>';
222  foreach ($asset_contents as $item) {
223  $this->_printContentItemCode($item);
224  }
225  echo '<','?php ';
226  }
227 
228  // if there is a divider to deal with
229  if ($divider != '') {
230 
231  // if there is not divider at the end we need to check that we aren't at the end of the list
232  if (!$this->attr('suffix_with_divider')) {
233  if ($this->attr('reverse_lineage')) {
234  echo '
235  if ($'.$this->attr('id_name').'_i != '.$start_index.') {
236  ';
237  } else {
238  echo '
239  if ($'.$this->attr('id_name').'_i != $'.$this->attr('id_name').'_total - 1) {
240  ';
241  }
242  }
243 
244  echo '?','>', $divider, '<','?php ';
245 
246  // if there is not divider at the end we need to check that we aren't at the end of the list
247  if (!$this->attr('suffix_with_divider')) {
248  echo '
249  }//end if';
250  }
251 
252  }//end if divider
253 
254  echo '
255  }//end for
256  ?','>';
257 
258  return TRUE;
259 
260  default :
261  return parent::_printContentItemCode($element);
262  }//end switch
263 
264  }//end _printContentItemCode()
265 
266 
276  public function getProtectedAttrs()
277  {
278  $res = parent::getProtectedAttrs();
279  $res[] = 'asset_contents';
280  $res[] = 'divider_contents';
281  return $res;
282 
283  }//end getProtectedAttrs()
284 
285 
299  public function setAttrValue($name, $value)
300  {
301  if (($name == 'unwanted_asset_types') && is_scalar($value)) {
302  $value = preg_split('/[ ,]+/', (string)$value);
303  foreach ($value as $type_code) {
304  if (!$GLOBALS['SQ_SYSTEM']->am->installed($type_code)) {
305  trigger_localised_error('CORE0145', E_USER_WARNING, $type_code);
306  return FALSE;
307  }
308  }
309  }
310  return parent::setAttrValue($name, $value);
311 
312  }//end setAttrValue()
313 
314 
315 }//end class
316 ?>