17 require_once SQ_CORE_PACKAGE_PATH.
'/bodycopy/bodycopy/bodycopy.inc';
18 require_once
'include/conditions_list.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
52 var $asset_to_paint = NULL;
54 var $conditions_list = NULL;
56 var $keyword_replacements = Array();
67 $this->_ser_attrs = TRUE;
68 parent::__construct($assetid);
83 if (!parent::_updated())
return FALSE;
100 require_once SQ_FUDGE_PATH.
'/general/text.inc';
101 $php_begin =
'<'.
'?'.
'php ';
104 $required_substitution_keywords = Array();
105 $required_substitution_asset_keywords = Array();
108 foreach (array_keys($containers) as $i) {
110 $container =& $containers[$i];
111 $edit = $container->getEditFns();
112 $edit->paint($container, FALSE, TRUE);
113 $content = ob_get_contents();
116 $required_keywords = retrieve_keywords_replacements($content);
117 $keyword_replacements = Array();
118 $additional_keywords = Array();
121 foreach ($required_keywords as $keyword) {
122 if (!isset($keyword_replacements[$keyword])) {
125 if (preg_match(
'/^('.SQ_KEYWORD_CONDITION_BEGIN.
'|'.SQ_KEYWORD_CONDITION_END.
'|'.SQ_KEYWORD_CONDITION_ELSE.
')_(.*)$/', $keyword, $condition_parts)) {
126 if (count($condition_parts) == 3) {
127 $test_keyword = $condition_parts[2];
128 switch ($condition_parts[1]) {
129 case SQ_KEYWORD_CONDITION_BEGIN :
131 $value =
'if (!empty($paint_layout_keywords[\''.$test_keyword.
'\']) && trim($paint_layout_keywords[\
''.$test_keyword.
'\']) != \
'\') {
';
133 case SQ_KEYWORD_CONDITION_ELSE :
136 case SQ_KEYWORD_CONDITION_END :
141 if (!empty($value)) {
142 $value = $php_begin.$value.$php_end;
148 $keyword_replacements[$keyword] = $value;
150 $required_substitution_asset_keywords[$keyword] = 1;
156 replace_keywords($content, $keyword_replacements);
160 $e =
'|\./\?a=([0-9:]+)([^0-9])|';
161 $with =
'<'.
'?php echo ((strpos("\\1", ":") !== FALSE) ? "./?a=\\1" : $sq_asset_url_list["\\1"]); ?'.
'>\\2';
162 $content = preg_replace($e, $with, $content);
165 $container = $GLOBALS["SQ_SYSTEM"]->am->getAsset('.$container->id.
', "'.$container->type().
'");
166 if ($container->readAccess()) {
167 '.$php_end.$content.$php_begin.
'
168 }//end if read access for container '.$container->id.
'
173 $content_file = $php_begin.$content_file.$php_end;
177 $content_file = str_replace(
"\r\n",
"\n", $content_file);
178 $content_file = str_replace(
"\r",
"\n", $content_file);
182 $content_file = str_replace(
"\n",
"\r\n", $content_file);
185 if (!is_dir($this->data_path)) {
186 create_directory($this->data_path);
189 $contextid = (int)$GLOBALS[
'SQ_SYSTEM']->getContextId();
190 $file_name =
'content_file'.(($contextid === 0) ?
'' : (
'.'.$contextid)).
'.php';
191 $keyword_name =
'keywords'.(($contextid === 0) ?
'' : (
'.'.$contextid));
193 if (!string_to_file($content_file, $this->data_path.
'/'.$file_name)) {
194 trigger_localised_error(
'CORE0047', E_USER_WARNING, $this->name);
199 create_directory($this->data_path);
200 if (!string_to_file(serialize(array_merge($required_substitution_keywords, $required_substitution_asset_keywords)), $this->data_path.
'/keywords')) {
201 trigger_localised_error(
'CORE0048', E_USER_WARNING, $this->name);
205 if (!string_to_file(serialize($required_substitution_keywords), $this->data_path.
'/conditional_keywords_to_eval')) {
206 trigger_localised_error(
'CORE0048', E_USER_WARNING, $this->name);
237 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this);
240 $this->asset_to_paint = $asset;
242 $contextid = (int)$GLOBALS[
'SQ_SYSTEM']->getContextId();
243 $context_suffix = ($contextid === 0) ?
'' : (
'.'.$contextid);
244 $content_file_name =
'content_file'.$context_suffix.
'.php';
245 $default_content_file_name =
'content_file.php';
246 $content_path = $this->data_path.
'/'.$content_file_name;
247 if (file_exists($content_path) === FALSE) {
248 $content_path = $this->data_path.
'/'.$default_content_file_name;
252 if (file_exists($this->data_path.
'/.notice_links')) {
253 $linked_assets = unserialize(file_to_string($this->data_path.
'/.notice_links'));
257 $linked_assets = Array();
260 foreach ($containers as $container) {
261 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($container->id, SQ_LINK_NOTICE);
262 foreach ($links as $link) {
263 $linked_assets[] = $link[
'minorid'];
266 $linked_assets = array_unique($linked_assets);
268 $sq_asset_url_list = $GLOBALS[
'SQ_SYSTEM']->am->getAssetHref($linked_assets);
271 $paint_layout_keywords = Array();
272 if (file_exists($this->data_path.
'/conditional_keywords_to_eval')) {
273 $required_keywords = array_keys(unserialize(file_to_string($this->data_path.
'/conditional_keywords_to_eval')));
279 if (file_exists($content_path)) {
281 include($content_path);
282 $content = ob_get_contents();
283 $keywords_in_condition = extract_keywords($content);
285 replace_keywords($content, $paint_layout_keywords);
291 $content = ob_get_contents();
295 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this);
316 foreach ($condition_list->getRequiredKeywords($evaluated_keyword) as $required_keyword) {
317 $required_keywords[$required_keyword] = 1;
321 $required_keywords[$evaluated_keyword] = 1;
337 if (!isset($this->keyword_replacements[$keyword_name])) {
341 $value = trim($this->keyword_replacements[$keyword_name]);
343 return ($value !=
'');
361 $ret = isset($ret[$keyword]) ? $ret[$keyword] :
'';
382 foreach ($required_keywords as $required_keyword) {
383 $full_keyword = $required_keyword;
384 $required_keyword = parse_keyword($required_keyword, $modifiers);
385 $context_array = extract_context_modifier($modifiers,
'both');
386 $contextid = $context_array[
'id'];
388 if ($contextid !== NULL) {
390 $required_keyword .=
'^context:'.$context_array[
'name'];
391 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
392 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
394 $contexted_asset = $asset;
398 if ($required_keyword ==
'asset_contents') {
399 if (!isset($ret[
'asset_contents'])) {
401 $contexted_asset->printBody();
402 $ret[
'asset_contents'] = ob_get_contents();
405 }
else if (substr($required_keyword, 0, 21) ==
'asset_contents_paint_') {
406 $paint_layout_name = substr($required_keyword, 21);
409 if (assert_valid_assetid($paint_layout_name,
'', TRUE, FALSE)) {
410 $paint_layout_id = $paint_layout_name;
412 $paint_layout_id = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL(preg_replace(
'/^[^:]*:\/\//',
'', $asset->
getURL()),
'paint_layout::user::'.$paint_layout_name);
415 if (assert_valid_assetid($paint_layout_id,
'Invalid paint layout specified in bodycopy #' . $this->
id .
': ' . $paint_layout_name, FALSE, FALSE)) {
416 $paint_layout = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($paint_layout_id,
'paint_layout_page');
417 if (!empty($paint_layout)) {
421 $type_formats = $paint_layout->getFormats();
422 if (!isset($type_formats[$this->
id])) {
424 $contexted_asset->printBodyWithPaintLayout($paint_layout_id);
425 $ret[$required_keyword] = ob_get_contents();
429 $contexted_asset->printBody();
430 $ret[$required_keyword] = ob_get_contents();
436 $ret[$required_keyword] = $contexted_asset->getKeywordReplacement($required_keyword);
441 if (($full_keyword != $required_keyword) && (0 !== strpos($required_keyword,
'globals_'))) {
443 $ret[$full_keyword] = $ret[$required_keyword];
444 apply_keyword_modifiers($ret[$full_keyword], $modifiers, Array(
'assetid' => $contexted_asset->id));
447 if ($contextid !== NULL) {
448 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($contexted_asset);
449 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
452 unset($contexted_asset);
457 if (in_array(
'asset_lineage', $required_keywords) || in_array(
'asset_lineage_linked', $required_keywords)) {
459 preg_match(
'|^([^:]*)://(.*)|', $asset->
getURL(), $matches);
460 $url = !empty($matches[1]) ? $matches[1] : NULL;
461 $protocol = !empty($matches[2]) ? $matches[2] : NULL;
462 $asset_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL($url, $protocol);
464 $ret[
'asset_lineage'] =
'';
465 $ret[
'asset_lineage_linked'] =
'';
466 $lineage_separator =
' > ';
467 $lineage_separator = $this->
attr(
'lineage_separator');
469 foreach ($asset_lineage as $asset_lineage_item) {
470 if (!empty($ret[
'asset_lineage'])) {
471 $ret[
'asset_lineage'] .= $lineage_separator;
472 $ret[
'asset_lineage_linked'] .= $lineage_separator;
474 $ret[
'asset_lineage'] .= $asset_lineage_item[
'short_name'];
475 $ret[
'asset_lineage_linked'].=
'<a href="'.$asset_lineage_item[
'protocol'].
'://'.$asset_lineage_item[
'url'].
'">'.$asset_lineage_item[
'short_name'].
'</a>';
484 $ret = array_merge($ret, $condition_list->evaluate($asset, $required_keywords, $ret, Array(FALSE, TRUE)));
500 $this->
setAttrValue(
'associated_asset_type', $asset_type);
513 return $this->
attr(
'associated_asset_type');
529 if (is_array($keywords)) {
532 $keywords[
'asset_contents'] = translate(
'asset_contents');
535 if (!empty($asset_type_code)) {
536 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($asset_type_code);
537 $asset =
new $asset_type_code();
539 $asset =
new Asset();
542 $asset_keywords = $asset->getAvailableKeywords();
543 foreach ($asset_keywords as $keyword_name => $description) {
544 $keywords[$keyword_name] = (empty($description)) ? ucwords(str_replace(
'_',
' ', $keyword_name)) : $description;
550 $keywords[
'asset_lineage'] = translate(
'asset_lineage');
551 $keywords[
'asset_lineage_linked'] = translate(
'asset_lineage_linked');
554 $keywords[
'asset_metadata_'] = translate(
'asset_metadata_x');
558 $condition_names = $condition_list->getConditionsNames();
560 foreach ($condition_names as $condition_name) {
561 $keywords[$condition_name] = ucwords(str_replace(
'_',
' ', $condition_name));
562 $keywords[
'begin_'.$condition_name] = translate(
'core_paint_layout_bodycopy_begin').
' '.ucwords(str_replace(
'_',
' ', $condition_name));
563 $keywords[
'else_'.$condition_name] = translate(
'core_paint_layout_bodycopy_else').
' '.ucwords(str_replace(
'_',
' ', $condition_name));
564 $keywords[
'end_'.$condition_name] = translate(
'core_paint_layout_bodycopy_end').
' '.ucwords(str_replace(
'_',
' ', $condition_name));
565 $keywords[
'begin_'.$condition_name.
'%<br />%else_'.$condition_name.
'%<br />%end_'.$condition_name] = translate(
'core_paint_layout_bodycopy_full').
' '.ucwords(str_replace(
'_',
' ', $condition_name));
583 unset($this->_tmp[
'containers']);
584 parent::linksUpdated();
585 if(!$this->
_updated())
return FALSE;