17 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_FUDGE_PATH.
'/var_serialise/var_serialise.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
20 require_once SQ_CORE_PACKAGE_PATH.
'/bodycopy/bodycopy/bodycopy_edit_fns.inc';
43 parent::__construct();
44 unset($this->static_screens[
'metadataSchemas']);
45 unset($this->static_screens[
'metadata']);
46 unset($this->static_screens[
'settings']);
47 unset($this->static_screens[
'tagging']);
66 $name = strtolower($name);
67 if (empty($attributes[$name])) $attributes[$name] =
'';
68 if ($attributes[$name] == $value)
return FALSE;
69 $attributes[$name] = $value;
137 $conflict_tags = Array(
150 $conflict_tag_search_string =
'~('.implode(
')|(', $conflict_tags).
')~i';
153 $this->
paint($asset, TRUE);
154 $container_content = ob_get_clean();
156 if (preg_match($conflict_tag_search_string, $container_content)) {
160 $this->
paint($asset, FALSE);
161 $container_content = ob_get_clean();
162 $container_content =
'<div style="padding: 1ex; margin-bottom: 1ex; border: solid 1px grey;"><strong>Container ID '.$asset->id.
'</strong><div class="sq-backend-warning">'.translate(
'bodycopy_html_conflict_warning').
'</div><hr /><pre>'.htmlentities($container_content, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'</pre></div>';
165 echo $container_content.
'<br />';
169 echo
'<span class="sq-backend-warning">You do not have access to view the contents of this container</span>';
198 if (!empty($bc_data[$prefix][$asset->id][
'attributes']) || !empty($bc_saved[$prefix][$asset->id][
'attributes'])) {
199 $attributes_updated = FALSE;
200 $attributes = $asset->
attr(
'attributes');
201 if (isset($bc_data[$prefix][$asset->id][
'attributes'])) {
202 foreach ($bc_data[$prefix][$asset->id][
'attributes'] as $name => $value) {
203 if ($name ==
'identifier') {
211 if ($name ==
'desc') {
215 $attributes_updated = TRUE;
220 if (isset($bc_saved[$prefix][$asset->id][
'attributes'])) {
222 foreach ($bc_saved[$prefix][$asset->id][
'attributes'] as $name => $value) {
223 if ($name ==
'identifier') {
231 if ($name ==
'desc') {
235 $attributes_updated = TRUE;
240 if ($attributes_updated) {
262 $this->
paint($asset, FALSE, TRUE);
263 $output = ob_get_contents();
270 require_once SQ_FUDGE_PATH.
'/general/text.inc';
271 $keywords = retrieve_keywords_replacements($output);
276 $matrix_url_keywords = Array();
277 foreach($keywords as $keyword) {
278 if (strpos($keyword,
'./?a=') !== FALSE) {
279 $hash = md5($keyword);
280 $matrix_url_keywords[$hash] = $keyword;
281 $output = preg_replace(
'|%((<([^>]+?)>)+)?'.escape_regex_chars($keyword).
'((<([^>]+?)>)+)?%|',
'%${1}'.$hash.
'$4%', $output);
286 $e =
'|\\./\\?a=([0-9]+)([^0-9:])|';
287 $r =
'<'.
'?php echo array_get_index($sq_asset_url_list, $1, "./?a=$1"); ?'.
'>$2';
288 $output = preg_replace($e, $r, $output);
290 $e =
'|\\./\\?a=([0-9]+:[^$]*)\\$|';
292 if (preg_match_all($e, $output, $matches, PREG_PATTERN_ORDER)) {
294 $replacements = Array();
295 foreach ($matches[1] as $shadow_assetid) {
297 $replacements[] =
'<'.
'?php echo $sq_asset_url_list['.var_export($shadow_assetid, 1).
']; ?'.
'>';
300 $output = str_replace($matches[0], $replacements, $output);
305 foreach($matrix_url_keywords as $hash => $keyword) {
306 $output = preg_replace(
'|%((<([^>]+?)>)+)?'.$hash.
'((<([^>]+?)>)+)?%|',
'%${1}'.$keyword.
'$4%', $output);
309 $attributes = $asset->
attr(
'attributes');
310 if (empty($attributes[
'disable_keywords'])) {
311 foreach ($keywords as $keyword) {
313 $regex_safe_keyword = escape_regex_chars($keyword);
315 $keyword = str_replace(
'$',
'\\\$', str_replace(
'\n',
'\\\\\n', htmlentities($keyword)));
317 $output = preg_replace(
'|%((<([^>]+?)>)+)?'.$regex_safe_keyword.
'((<([^>]+?)>)+)?%|',
'\\1<'.
'?php echo (isset($keyword_replacements["'.$keyword.
'"])) ? $keyword_replacements["'.$keyword.
'"] : ""; ?'.
'>\\4', $output);
324 foreach ($keywords as $keyword) {
325 $output = preg_replace(
'|%((<([^>]+?)>)+)?'.$keyword.
'((<([^>]+?)>)+)?%|',
'\\1<'.
'?php echo "%'.$keyword.
'%"; ?'.
'>\\4', $output);
331 $output = str_replace(
"\r\n",
"\n", $output);
332 $output = str_replace(
"\r",
"\n", $output);
333 $output = preg_replace(
"/\\?>\n/m",
'?'.
'>'.
"\n\n", $output);
338 $output = str_replace(
"\n",
"\r\n", $output);
340 create_directory($asset->data_path);
342 $contextid = (int)$GLOBALS[
'SQ_SYSTEM']->getContextId();
343 $file_name =
'content_file'.(($contextid === 0) ?
'' : (
'.'.$contextid)).
'.php';
345 return string_to_file($output, $asset->data_path.
'/'.$file_name);
363 if (is_null($output)) {
365 $this->
paint($asset, TRUE);
366 $output = ob_get_contents();
375 $files = glob($asset->data_path.
'/content_file*.php');
376 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
377 $current_filename =
'content_file'.(($contextid === 0) ?
'' : (
'.'.$contextid)).
'.php';
378 foreach ($files as $file) {
379 if (strpos($file, $current_filename) === FALSE) {
380 $output .= file_get_contents($file);
384 $existing_links = $asset->
attr(
'shadow_links');
385 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE);
386 foreach ($notice_links as $link_data) {
387 $existing_links[] = $link_data[
'minorid'];
391 $shadow_reg =
'|\./\?a=(\d+:[0-9a-zA-Z]*)\$|';
392 $normal_reg =
'|\./\?a=(\d+)|';
393 $shadow_matches = Array();
394 $normal_matches = Array();
395 preg_match_all($shadow_reg, $output, $shadow_matches);
396 preg_match_all($normal_reg, $output, $normal_matches);
397 $shadow_matches = $shadow_matches[1];
398 $normal_matches = $normal_matches[1];
399 $replace_assetids = Array();
400 foreach ($shadow_matches as $data) {
401 $replace_assetids[] = $data;
403 foreach ($normal_matches as $data) {
404 $replace_assetids[] = $data;
406 $replace_assetids = array_unique($replace_assetids);
408 if ($asset->status & SQ_SC_STATUS_SAFE_EDITING) {
409 $notice_links_file = file_to_string($asset->data_path.
'/.sq_system/.notice_links');
410 if (!empty($notice_links_file)) {
414 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
415 $system_assetids = unserialize($notice_links_file);
416 $replace_assetids = array_merge($replace_assetids, $system_assetids);
420 if (!empty($replace_assetids) || !empty($notice_links)) {
422 $replace_assetids = array_unique($replace_assetids);
425 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
426 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
428 $run_level_changed = FALSE;
429 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
430 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() - SQ_SECURITY_LOCKING);
431 $run_level_changed = TRUE;
434 foreach ($notice_links as $link_data) {
437 if (empty($link_data[
'value'])) {
438 if (!in_array($link_data[
'minorid'], $replace_assetids)) {
439 if (!$asset->
deleteLink($link_data[
'linkid'])) {
440 if ($run_level_changed) {
441 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
443 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
444 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
451 $shadow_links = array_values(array_intersect($asset->
attr(
'shadow_links'), $replace_assetids));
452 foreach ($replace_assetids as $assetid) {
453 if (!assert_valid_assetid($assetid,
'', FALSE, FALSE)) {
456 if (in_array($assetid, $existing_links))
continue;
458 $ereg_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
459 if (is_null($ereg_asset))
continue;
461 if (strpos($ereg_asset->id,
':') !== FALSE) {
462 $shadow_links[] = $ereg_asset->id;
471 $asset->
createLink($ereg_asset, SQ_LINK_NOTICE);
477 if ($run_level_changed) {
478 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
480 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
481 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
485 if ($run_level_changed) {
486 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
489 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
490 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
510 if (is_null($asset))
return FALSE;
511 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
512 return $em->broadcastEvent($asset,
'contentsUpdated', Array());
527 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
529 $url = $GLOBALS[
'sq_preview_url'];
530 $url = preg_replace(
'|^http[s]?://|',
'', $url);
532 $designid = $am->getValueFromURL($url,
'design::%', TRUE);
536 $design = $am->getAsset($designid);
537 $stylesheets = $design->getStylesheets();
542 $GLOBALS[
'sq_bodycopy_cssids'] = array_keys($stylesheets);
544 $css_urls = $am->getAssetURL($GLOBALS[
'sq_bodycopy_cssids']);
546 $am->forgetAsset($design);
573 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
577 if (isset($GLOBALS[
'sq_preview_url']) && !empty($GLOBALS[
'sq_preview_url'])) {
580 if (!is_null($css_urls)) {
582 <style type=
"text/css">
585 foreach ($css_urls as $cssid => $css_url) {
586 ?>@
import url(
"<?php echo $css_url; ?>");<?php
593 <p
class=
"sq-backend-notice"><b>NOTE:</b> This asset does not have a design applied to it
for the URL currently being edited [<b><?php echo $GLOBALS[
'sq_preview_url']; ?></b>]. No style information is available to use
for content editing.</p>
598 <p
class=
"sq-backend-notice"><b>NOTE:</b> This asset does not have a preview URL or design applied to it in
this context. No style information is available to use
for content editing.</p>
605 $keyword_replacements = Array();
606 $asset->
printBody($keyword_replacements);
614 $init_layer_width = 500;
615 $init_layer_height = 500;
618 $content_types = Array();
619 require_once SQ_CORE_PACKAGE_PATH.
'/content_type/content_type.inc';
622 foreach ($types as $type => $type_data) {
623 $content_types[$type] = Array(
'name' => str_replace(
' Content Type',
'', $type_data[
'name']));
627 <input type=
"hidden" name=
"bodycopy_action" value=
"">
628 <input type=
"hidden" name=
"bodycopy_name" value=
"">
629 <input type=
"hidden" name=
"bodycopy_data" value=
"">
631 <script type=
"text/javascript"src=
"<?php echo sq_web_path('fudge').'/var_serialise/var_serialise.js'?>" ></script>
632 <script type=
"text/javascript"src=
"<?php echo sq_web_path('lib').'/js/detect.js';?>" ></script>
633 <script type=
"text/javascript"src=
"<?php echo sq_web_path('lib').'/js/layer_handler.js';?>" ></script>
634 <script type=
"text/javascript"src=
"<?php echo sq_web_path('lib').'/js/general.js';?>" ></script>
635 <script type=
"text/javascript"src=
"<?php echo sq_web_path('lib').'/js/debug.js';?>" ></script>
636 <script type=
"text/javascript"src=
"<?php echo sq_web_path('lib').'/js/tooltip.js';?>" ></script>
637 <script type=
"text/javascript"src=
"<?php echo sq_web_path('lib').'/html_form/html_form.js';?>" ></script>
639 <script type=
"text/javascript">
642 var bodycopy_current_data =
new Object();
643 var bodycopy_saved =
new Object();
648 var bodycopy_current_edit =
new Object();
649 bodycopy_current_edit[
"data"] = null;
650 bodycopy_current_edit[
"bodycopy_name"] = null;
652 var bodycopy_initialised =
false;
653 var bodycopy_popup = null;
654 var bodycopy_popup_visible =
false;
655 var bodycopy_nested_doc = null;
658 function bodycopy_init() {
659 bodycopy_popup =
new Layer_Handler(
"bodycopyPopupDiv", 0,<?php echo $init_layer_width?>,<?php echo $init_layer_height?>,0);
660 set_bodycopy_nested_doc();
661 bodycopy_hide_popup();
662 bodycopy_initialised =
true;
663 bodycopy_otheronload();
666 var bodycopy_otheronload = (window.onload) ? window.onload :
new Function;
667 window.onload = bodycopy_init;
670 function bodycopy_submit(bodycopy_action, bodycopy_name, bodycopy_data) {
671 var form = document.main_form;
673 form.bodycopy_action.value = bodycopy_action;
674 form.bodycopy_name.value = bodycopy_name;
677 form.bodycopy_data.value = var_serialise(bodycopy_data);
685 function set_bodycopy_nested_doc() {
687 bodycopy_nested_doc = bodycopyFrame;
689 bodycopy_nested_doc = document.getElementById(
"bodycopyFrame");
691 bodycopy_nested_doc = bodycopy_popup.layer;
695 function get_bodycopy_popup_visibilty() {
696 return bodycopy_popup_visible;
699 function bodycopy_show_popup(file, width, height) {
700 if (!bodycopy_initialised) {
701 if (confirm(js_translate(
'page_not_loaded_yet'))) {
702 document.edit.action.value=
'';
703 document.edit.submit()
708 var w = (width != null) ? width : 500;
709 var h = (height != null) ? height : 400;
713 var page_w = (is_nav4 || is_gecko) ? w - 17 : w;
714 var page_h = (is_nav4 || is_gecko) ? h - 17 : h;
716 file =
'<?php echo $asset->getBackendHref('show_popup
');?>' +
'&popup_file=' + file;
717 file +=
'&page_width=' + page_w;
718 file +=
'&page_height=' + page_h;
719 file +=
'&body_extra=';
720 file +=
'&browser=' + ((is_dom) ?
"dom" : ((is_ie4up) ?
"ie" :
"ns"));
722 bodycopy_popup.w = w;
723 bodycopy_popup.h = h;
724 bodycopy_popup.clip(null, w, h, null);
725 bodycopy_popup_visible =
true;
729 bodycopy_nested_doc.width = w - border;
730 bodycopy_nested_doc.height = h - border;
731 bodycopy_nested_doc.location = file;
733 bodycopy_nested_doc.width = w - border;
734 bodycopy_nested_doc.height = h - border;
735 bodycopy_nested_doc.src = file;
737 bodycopy_nested_doc.clip.right = w - border;
738 bodycopy_nested_doc.clip.width = w - border;
739 bodycopy_nested_doc.clip.height = h - border;
740 bodycopy_nested_doc.clip.bottom = h - border;
741 bodycopy_nested_doc.load(file, w - 5);
743 if (is_linux && is_gecko) {
745 bodycopy_nested_doc.height =
'100%';
749 var scroll_top = ((is_ie4up) ? document.body.scrollTop :
self.pageYOffset);
750 bodycopy_popup.move(null, scroll_top + top_offset);
751 bodycopy_popup.show();
754 function bodycopy_hide_popup() {
755 if (!bodycopy_initialised) {
return; }
756 bodycopy_show_popup(
"blank.php");
757 bodycopy_popup_visible = null;
758 bodycopy_popup.hide();
762 var BODYCOPY_AVAILABLE_CONTENT_TYPES = null;
763 function get_bodycopy_available_content_types() {
764 if (BODYCOPY_AVAILABLE_CONTENT_TYPES == null) {
765 BODYCOPY_AVAILABLE_CONTENT_TYPES = var_unserialise(
'<?php echo var_serialise($content_types, TRUE)?>');
767 return BODYCOPY_AVAILABLE_CONTENT_TYPES;
770 function bodycopy_data_exists(args) {
771 var str =
'bodycopy_saved';
772 for (var i = 0; i < args.length; i++) {
773 switch (typeof(args[i])) {
775 str +=
'[' + args[i] +
']';
778 str +=
'["' + args[i] +
'"]';
780 eval(
'var exists = (' + str +
') ? true : false;');
781 if (!exists)
return false;
786 function bodycopy_chgColor(
id, colour) {
789 if (!colour) { colour =
'559AE7'; }
790 chgcell =
"document.getElementById('"+
id +
"').style.backgroundColor = '#"+ colour +
"'";
795 function bodycopy_insert_container(bodycopy_name, containerid, before) {
796 var form = document.main_form;
797 var container_type = form_element_value(form.<?php echo $prefix; ?>_insert_container_type);
798 eval(
'bodycopy_insert_' + container_type +
'("' + bodycopy_name +
'", ' + containerid +
', ' + before +
');');
801 bodycopy_current_data[
"<?php echo $prefix?>"] =
new Object();
806 $container_types = $am->getAssetTypeHierarchy(
'bodycopy_container');
807 foreach ($container_types as $type => $type_data) {
808 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type);
809 $type_asset =
new $type();
810 $edit_fns = $type_asset->getEditFns();
811 $edit_fns->paintGenericBackend($asset, $o, $prefix);
814 $container_type_options = Array();
816 foreach ($container_types as $type => $type_data) {
817 $code = strtolower(substr($type,9));
818 $container_type_options[$code] = ucfirst(substr($type,9));
819 if (empty($default)) $default = $code;
821 echo hidden_field($prefix.
'_insert_container_type', $default);
825 <style type=
"text/css">
831 width:<?php echo $init_layer_width?>;
832 height:<?php echo $init_layer_height?>;
833 clip:rect(0,600,600,0);
836 #bodycopyToolTipDiv {
844 <!-- Begin Tooltip -->
845 <div
id=
"bodycopyToolTipDiv" style=
"z-index:1000"></div>
849 <div
id=
"bodycopyPopupDiv" style=
"z-index:1001">
850 <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>
854 <table border=
"0" cellspacing=
"0" cellpadding=
"0" width=
"100%" class=
"bodytext">
857 <input type=
"hidden" name=
"bodycopy_saved[<?php echo $prefix?>][<?php echo $asset->id?>]" value=
"">
858 <?php $this->paintContainer($asset, $o, $prefix); ?>
883 $this->_saveCssIds($o);
886 $bc_action = (empty($_POST[
'bodycopy_action'])) ?
'' : $_POST[
'bodycopy_action'];
887 $bc_name = (empty($_POST[
'bodycopy_name'])) ?
'' : $_POST[
'bodycopy_name'];
888 $bc_data = (empty($_POST[
'bodycopy_data'])) ? Array() : $_POST[
'bodycopy_data'];
889 $bc_saved = (empty($_POST[
'bodycopy_saved'])) ? Array() : $_POST[
'bodycopy_saved'];
893 if ($bc_data) $bc_data = var_unserialise($bc_data);
896 for (reset($bc_saved); NULL !== ($k = key($bc_saved)); next($bc_saved)) {
897 $containers =& $bc_saved[$k];
898 for (reset($containers); NULL !== ($containersid = key($containers)); next($containers)) {
899 $containers[$containersid] = var_unserialise($containers[$containersid]);
905 if ($this->processContainer($asset, $o, $prefix, $bc_action, $bc_name, $bc_data, $bc_saved)) {
926 text_area($prefix.
'_description', $asset->
attr(
'description'), 20, 3);
930 echo nl2br(htmlspecialchars($asset->
attr(
'description')));
949 if (isset($_POST[$prefix.
'_description']) && !empty($_POST[$prefix.
'_description'])) {
951 $value = $_REQUEST[$prefix.
'_description'];
954 $attributes = $asset->
attr(
'attributes');
955 $attributes[
'desc'] = $value;
958 trigger_localised_error(
'CORE0121', E_USER_WARNING, $asset->name, $asset->id);