Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
bodycopy_div_edit_fns.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/bodycopy/bodycopy_container/bodycopy_container_edit_fns.inc';
18 
31 {
32 
33 
38  function __construct()
39  {
40  parent::__construct();
41 
42  }//end __construct()
43 
44 
54  public function paintBackendJsData(Bodycopy_Div $asset, $prefix)
55  {
56  $div_attributes = $asset->attr('attributes');
57  $div_attributes['identifier'] = $asset->name;
58 
59  ?>
60  case <?php echo $asset->id?> :
61 
62  retVal["attributes"] = '<?php echo var_serialise($div_attributes, TRUE)?>';
63 
64  break;
65  <?php
66 
67  }//end paintBackendJsData()
68 
69 
80  public function paintGenericBackend(Asset $bodycopy, Backend_Outputter $o, $prefix)
81  {
82  // If the parent bodycopy class is itself, fudge the containers array
83  // so that the proper stuff gets drawn when putting out the javascript
84  // to edit.
85  if ($bodycopy instanceof Bodycopy_Div) {
86  $containers = Array(Array('minorid'=>$bodycopy->id, 'minor_type_code'=>get_class_lower($bodycopy)));
87  } else {
88  $containers = $GLOBALS['SQ_SYSTEM']->am->getLinks($bodycopy->id, SQ_LINK_TYPE_2, 'bodycopy_container', FALSE);
89  }
90 
91  ?>
92  <script language="JavaScript" src="<?php echo sq_web_path('data').'/asset_types/bodycopy/js/bodycopy_edit_divs.js'?>"></script>
93 
94  <script language="JavaScript" type="text/javascript">
95  function serialise_div(bodycopy_name, bodycopy_data, divid) {
96  var form = document.main_form;
97  if (!bodycopy_saved[bodycopy_name] && bodycopy_name != null) bodycopy_saved[bodycopy_name] = new Object();
98 
99  if (divid != null) {
100  if (!bodycopy_saved[bodycopy_name][divid]) {
101  bodycopy_saved[bodycopy_name][divid] = new Object();
102  }
103 
104  bodycopy_saved[bodycopy_name][divid]['attributes'] = bodycopy_data['attributes'];
105  }// end if divid
106 
107  form.elements['bodycopy_saved[' + bodycopy_name + '][' + divid + ']'].value = var_serialise(bodycopy_saved[bodycopy_name][divid]);
108  }// end serialise_div()
109 
110  // general fn that the generic include fns can use to get data to use
111  function get_bodycopy_current_div_data(bodycopy_name, divid) {
112  if (divid == null) divid = -1;
113  return bodycopy_current_data[bodycopy_name].get_div_data(divid);
114  }
115 
116  // general function that the generic include fns can use to get data to use ()
117  // used in getting numebr of assets the DIV is linked to
118  function get_bodycopy_current_div_count(bodycopy_name, asset_linked) {
119  return bodycopy_current_data[bodycopy_name].get_div_data(linked);
120  }
121 
122  function get_bodycopy_div_available_classes() {
123  <?php
124  $classes = Array();
125  if (isset($GLOBALS['sq_preview_url']) && !empty($GLOBALS['sq_preview_url'])) {
126  $url = $GLOBALS['sq_preview_url'];
127  $url = preg_replace('|^http[s]?://|', '', $url);
128 
129  $designid = $GLOBALS['SQ_SYSTEM']->am->getValueFromURL($url, 'design::%frontend%', TRUE);
130 
131  if ($designid) {
132  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($designid);
133  $classes_list = $design->attr('div_classes');
134  if (!empty($classes_list)) {
135  //$vars = explode("\n", $classes_list);
136  foreach ($classes_list as $key => $value) {
137  $classes[$key] = $value;
138  }
139  }
140  }
141  }
142  ?>
143  return var_unserialise('<?php echo empty($classes) ? NULL : var_serialise($classes, TRUE); ?>');
144  }
145 
146  function get_bodycopy_<?php echo $prefix?>_current_div_data(divid) {
147 
148  retVal = new Object();
149 
150  switch (divid) {
151  <?php
152  // if we have tables get them to print the js data they need
153  $i = 0;
154  if (count($containers)) {
155  foreach ($containers as $container_data) {
156  if ($container_data['minor_type_code'] != 'bodycopy_div') {
157  continue;
158  }
159 
160  $div = $GLOBALS['SQ_SYSTEM']->am->getAsset($container_data['minorid'], $container_data['minor_type_code']);
161  $div_edit = $div->getEditFns();
162  $div_edit->paintBackendJsData($div, $prefix, $i);
163  $i++;
164  }
165  }
166  ?>
167  default :
168  retVal["num_containers"] = <?php echo count($containers); ?>;
169 
170  }// end switch divid
171 
172 
173  // check if this piece of data has been changed before
174  // if it has, return the changed version, not the original
175  if (divid != -1) {
176  if (bodycopy_data_exists(new Array('<?php echo $prefix?>', divid, 'attributes'))) {
177  retVal ["attributes"] = var_serialise(bodycopy_saved["<?php echo $prefix?>"][divid]["attributes"]);
178  return retVal;
179  }
180  }
181 
182  return retVal;
183  }// end get_bodycopy_<?php echo $prefix?>_current_table_data()
184 
185  // set reference so generic fn can be called above
186  bodycopy_current_data["<?php echo $prefix?>"].get_div_data = get_bodycopy_<?php echo $prefix?>_current_div_data;
187  </script>
188 
189  <?php
190 
191  }//end paintGenericBackend()
192 
193 
204  public function paint(Bodycopy_Div $asset, $editing=FALSE, $generating=FALSE)
205  {
206  $div_attributes = $asset->attr('attributes');
207  if (!isset($div_attributes['layout_type'])) {
208  $div_attributes['layout_type'] = 'div';
209  }
210 
211  $attribute_list = '';
212 
213  for (reset($div_attributes); $name = key($div_attributes); next($div_attributes)) {
214  $val = $div_attributes[$name];
215  if ($val == '') continue;
216 
217  $skip_attribute = FALSE;
218  switch ($name) {
219  case 'layout_type':
220  case 'content_type':
221  case 'identifier':
222  case 'disable_keywords':
223  case 'css_class_list':
224  $skip_attribute = TRUE;
225  break;
226  case 'css_class':
227  $name = 'class';
228  break;
229  }
230 
231  if ($skip_attribute) continue;
232  $attribute_list .= ' '.$name.'="'.str_replace('"', '&quot;', $val).'"';
233  }
234 
235  // Now add the ID of the DIV
236  $val = clean_div_attribute($asset->attr('name'));
237  if (!empty($val)) {
238  $attribute_list .= ' '.'id="'.$val.'"';
239  }
240 
241  // print DIV or SPAN tag if we are not printing raw HTML
242  if ($div_attributes['layout_type'] != 'none') {
243  echo "\n<".strtolower($div_attributes['layout_type']).$attribute_list.">\n";
244  }
245 
246  $content_type = $asset->getContentType();
247 
248  if (!is_null($content_type)) {
249  $content_edit = $content_type->getEditFns();
250  $content_edit->paint($content_type, $editing, $generating);
251  }
252 
253  // print end DIV or SPAN tag if we are not printing raw HTML
254  if ($div_attributes['layout_type'] != 'none') {
255  echo "\n</".strtolower($div_attributes['layout_type']).">\n";
256  }
257 
258  return TRUE;
259 
260  }//end paint()
261 
262 
273  public function paintContainer(Bodycopy_Div $asset, Backend_Outputter $o, $prefix)
274  {
275  if (!parent::paintContainer($asset, $o, $prefix)) {
276  return FALSE;
277  }
278 
279  $div_attributes = $asset->attr('attributes');
280 
281  $attribute_list = '';
282  $popup_attribute_list = '';
283  $dir_attribute = '';
284 
285  if (!empty($div_attributes)) {
286  for (reset($div_attributes); $name = key($div_attributes); next($div_attributes)) {
287  $val = $div_attributes[$name];
288  if ($val == '') continue;
289  if ($name == 'css_class_list') continue;
290  if ($name == 'dir') $dir_attribute = $div_attributes[$name];
291  $popup_attribute_list .= ' '.$name.'="'.str_replace('"', '&quot;', $val).'"';
292  $attribute_list .= ' '.$name.'="'.str_replace('"', '&quot;', $val).'"';
293  }
294  }
295 
296  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_TYPE_2, 'content_type', FALSE, 'div_contents', 'major', TRUE);
297  if (!empty($link)) {
298  $content_type = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
299  $content_prefix = $prefix.'_'.get_class_lower($content_type).'_'.$link['linkid'];
300  } else {
301  $content_type = NULL;
302  $content_prefix = '';
303  }
304 
305  // require library functions needed for drawing the bodycopy divs
306  $type_info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo('bodycopy');
307 
308  ?>
309  <table<?php echo $attribute_list?> style="width:100%;">
310  <tr>
311  <td align="left" background="" id="<?php echo $prefix.'_div_'.$asset->id;?>" width="4%" style="border: 1px dashed #C0C0C0;">
312  <span style="float: left;">
313  <?php
314 
315  $public_userid = $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('public_user');
316 
317  $public_read = FALSE;
318  if ($asset->status == SQ_STATUS_LIVE && $asset->readAccess(Array($public_userid))) {
319  $public_read = TRUE;
320  }
321  $status_name = get_status_description($asset->status);
322  $status_img = get_asset_status_icon($asset->status);
323  $desc = translate('content_type_tooltip_status').': '.$status_img.'<b>'.get_status_description($asset->status).'</b><br />';
324  $desc .= translate('content_type_tooltip_public').': <b>'.($public_read ? translate('yes') : translate('no')).'</b><br />';
325  $desc .= (($popup_attribute_list) ? translate('current_properties').':<br> '.$popup_attribute_list : '');
326  Bodycopy_Edit_Fns::printBodycopyIcon('bodycopy_edit_div_properties(\''.$prefix.'\', '.$asset->id.', '.(($asset->status & SQ_SC_STATUS_SAFE_EDITING) ? 'false' : 'true').');', 'Edit '.$asset->attr('name').'\'s Properties', $desc, 'table_properties', '[Edit Properties]');
327 
328  if (!is_null($content_type)) {
329  $content_edit = $content_type->getEditFns();
330  $content_edit->paintBackendIcons($content_type, $content_prefix);
331  }
332 
333  $asset_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_ALL, '', TRUE, 'minor');
334  $count_linked_to = count($asset_links);
335  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($asset->id));
336 
337  $lineages = $GLOBALS['SQ_SYSTEM']->am->getLinkLineages($asset->id, 5);
338  ?>
339  </span>
340 
341  <div id="asset-tag-line-<?php echo $asset->id ?>-lineages-linked" style="display:none">
342  <table><tr><td>
343  <?php
344  echo 'This DIV is linked to <strong><i>'.$count_linked_to.'</i></strong> assets'; ?></td></tr><?php
345  foreach ($lineages as $lineage_key => $lineage) {
346  if ($lineage['link_type'] & SQ_SC_LINK_BACKEND_NAV) {
347  $lineage_assetids = array_keys($lineage['lineage']);
348  $lineage_assetids[] = $asset->id;
349  $lineage_names = $lineage['lineage'];
350 
351  if (count($lineage['lineage']) > 3) {
352  $lineage_names = $lineage['lineage'];
353  array_splice($lineage_names, 2, -1, Array('...'));
354  }
355  foreach ($lineage_names as $id => $name){
356  $lineage_names[$id] = htmlspecialchars($name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
357  }
358  $lineage_names[$asset->id] = htmlspecialchars($asset_info[$asset->id]['name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
359  require_once SQ_INCLUDE_PATH.'/general.inc';
360  ?><tr><td class="sq-backend-table-cell" ><a href="#" onclick="if (self.name == 'sq_wysiwyg_popup_main') {am = self;} else if (self.name == 'hipo_job') {am = opener;} else if ((typeof sq_wysiwyg_dialog != 'undefined') && (sq_wysiwyg_dialog != null) && !sq_wysiwyg_dialog.closed) { am = sq_wysiwyg_dialog; am.focus(); } else { am = parent.top.frames['sq_sidenav']; } am.asset_locator_start('<?php echo get_asset_lineage_sort_order($lineage_assetids) ?>'); tooltip.hide(); return false;"><?php echo implode(' &gt; ', $lineage_names) ?></a></td>
361  </tr>
362  <?php ;
363  } else {
364  unset($lineages[$lineage_key]);
365  }
366  }// end foreach
367  ?>
368  </table>
369  </div>
370  <span style="float: right;">
371  <?php
372  if (count($lineages) > 1) {
373  ?><div id="asset-tag-line-<?php echo $asset->id ?>-cancel-icon" style="display:none"><?php
374  sq_print_icon(sq_web_path('data').'/asset_types/bodycopy/images/icons/delete.png', 16, 16, translate('cancel'), translate('cancel'), ' style="border:none"');
375  ?></div><?php
376  $lineages_onclick = 'tooltip.show(this, document.getElementById(\'asset-tag-line-'.$asset->id.'-lineages-linked\').innerHTML, \''.translate('linked_to_assets').'\', document.getElementById(\'asset-tag-line-'.$asset->id.'-cancel-icon\').innerHTML)';
377  $lineages_name = translate('linked_to_assets');
378  require_once SQ_INCLUDE_PATH.'/general.inc';
379  echo sq_print_icon(sq_web_path('lib').'/web/images/icons/asset_locator.png', 16, 16, $lineages_name, $lineages_name, ' class="clickable" align="absmiddle" onclick="'.$lineages_onclick.'"');
380  }
381  if (!is_null($content_type)) {
382  $content_edit = $content_type->getEditFns();
383  $content_edit->paintBackendStatusIcons($content_type, $content_prefix);
384  }
385  ?>
386  </span>
387  </td>
388  </tr>
389  <tr>
390  <td style="border-left: 1px dashed #C0C0C0; border-right: 1px dashed #C0C0C0; border-bottom: 1px dashed #C0C0C0;" id="<?php echo $content_prefix; ?>_cell">
391  <?php
392  if (!is_null($content_type)) {
393  $content_edit = $content_type->getEditFns();
394  if (method_exists($content_edit,'setDirAttr')) {
395  $content_edit->setDirAttr($dir_attribute);
396  }
397  $content_edit->paintBackend($content_type, $content_prefix);
398  }
399  ?>
400  </td>
401  </tr>
402  </table>
403  <?php
404 
405  return TRUE;
406 
407  }//end paintContainer()
408 
409 
424  public function processContainer(Bodycopy_Div $asset, Backend_Outputter $o, $prefix, $bc_action, $bc_name, Array $bc_data, Array $bc_saved)
425  {
426  $updated = parent::processContainer($asset, $o, $prefix, $bc_action, $bc_name, $bc_data, $bc_saved);
427 
428  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_TYPE_2, 'content_type', FALSE, 'div_contents', 'major', TRUE);
429 
430  if (!empty($link)) {
431  $content_type = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
432  if (!is_null($content_type)) {
433  $content_prefix = $prefix.'_'.get_class_lower($content_type).'_'.$link['linkid'];
434  $content_edit = $content_type->getEditFns();
435  if ($content_edit->processBackend(Array(), $content_type, $content_prefix)) {
436  if ($content_type->saveAttributes()) $updated = TRUE;
437  }
438  }
439  }
440 
441  if (isset($bc_saved[$prefix][$asset->id]['attributes']['content_type'])) {
442  if ($this->_updateCellType($asset, $bc_saved[$prefix][$asset->id]['attributes']['content_type'])) {
443  $updated = TRUE;
444  }
445  }
446 
447  if ($updated) $this->generateContentFile($asset);
448  $this->_contentsUpdated($asset);
449  return $updated;
450 
451  }//end processContainer()
452 
453 
463  protected function _updateCellType(Bodycopy_Div $asset, $new_type='')
464  {
465  // dont change anything if the new type id blank
466  $new_type = trim($new_type);
467  if (empty($new_type)) return FALSE;
468 
469  // get the contentType
470  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_TYPE_2, 'content_type', FALSE, 'div_contents', 'major', TRUE);
471  if (empty($link)) return FALSE;
472  $content_type = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
473 
474  // if the new type is the same as the current, change nothing
475  $current_type = get_class_lower($content_type);
476  if ($current_type == $new_type) return FALSE;
477 
478  // morph the content type to the new type
479  // first up
480  $morphed = $content_type->morph('content_type');
481  if (!$morphed) return FALSE;
482 
483  // then down
484  $content_type = $morphed->morph($new_type);
485  if (!$content_type) return FALSE;
486 
487  return TRUE;
488 
489  }//end _updateCellType()
490 
491 
492 }//end class
493 
494 ?>