Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
content_type_nest_content_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/content_type/content_type_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
55  function paintBackend(&$asset, $prefix)
56  {
57  if ($asset->writeAccess('links') && $asset->writeAccess('attributes')) {
58  $nested_asset = $this->_getNestedAsset($asset);
59 
60  if (!is_null($nested_asset)) {
61  $paint_with = $asset->attr('paint_with');
62  $arbitrary_paint_layout = $this->_getArbitraryPaintLayout($asset);
63  $paint_layout_id = (is_null($arbitrary_paint_layout)) ? 0 : $arbitrary_paint_layout->id;
64  $asset_link = $GLOBALS['SQ_SYSTEM']->am->getAssetURL($nested_asset->id);
65  if (empty($asset_link)) {
66  $asset_link = strip_url(current_url(FALSE, TRUE)).'/?a='.$nested_asset->id;
67  }
68  ?>
69  <table class="sq-backend-table">
70  <tr>
71  <td class="sq-backend-table-cell-alt"><b><?php echo translate('cms_ct_nest_content_currently_nesting', $nested_asset->attr('name')) ?><?php require_once SQ_INCLUDE_PATH.'/general.inc'; echo ' : '.get_asset_tag_line($nested_asset->id);?></b></td>
72  </tr>
73  <tr>
74  <td class="sq-backend-table-cell"><?php asset_finder($prefix.'_nested_assetid', $nested_asset->id, Array('asset' => 'D')); ?></td>
75  </tr>
76  <tr>
77  <td class="sq-backend-table-cell"><b><a href="<?php echo $asset_link; ?>" id="sq_preview_new_window" target="_blank"><?php echo translate('cms_ct_nest_content_click_to_preview') ?></a></b></td>
78  </tr>
79  <tr>
80  <td class="sq-backend-table-cell-alt"><b>Dynamic Options:</b></td>
81  </tr>
82  <tr>
83  <td class="sq-backend-table-cell">
84  <table>
85  <colgroup>
86  <col width="50%" />
87  <col width="50%" />
88  </colgroup>
89  <thead>
90  <tr>
91  <th>Parameter</th>
92  <th>GET Variable Name</th>
93  </tr>
94  </thead>
95  <tbody>
96  <tr>
97  <td>Asset ID to nest the contents of:</td>
98  <td><?php text_box($prefix.'_dynamic_nest_get', $asset->attr('dynamic_nest_get'), 30) ?></td>
99  </tr>
100  </tbody>
101  </table>
102  </td>
103  </tr>
104  <tr>
105  <td class="sq-backend-table-cell-alt"><b>Paint this asset:</b></td>
106  </tr>
107  <tr>
108  <td class="sq-backend-table-cell">
109  <?php
110  radio_button($prefix.'_paint_with', 'raw', ($paint_with == 'raw' ? 1 : 0));
111  label('Raw (no Paint Layout)', $prefix.'_paint_with_raw');
112  ?><br/>
113  <?php
114  radio_button($prefix.'_paint_with', 'default', ($paint_with == 'default' ? 1 : 0));
115  label('Using default Paint Layout (based on lookup rules)', $prefix.'_paint_with_default');
116  ?><br/>
117  <?php
118  radio_button($prefix.'_paint_with', 'arbitrary', ($paint_with == 'arbitrary' ? 1 : 0));
119  label('Using an arbitrary Paint Layout: ', $prefix.'_paint_with_arbitrary');
120  asset_finder($prefix.'_paint_with_layout', $paint_layout_id, Array('paint_layout_page' => 'D'));
121  ?>
122  </td>
123  </tr>
124  <tr>
125  <td class="sq-backend-table-cell-alt"><b>Send the following additional GET variables to the asset:</b></td>
126  </tr>
127  <tr>
128  <td class="sq-backend-table-cell">
129  <?php
130  // get delete icon, with new lines replaced
131  ob_start();
132  sq_print_icon(sq_web_path('data').'/asset_types/bodycopy/images/icons/delete.png', 16, 16, translate('delete'), translate('delete'), ' style="border:none"');
133  $delete_icon = ob_get_clean();
134  $delete_icon = str_replace("\n", ' ', $delete_icon);
135 
136  $additional_get_vars = $asset->attr('additional_get');
137  if (empty($additional_get_vars)) {
138  // max() won't work on an empty array
139  $last_key = -1;
140  } else {
141  $last_key = max(array_keys($additional_get_vars));
142  }
143  ?>
144  <script type="text/javascript">
145  if (typeof <?php echo $asset->type() ?> == 'undefined') {
146  <?php echo $asset->type() ?> = {
147  nextIndex: [],
148 
152  addGetRow: function(prefix) {
153  node = document.getElementById(prefix + '_additional_get_body');
154  index = this.nextIndex[prefix];
155 
156  // create a new row
157  tr = document.createElement('tr');
158  tr.id = prefix + '_additional_get_row_' + index;
159 
160  // build the cells
161  td1 = document.createElement('td');
162  td1.innerHTML = '<?php text_box("' + prefix + '_additional_get[' + index + '][name]", '', 20) ?>';
163  td2 = document.createElement('td');
164  td2.innerHTML = '<?php text_box("' + prefix + '_additional_get[' + index + '][value]", '', 30) ?>'
165  td3 = document.createElement('td');
166  td3.innerHTML = '<a href="" onclick="<?php echo $asset->type() ?>.removeGetRow(\'' + prefix +'\', \'' + index + '\'); return false;"><?php echo $delete_icon; ?></a>';
167 
168  // Now put them all together
169  tr.appendChild(td1);
170  tr.appendChild(td2);
171  tr.appendChild(td3);
172  node.appendChild(tr);
173 
174  // Go to next index
175  this.nextIndex[prefix]++;
176 
177  // Update display of "no variable" status
178  this.updateNoVarStatus(prefix);
179  },
180 
181  /*
182  * Removes a row.
183  */
184  removeGetRow: function(prefix, index) {
185  node = document.getElementById(prefix + '_additional_get_row_' + index);
186  node.parentNode.removeChild(node);
187  this.updateNoVarStatus(prefix);
188  },
189 
190  /*
191  * Updates display of the "no variable" body.
192  */
193  updateNoVarStatus: function(prefix) {
194  node = document.getElementById(prefix + '_additional_get_body');
195  var noVarBody = document.getElementById(prefix + '_additional_get_none');
196  noVarBody.style.display = (node.getElementsByTagName('tr').length > 0) ? 'none' : 'block';
197  }
198  };
199  }//end if
200 
201  // Set the first new index for newly created rows
202  <?php echo $asset->type(); ?>.nextIndex['<?php echo $prefix; ?>'] = <?php echo ($last_key + 1); ?>;
203  </script>
204  <table>
205  <colgroup>
206  <col width="40%" />
207  <col width="60%" />
208  <col />
209  </colgroup>
210  <thead>
211  <tr>
212  <th>Variable Name</th>
213  <th>Variable Value</th>
214  <th><span style="white-space: nowrap"><?php echo translate('delete_question') ?></span></th>
215  </tr>
216  </thead>
217  <tfoot>
218  <tr>
219  <td colspan="3"><a href="" onclick="<?php echo $asset->type() ?>.addGetRow('<?php echo $prefix ?>'); return false;" id="<?php echo $prefix ?>_additional_get_new_row"><?php echo translate('cms_ct_nest_content_additional_get_add'); ?></a></td>
220  </tr>
221  <tr>
222  <td colspan="3">You can use keywords of the form <strong>%nested_asset_*%</strong> to refer to any of the keywords of the asset<br/>being nested. You can also use global keywords (<strong>%globals_*%</strong>). These will be evaluated upon asset load.</td>
223  </tr>
224  </tfoot>
225  <tbody id="<?php echo $prefix ?>_additional_get_none" style="display: <?php echo empty($additional_get_vars) ? 'table-row-group' : 'none' ?>">
226  <tr>
227  <td colspan="3"><em><?php echo translate('cms_ct_nest_content_additional_get_no_variables'); ?></em></td>
228  </tr>
229  </tbody>
230  <tbody id="<?php echo $prefix ?>_additional_get_body">
231  <?php
232  foreach ($additional_get_vars as $key => $var_info) {
233  ?>
234  <tr id="<?php echo $prefix; ?>_additional_get_row_<?php echo $key; ?>">
235  <td><?php text_box($prefix.'_additional_get['.$key.'][name]', $var_info['name'], 20) ?></td>
236  <td><?php text_box($prefix.'_additional_get['.$key.'][value]', $var_info['value'], 30) ?></td>
237  <td><a href="" onclick="<?php echo $asset->type() ?>.removeGetRow('<?php echo $prefix; ?>','<?php echo $key; ?>'); return false;"><?php echo $delete_icon; ?></a></td>
238  </tr>
239  <?php
240  }
241  ?>
242  </tbody>
243  </table>
244  </td>
245  </tr>
246  </table>
247  <?php
248  } else {
249  ?>
250  <table class="sq-backend-table">
251  <tr>
252  <td class="sq-backend-table-cell-alt"><b><?php echo translate('cms_ct_nest_content_no_page_selected'); ?></b></td>
253  </tr>
254  <tr>
255  <td class="sq-backend-table-cell"><?php asset_finder($prefix.'_nested_assetid', '', Array('asset' => 'D')); ?></td>
256  </tr>
257  </table>
258  <?php
259  }
260  }//end if
261 
262  return TRUE;
263 
264  }//end paintBackend()
265 
266 
278  function paint(&$asset, $editing=FALSE, $generating=FALSE)
279  {
280  // get the asset - we can't pass the type in because it could be anything
281  // we also mute errors because we check later on
282  $nested_asset = $this->_getNestedAsset($asset);
283  if (is_null($nested_asset)) return FALSE;
284 
285  if ($generating) {
286  $this->paintGenerated($asset, $nested_asset);
287  return TRUE;
288  }
289 
290  if ($editing) {
291  // We are in the edit interface, so just print a link
292  $asset_link = $GLOBALS['SQ_SYSTEM']->am->getAssetURL($nested_asset->id);
293  if (empty($asset_link)) {
294  $asset_link = strip_url(current_url(FALSE, TRUE)).'/?a='.$nested_asset->id;
295  }
296  $asset_contents = '<strong>'.translate('cms_ct_nest_content_nested_content').get_asset_tag_line($nested_asset->id).'</strong> <a href="'.$asset_link.'" id="sq_preview_new_window" target="_blank">'.translate('cms_ct_nest_content_click_to_preview').'</a>.';
297  } else {
298  $asset_contents = '';
299  // This is the real deal, so we want to actually print the asset
300 
301  // Check for recursion
302  // We use the cache key where available to distinguish differently-behaving
303  // copies of the same asset (Bug Fix #1601)
304  $asset_cache_key = $nested_asset->id;
305  if (method_exists($nested_asset, '_getCacheKey')) {
306  $asset_cache_key .= $nested_asset->_getCacheKey();
307  }
308 
309  // Add GET vars to the cache key, as these will
310  $additional_get_vars = $this->_processAdditionalGetVars($asset, $nested_asset);
311  $asset_cache_key .= '-'.md5(serialize($additional_get_vars));
312 
313  if (isset($GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key])) {
314  unset($GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key]);
315  echo '<span class="sq-backend-warning"><b>[ ** '.translate('cms_ct_nest_content_recursion_warning').' ** ]<br/>'.translate('cms_ct_nest_content_recursion_body').'</b></span>';
316  return TRUE;
317  }
318 
319  // Now do the additional GET vars stuff
320  $old_get = $_GET;
321  $_GET = array_merge($_GET, $additional_get_vars);
322 
323  // Record that we have printed this asset
324  // OKAY! so we havn't actually printed it yet, but we need to record that
325  // we have or we might just fall endlessly into printBody functions and
326  // never get back here again
327  $GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key] = 1;
328 
329  // Ask the asset to do its thing
330  ob_start();
331  switch ($asset->attr('paint_with')) {
332  case 'raw':
333  // Raw - just paint it
334  $nested_asset->printBody();
335  break;
336 
337  case 'default':
338  // Default Rules - use the "normal" method of determining
339  // which paint layout gets used
340  $nested_asset->printBodyWithPaintLayout();
341  break;
342 
343  case 'arbitrary':
344  // Get the arbitary paint layout; if there is none set,
345  // paint it raw, otherwise paint it with the arbitrary layout
346  $arbitrary_paint_layout = $this->_getArbitraryPaintLayout($asset);
347  if (empty($arbitrary_paint_layout)) {
348  $nested_asset->printBody();
349  } else {
350  $nested_asset->printBodyWithPaintLayout($arbitrary_paint_layout->id);
351  }//end else
352  break;
353  }//end switch
354 
355  $asset_contents = ob_get_contents();
356  ob_end_clean();
357 
358  $keywords = extract_keywords($asset_contents);
359  $replacements = Array();
360  foreach ($keywords as $idx => $keyword) {
361  if (strpos($keyword, 'nested_get_') === 0) {
362  $sub_keyword = substr($keyword, 11);
363  $replacements[$keyword] = array_get_index($_GET, $sub_keyword, '');
364  }
365  }
366 
367  replace_keywords($asset_contents, $replacements);
368 
369  $_GET = $old_get;
370 
371  unset($GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key]);
372  }//end else
373 
374  echo $asset_contents;
375 
376  return TRUE;
377 
378  }//end paint()
379 
380 
390  function paintGenerated(&$asset, &$nested_asset)
391  {
392  $additional_get_vars = $asset->attr('additional_get');
393  $get_var_cache_key = md5(serialize($additional_get_vars));
394  echo '<'.'?php'."\n";
395  ?>
396 
397  if (isset($_GET['<?php echo $asset->attr('dynamic_nest_get'); ?>'])) {
398  $nested_assetid = $_GET['<?php echo $asset->attr('dynamic_nest_get'); ?>'];
399  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($nested_assetid, '', TRUE);
400  if ($nested_asset == null) {
401  $nested_assetid = '<?php echo $nested_asset->id; ?>';
402  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($nested_assetid);
403  }
404  } else {
405  $nested_assetid = '<?php echo $nested_asset->id; ?>';
406  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($nested_assetid);
407  }
408  $nesting_assetid = '<?php echo $asset->id; ?>';
409  $temp_parent_array = $GLOBALS['SQ_SYSTEM']->am->getDependantParents($nesting_assetid, '' , TRUE, FALSE);
410  $parents_nesting_asset_id = $temp_parent_array[0];
411  $parents_nesting_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($parents_nesting_asset_id);
412 
413  $asset_cache_key = $nested_assetid.'-<?php echo $get_var_cache_key; ?>';
414  if (method_exists($nested_asset, '_getCacheKey')) {
415  $asset_cache_key .= $nested_asset->_getCacheKey();
416  }
417 
418  if (!isset($GLOBALS['SQ_NEST_CONTENT_PAINTED'])) $GLOBALS['SQ_NEST_CONTENT_PAINTED'] = Array();
419  if (!isset($GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key])) {
420 
421  $additional_get_vars = <?php
422  // keyword delimiters need to be replaced temporarily
423  echo str_replace('%', '&#37;', var_export($additional_get_vars, TRUE)); ?>;
424  $processed_get_vars = Array();
425  foreach ($additional_get_vars as $get_var) {
426  $get_name = $get_var['name'];
427  $get_value = str_replace('&#37;', '%', $get_var['value']);
428  $found = preg_match_all('/%(asset\_.*)%/U', $get_value, $set_matches, PREG_PATTERN_ORDER);
429  $asset_matches = $set_matches[1];
430 
431  foreach ($asset_matches as $asset_keyword) {
432  $replacement = $parents_nesting_asset->getKeywordReplacement($asset_keyword);
433  if (!is_null($replacement)) {
434  $get_value = str_replace('%'.$asset_keyword.'%', $replacement, $get_value);
435  }
436  }
437 
438  $found = preg_match_all('/%(nested\_asset\_.*)%/U', $get_value, $set_matches, PREG_PATTERN_ORDER);
439  $nested_asset_matches = $set_matches[1];
440 
441  foreach ($nested_asset_matches as $nested_asset_keyword) {
442  if (0 === strpos($nested_asset_keyword, 'nested_')) {
443  $nested_asset_keyword = str_replace('nested_','',$nested_asset_keyword);
444  }
445  $replacement = $nested_asset->getKeywordReplacement($nested_asset_keyword);
446  if (!is_null($replacement)) {
447  $get_value = str_replace('nested_','',$get_value);
448  $get_value = str_replace('%'.$nested_asset_keyword.'%', $replacement, $get_value);
449  }
450  }
451 
452  replace_global_keywords($get_value);
453 
454  preg_match('/([^\[]*)(.*)/', $get_name, $base_name);
455  $array_bits = $base_name[2];
456  if (empty($array_bits)) {
457  $processed_get_vars[$base_name[1]] = $get_value;
458  } else {
459  $array_els = Array();
460 
461  if (!isset($processed_get_vars[$base_name[1]])) {
462  $processed_get_vars[$base_name[1]] = Array();
463  }
464 
465  $done = FALSE;
466  while (!empty($array_bits)) {
467  $found = preg_match('/\[([^\]]*)\](.*)/', $array_bits, $base_name);
468  if (!$found) break;
469  $array_bits = $base_name[2];
470  $array_els[] = addslashes($base_name[1]);
471  }
472 
473  $eval_str = '$processed_get_vars[\''.addslashes($base_name[1]).'\'][\''.implode('\'][\'', $array_els).'\'] = '.addslashes($get_value);
474  eval($eval_str);
475  }
476  }
477  $old_get[$asset_cache_key] = $_GET;
478  $_GET = array_merge($_GET, $processed_get_vars);
479 
480  // $_REQUEST by default is supposed to contain the contnets of $_GET
481  $old_request[$asset_cache_key] = $_REQUEST;
482  $_REQUEST = array_merge($_REQUEST, $processed_get_vars);
483 
484  $GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key] = 1;
485  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($nested_assetid, '', TRUE);
486  $asset_contents = '';
487  if ($nested_asset->id && $nested_asset->readAccess()) {
488  ob_start();
489  <?php
490  switch ($asset->attr('paint_with')) {
491  case 'raw':
492  ?>
493  $nested_asset->printBody();
494  <?php
495  break;
496 
497  case 'default':
498  ?>
499  $nested_asset->printBodyWithPaintLayout();
500  <?php
501  break;
502 
503  case 'arbitrary':
504  $arbitrary_paint_layout = $this->_getArbitraryPaintLayout($asset);
505  if (empty($arbitrary_paint_layout)) {
506  ?>
507  $nested_asset->printBody();
508  <?php
509  } else {
510  ?>
511  $arbitrary_paint_layout = $GLOBALS['SQ_SYSTEM']->am->getAsset(<?php echo $arbitrary_paint_layout->id ?>);
512  $nested_asset->printBodyWithPaintLayout($arbitrary_paint_layout->id);
513  <?php
514  }
515  break;
516  }//end switch
517  ?>
518  $asset_contents = ob_get_contents();
519  ob_end_clean();
520 
521  $keywords = extract_keywords($asset_contents);
522  $replacements = Array();
523  foreach ($keywords as $idx => $keyword) {
524  if (strpos($keyword, 'nested_get_') === 0) {
525  $sub_keyword = substr($keyword, 11);
526  $replacements[$keyword] = array_get_index($_GET, $sub_keyword, '');
527  }
528  }
529 
530  replace_keywords($asset_contents, $replacements);
531  }
532 
533  echo $asset_contents;
534  unset($GLOBALS['SQ_NEST_CONTENT_PAINTED'][$asset_cache_key]);
535 
536  $_GET = $old_get[$asset_cache_key];
537  $_REQUEST = $old_request[$asset_cache_key];
538  } else {
539  echo '<font color="red"><b>[ ** '.translate('cms_ct_nest_content_recursion_warning').' ** ]<br />'.translate('cms_ct_nest_content_recursion_body').'</b></font>';
540  }
541 
542  <?php echo "\n".'?'.'>';
543 
544  }//end paintGenerated()
545 
546 
556  function _processAdditionalGetVars(&$asset, &$nested_asset)
557  {
558  $processed_get_vars = Array();
559  $additional_get_vars = $asset->attr('additional_get');
560  if (!isset($additional_vars) || empty($additional_vars)) {
561  return $processed_get_vars;
562  }
563  $temp_parent_array = $GLOBALS['SQ_SYSTEM']->am->getDependantParents($asset->id, '' , TRUE, FALSE);
564  $parents_nesting_asset_id = $temp_parent_array[0];
565  $parents_nesting_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($parents_nesting_asset_id);
566  foreach ($additional_get_vars as $get_var) {
567  $get_name = $get_var['name'];
568  $get_value = $get_var['value'];
569  $found = preg_match_all('/%(asset\_.*)%/U', $get_value, $set_matches, PREG_PATTERN_ORDER);
570  $asset_matches = $set_matches[1];
571  foreach ($asset_matches as $asset_keyword) {
572  $replacement = $parents_nesting_asset->getKeywordReplacement($asset_keyword);
573  if (!is_null($replacement)) {
574  $get_value = str_replace('%'.$asset_keyword.'%', $replacement, $get_value);
575  }
576  }
577 
578  $found = preg_match_all('/%(nested\_(asset\_.*))%/U', $get_value, $set_matches, PREG_PATTERN_ORDER);
579  $nested_asset_orig_matches = $set_matches[1];
580  $nested_asset_matches = $set_matches[2];
581 
582  foreach ($nested_asset_matches as $na_id => $nested_asset_keyword) {
583  if (0 === strpos($nested_asset_keyword, 'nested_')) {
584  $nested_asset_keyword = str_replace('nested_','',$nested_asset_keyword);
585  }
586  $replacement = $nested_asset->getKeywordReplacement($nested_asset_keyword);
587  if (!is_null($replacement)) {
588  $get_value = str_replace('nested_','',$get_value);
589  $get_value = str_replace('%'.$nested_asset_orig_matches[$na_id].'%', $replacement, $get_value);
590  }
591  }
592 
593  replace_global_keywords($get_value);
594 
595  preg_match('/([^\[]*)(.*)/', $get_name, $base_name);
596  $array_bits = $base_name[2];
597  if (empty($array_bits)) {
598  $processed_get_vars[$base_name[1]] = $get_value;
599  } else {
600  $array_els = Array();
601 
602  if (!isset($processed_get_vars[$base_name[1]])) {
603  $processed_get_vars[$base_name[1]] = Array();
604  }
605 
606  $done = FALSE;
607  while (!empty($array_bits)) {
608  $found = preg_match('/\[([^\]]*)\](.*)/', $array_bits, $base_name);
609  if (!$found) break;
610  $array_bits = $base_name[2];
611  $array_els[] = addslashes($base_name[1]);
612  }
613 
614  $eval_str = '$processed_get_vars[\''.addslashes($base_name[1]).'\'][\''.implode('\'][\'', $array_els).'\'] = '.addslashes($get_value);
615  eval($eval_str);
616  }//end else
617  }//end foreach
618 
619  return $processed_get_vars;
620 
621  }//end _processAdditionalGetVars()
622 
623 
634  function processBackend($link, &$asset, $prefix)
635  {
636  $ok = FALSE;
637 
638  $nested_asset = $this->_getNestedAsset($asset);
639  $current_assetid = (!is_null($nested_asset)) ? $nested_asset->id : 0;
640 
641  $arbitrary_paint_layout = $this->_getArbitraryPaintLayout($asset);
642  $current_apl_assetid = (!is_null($arbitrary_paint_layout)) ? $arbitrary_paint_layout->id : 0;
643 
644  $additional_get = array_get_index($_POST, $prefix.'_additional_get', Array());
645  foreach ($additional_get as $var_index => $var_value) {
646  $var_value['name'] = trim($var_value['name']);
647  if (empty($var_value['name'])) {
648  unset($additional_get[$var_index]);
649  }
650  }
651 
652  $dynamic_nest_get = (isset($_POST[$prefix.'_dynamic_nest_get'])) ? $_POST[$prefix.'_dynamic_nest_get'] : '';
653  $assetid = (isset($_POST[$prefix.'_nested_assetid']['assetid'])) ? $_POST[$prefix.'_nested_assetid']['assetid'] : 0;
654  $paint_with = array_get_index($_POST, $prefix.'_paint_with', 'raw');
655  $paint_with_assetid = (isset($_POST[$prefix.'_paint_with_layout']['assetid'])) ? $_POST[$prefix.'_paint_with_layout']['assetid'] : 0;
656 
657  if ($paint_with_assetid && ($paint_with == 'arbitrary')) {
658  if ($current_apl_assetid) {
659  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', TRUE, 'paint_with_layout');
660  if (!$asset->deleteLink($link['linkid'])) {
661  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
662  return FALSE;
663  }
664  }
665 
666  // create a NOTICE link for delete notification
667  $arbitrary_paint_layout = $GLOBALS['SQ_SYSTEM']->am->getAsset($paint_with_assetid);
668  if (!$asset->createLink($arbitrary_paint_layout, SQ_LINK_NOTICE, 'paint_with_layout')) {
669  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
670  return FALSE;
671  }
672 
673  $asset->linksUpdated();
674 
675  }
676 
677  if (($dynamic_nest_get != $asset->attr('dynamic_nest_get')) || ($paint_with != $asset->attr('paint_with')) || ($additional_get != $asset->attr('additional_get')) || ($paint_with_assetid != $current_apl_assetid)) {
678  $asset->setAttrValue('paint_with', $paint_with);
679  $asset->setAttrValue('additional_get', $additional_get);
680  $asset->setAttrValue('dynamic_nest_get', trim($dynamic_nest_get));
681 
682  if (!$asset->saveAttributes()) {
683  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
684  return FALSE;
685  }
686 
687  $ok = TRUE;
688  }
689 
690  if ($assetid) {
691 
692  if ($assetid != $current_assetid) {
693 
694  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
695  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
696 
697  if ($current_assetid) {
698  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', TRUE, 'nested_asset');
699  if (!$asset->deleteLink($link['linkid'])) {
700  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
701  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
702  return FALSE;
703  }
704  }
705 
706  // create a NOTICE link for delete notification
707  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
708  if (!$asset->createLink($nested_asset, SQ_LINK_NOTICE, 'nested_asset')) {
709  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
710  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
711  return FALSE;
712  }
713 
714  // get the html contents of the nested asset so
715  // we change the type of the cell later - other content
716  // types can use the html
717 
718  // if we dont have the frontend asset set just buffer nothing
719  if (SQ_IN_LIMBO && !isset($GLOBALS['SQ_SYSTEM']->frontend_asset)) {
720  $html = '';
721  } else {
722  ob_start();
723  $this->paint($asset, $prefix);
724  $html = ob_get_contents();
725  ob_end_clean();
726  }
727 
728  $asset->setAttrValue('html', $html);
729 
730  // Bug Fix 1541
731  if (!$current_assetid && $assetid) {
732  // Normally you are not supposed to call linksUpdated() directly, however,
733  // createAssetLink() does not call linksUpdated() to the major unless its dependant link.
734  // let's manually update the paint layout bodycopy if there is any
735  $asset->linksUpdated();
736  }
737 
738  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
739  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
740  $ok = TRUE;
741 
742  // Fix to Bug #5055 Nested content divs don't save properly across contexts
743  // refresh the content_file.php for all the context here. This content_type(_nest_asset)
744  // is different to any other content types. This is more so based on what asset is linked
745  // with the link_value of 'nested_asset'. And since the Links are not contextable
746  // we have to treat all the context w.r.t the changed asset
747  $bodycopy_div_id = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($asset->id, 'bodycopy_container', FALSE));
748  if (isset($bodycopy_div_id[0])) {
749  $bodycopy_div = $GLOBALS['SQ_SYSTEM']->am->getAsset($bodycopy_div_id[0]);
750  $bodycopy_div_edit_fns = $bodycopy_div->getEditFns();
751  $all_context = $GLOBALS['SQ_SYSTEM']->getAllContexts();
752  foreach ($all_context as $context_id => $info) {
753  $GLOBALS['SQ_SYSTEM']->changeContext($context_id);
754  $bodycopy_div_edit_fns->generateContentFile($bodycopy_div);
755  $GLOBALS['SQ_SYSTEM']->restoreContext();
756  }
757  }
758 
759  }//end if
760 
761  } else if ($current_assetid) {
762  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', TRUE, 'nested_asset');
763  $ok = $asset->deleteLink($link['linkid']);
764  }
765 
766  return $ok;
767 
768  }//end processBackend()
769 
770 
779  function &_getNestedAsset(&$asset)
780  {
781  $nested_asset = NULL;
782 
783  if (isset($_GET[$asset->attr('dynamic_nest_get')])){
784  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($_GET[$asset->attr('dynamic_nest_get')], '', TRUE);
785  } else {
786  $nested_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', TRUE, 'nested_asset');
787  if (!empty($nested_link)) {
788  $nested_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($nested_link['minorid'], $nested_link['minor_type_code'], TRUE);
789  }
790  }
791 
792  return $nested_asset;
793 
794  }//end _getNestedAsset()
795 
796 
805  function &_getArbitraryPaintLayout(&$asset)
806  {
807  $paint_layout = NULL;
808 
809  $paint_layout_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', TRUE, 'paint_with_layout');
810  if (!empty($paint_layout_link)) {
811  $paint_layout = $GLOBALS['SQ_SYSTEM']->am->getAsset($paint_layout_link['minorid'], $paint_layout_link['minor_type_code'], TRUE);
812  }
813 
814  return $paint_layout;
815 
816  }//end _getArbitraryPaintLayout()
817 
818 
819 }//end class
820 
821 ?>