18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/var_serialise/var_serialise.inc';
43 parent::__construct();
45 unset($this->static_screens[
'workflow']);
46 unset($this->static_screens[
'metadataSchemas']);
47 unset($this->static_screens[
'metadata']);
48 unset($this->static_screens[
'linking']);
49 unset($this->static_screens[
'settings']);
50 unset($this->static_screens[
'tagging']);
66 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
68 if (isset($GLOBALS[
'sq_preview_url']) && !empty($GLOBALS[
'sq_preview_url'])) {
69 $url = $GLOBALS[
'sq_preview_url'];
70 $url = preg_replace(
'|^http[s]?://|',
'', $url);
72 $designid = $am->getValueFromURL($url,
'design::%frontend%', TRUE);
75 $design = $am->getAsset($designid);
76 $stylesheets = $design->getStylesheets();
81 $GLOBALS[
'sq_bodycopy_cssids'] = array_keys($stylesheets);
83 $am->forgetAsset($design);
88 $o->
note(translate(
'bodycopy_asset_has_no_design', $GLOBALS[
'sq_preview_url']));
93 $o->
note(translate(
'bodycopy_asset_has_no_preview'));
112 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
115 $print_commit_button = $write_access;
121 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
122 if (!$write_access) {
124 foreach ($containers as $container_data) {
125 $container = $am->getAsset($container_data[
'minorid'], $container_data[
'minor_type_code']);
126 if ($container->useSystemVersion()) {
127 $keyword_replacements = Array();
128 $container->printBody($keyword_replacements);
130 $container_edit = $container->getEditFns();
131 $container_edit->paintContainer($container, $o, $prefix);
134 $html = ob_get_clean();
135 $html = preg_replace(
'|<script\b[^>]*>(.*?)</script>|is',
'', $html);
141 $init_layer_width = 500;
142 $init_layer_height = 500;
145 $content_types = Array();
146 require_once SQ_CORE_PACKAGE_PATH.
'/content_type/content_type.inc';
148 foreach ($types as $type => $type_data) {
149 $content_types[$type] = Array(
'name' => str_replace(
' Content Type',
'', $type_data[
'name']));
153 <input type=
"hidden" name=
"bodycopy_action" value=
"">
154 <input type=
"hidden" name=
"bodycopy_name" value=
"">
155 <input type=
"hidden" name=
"bodycopy_data" value=
"">
157 <script type=
"text/javascript">
160 var backendHref =
"<?php echo $asset->getBackendHref('show_popup');?>";
161 var init_layer_width = <?php echo $init_layer_width?>;
162 var init_layer_height = <?php echo $init_layer_height?>;
163 var bodycopy_types =
'<?php echo var_serialise($content_types, TRUE)?>';
164 var _prefix =
"<?php echo $prefix; ?>";
165 var asset_id =
"<?php echo $asset->id; ?>";
168 <script type=
"text/javascript" src=
"<?php echo sq_web_path('data').'/asset_types/bodycopy/js/bodycopy_edit_fns.js'?>"></script>
169 <script type=
"text/javascript" src=
"<?php echo sq_web_path('fudge').'/var_serialise/var_serialise.js'?>" ></script>
170 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/js/detect.js';?>"></script>
171 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/js/layer_handler.js';?>"></script>
172 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/js/general.js';?>"></script>
173 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/js/debug.js';?>"></script>
174 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/html_form/html_form.js';?>"></script>
179 $container_types = $am->getTypeDescendants(
'bodycopy_container');
180 foreach ($container_types as $type) {
181 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type);
182 $type_asset =
new $type();
183 $edit_fns = $type_asset->getEditFns();
184 $edit_fns->paintGenericBackend($asset, $o, $prefix);
187 $container_type_options = Array();
189 foreach ($container_types as $type) {
190 $code = strtolower(substr($type,9));
191 $container_type_options[$code] = ucwords(str_replace(
'_',
' ', substr($type,9)));
192 if (empty($default)) $default = $code;
194 asort($container_type_options);
195 echo hidden_field($prefix.
'_insert_container_type', $default);
198 <style type=
"text/css">
204 width: <?php echo $init_layer_width?>;
205 height: <?php echo $init_layer_height?>;
206 clip: rect(0,600,600,0);
209 #bodycopyToolTipDiv {
219 <div
id=
"bodycopyPopupDiv" style=
"z-index:1001">
220 <iframe name=
"bodycopyFrame" id=
"bodycopyFrame" scrolling=
"no" width=
"<?php echo $init_layer_width?>" height=
"<?php echo $init_layer_height?>" marginwidth=0 marginheight=0 frameborder=
"no"></iframe>
224 <table border=
"0" cellspacing=
"0" cellpadding=
"0" class=
"bodytext">
229 $type_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo(
'bodycopy');
233 foreach ($containers as $container_data) {
234 $container = $am->getAsset($container_data[
'minorid'], $container_data[
'minor_type_code']);
235 $container_edit = $container->getEditFns();
241 <input type=
"hidden" name=
"bodycopy_saved[<?php echo $prefix?>][<?php echo $container->id?>]" value=
"">
242 <table border=
"0" cellspacing=
"0" cellpadding=
"0">
245 if ( $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'bodycopy_container',
'SQ_DIV_DISABLE_CREATE') ===
'yes'){
247 <td colspan=
"2"><span
class=
"sq-backend-warning"><?php echo translate(
'bodycopy_pref_cannot_insert_new'); ?></span></td>
254 Bodycopy_Edit_Fns::printBodycopyIcon(
"document.main_form.{$prefix}_insert_container_type.value = document.main_form.{$prefix}_insert_container_type_before_{$i}.value; bodycopy_insert_container('$prefix', $i, true)", translate(
'insert_container'), translate(
'select_container_type'),
'create_container',
'['.translate(
'insert').
']');
257 <td
class=
"sq-backend-data" valign=
"top">
259 echo
' '.translate(
'create_new').
' ';
260 echo combo_box($prefix.
'_insert_container_type_before_'.$i, $container_type_options, FALSE,
'');
280 if ($container_edit->paintContainer($container, $o, $prefix) == TRUE) {
281 $print_commit_button = TRUE;
297 <table border=
"0" cellspacing=
"0" cellpadding=
"0">
300 if ( $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'bodycopy_container',
'SQ_DIV_DISABLE_CREATE') ===
'yes'){
302 <td colspan=
"2"><span
class=
"sq-backend-warning"><?php echo translate(
'bodycopy_pref_cannot_insert_new'); ?></span></td>
309 Bodycopy_Edit_Fns::printBodycopyIcon(
"document.main_form.{$prefix}_insert_container_type.value = document.main_form.{$prefix}_insert_container_type_after_{$i}.value; bodycopy_insert_container('$prefix', $i, false)", translate(
'insert_container'), translate(
'select_container_type'),
'create_container',
'['.translate(
'insert').
']');
312 <td
class=
"sq-backend-data" valign=
"top">
314 echo
' '.translate(
'create_new').
' ';
315 echo combo_box($prefix.
'_insert_container_type_after_'.$i, $container_type_options, FALSE,
'');
333 return $print_commit_button;
350 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
356 $this->_saveCssIds($o,TRUE);
359 if (empty($this->_tmp[
'update_initialised'])) {
360 $bc_action = (empty($_POST[
'bodycopy_action'])) ?
'' : $_POST[
'bodycopy_action'];
361 $bc_name = (empty($_POST[
'bodycopy_name'])) ?
'' : $_POST[
'bodycopy_name'];
362 $bc_data = (empty($_POST[
'bodycopy_data'])) ? Array() : $_POST[
'bodycopy_data'];
363 $bc_saved = (empty($_POST[
'bodycopy_saved'])) ? Array() : $_POST[
'bodycopy_saved'];
365 if (empty($bc_data) && empty($bc_saved)) {
371 if ($bc_data) $bc_data = var_unserialise($bc_data);
374 for (reset($bc_saved); NULL !== ($k = key($bc_saved)); next($bc_saved)) {
375 $containers =& $bc_saved[$k];
376 for (reset($containers); NULL !== ($containersid = key($containers)); next($containers)) {
377 $containers[$containersid] = var_unserialise($containers[$containersid]);
383 $this->_tmp[
'update_initialised'] = TRUE;
387 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
390 foreach ($containers as $container_data) {
391 $container = $am->getAsset($container_data[
'minorid'], $container_data[
'minor_type_code']);
392 $container_edit = $container->getEditFns();
393 if ($container_edit->processContainer($container, $o, $prefix, $bc_action, $bc_name, $bc_data, $bc_saved)) {
394 if ($container->saveAttributes()) $updated = TRUE;
399 if ($bc_name == $prefix || isset($bc_saved[$prefix])) {
401 if ($bc_name == $prefix) {
402 switch ($bc_action) {
403 case 'insert_container' :
404 if ($this->insertContainer($asset, $bc_data[
'container_type'], $bc_data[
'containerid'], $bc_data)) {
409 case 'delete_container' :
410 if ($this->deleteContainer($asset, $bc_data[
'containerid'])) {
435 public function insertContainer(
Bodycopy $asset, $type, $containerid, Array $bc_data)
438 if ($asset->status & SQ_SC_STATUS_SAFE_EDITING) {
439 if (!file_exists($asset->data_path.
'/.safe_edit_before')) {
440 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
441 file_put_contents($asset->data_path.
'/.safe_edit_before', serialize($containers));
446 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
447 $num_containers = count($containers);
449 $containerid = intval($containerid);
452 if ($containerid > $num_containers - 1) {
453 $containerid = $num_containers - 1;
454 }
else if ($containerid < 0) {
460 if (!$bc_data[
'before']) $containerid++;
463 $copy_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'',
'sort_order' => $containerid,
'is_dependant' => 1);
465 $asset_type =
'bodycopy_'.$type;
466 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($asset_type);
467 $new_container =
new $asset_type();
469 $new_container->_tmp[
'skip_save_system_version_content_file'] = TRUE;
471 $new_container->setAttrValue(
'name',
'New '.ucfirst($type));
472 $new_container->setAttrValue(
'attributes', $bc_data[
'attributes']);
473 $retval = (bool) $new_container->create($copy_link, $bc_data);
474 if ($retval && (!isset($bc_data[
'attributes'][
'identifier']) || trim($bc_data[
'attributes'][
'identifier']) ==
'')) {
476 $new_container->setAttrValue(
'name',
'New '.ucfirst($type).
' '.$new_container->id);
477 $new_container->saveAttributes();
481 if ($asset->status & SQ_SC_STATUS_SAFE_EDITING) {
482 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
483 $schemas = $wfm->getSchemas($asset->id, TRUE);
484 if (!empty($schemas) && $new_container->status != SQ_STATUS_EDITING) {
486 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(191);
487 $new_container->saveSystemVersion();
488 $new_container->processStatusChange(SQ_STATUS_EDITING, FALSE);
489 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($new_container->id);
490 if (!empty($children)) {
491 foreach (array_keys($children) as $child_assetid) {
492 $child = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($child_assetid,
'', TRUE);
493 if (!is_null($child)) {
494 $child->saveSystemVersion();
495 $child->processStatusChange(SQ_STATUS_EDITING, FALSE);
496 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($child);
500 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
504 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($new_container);
507 if ($asset->status & SQ_SC_STATUS_SAFE_EDITING) {
508 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
509 file_put_contents($asset->data_path.
'/.safe_edit_after', serialize($containers));
526 public function deleteContainer(
Bodycopy $asset, $containerid)
528 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
531 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
532 foreach ($containers as $container_data) {
533 if ($container_data[
'minorid'] == $containerid) {
535 return $asset->
deleteLink($container_data[
'linkid']);
559 public static function printBodycopyIcon($onclick, $heading, $desc, $icon, $alt=
'', $extra=
'', $width=
'16', $height=
'16')
561 $path = sq_web_path(
'data').
'/asset_types/bodycopy/images/icons/'.$icon.
'.png';
562 $extra .=
' onmouseover="if (bodycopy_initialised) tooltip.show(this, \''.addslashes(htmlentities($desc, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).
'\', \
''.addslashes(htmlentities($heading, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).
'\')
"';
563 $extra .= ' onmouseout="if (bodycopy_initialised) tooltip.hide()
"';
564 $extra .= ' onclick="'.$onclick.'"';
565 $extra .= ' align="absmiddle
" ';
566 if (!empty($onclick)) {
567 $extra .= ' style="cursor:pointer;
"';
569 sq_print_icon($path, $width, $height, $alt, '', $extra);
571 }//end printBodycopyIcon()