18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
60 public function create(Array &$link, Array $bc_data=Array())
63 $this->_tmp[
'bodycopy_create_data'] = $bc_data;
65 return parent::create($link);
82 if (!parent::_preCreateCheck($link))
return FALSE;
84 $name = trim($this->
attr(
'name'));
86 trigger_localised_error(
'CORE0083', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
103 $lock_types = parent::lockTypes();
104 $lock_types[
'content'] = ($lock_types[
'attributes'] | $lock_types[
'links']);
121 if (!isset($_REQUEST[
'asset_ei_screen'])) {
122 return parent::paintBackend($o);
125 switch ($_REQUEST[
'asset_ei_screen']) {
128 $type_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo(
'bodycopy');
130 $include_file = trim($_REQUEST[
'popup_file']);
131 $bodycopy_popup_dir = SQ_SYSTEM_ROOT.
'/'.$type_info[
'dir'].
'/popups/';
132 $dir_listing = scandir($bodycopy_popup_dir);
134 if (in_array($include_file, $dir_listing)) {
135 require_once($bodycopy_popup_dir.$include_file);
140 return parent::paintBackend($o);
157 if (!parent::saveSystemVersion())
return FALSE;
158 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
163 if (!isset($this->_tmp[
'skip_save_system_version_content_file'])) {
166 if (!$edit->generateContentFile($this)) {
167 trigger_localised_error(
'CORE0047', E_USER_WARNING, $this->name);
171 $contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
172 foreach ($contexts as $contextid => $context_data) {
173 $filename_suffix = ((int)$contextid === 0) ?
'' :
'.'.$contextid;
174 if (file_exists($this->data_path.
'/content_file'.$filename_suffix.
'.php') === TRUE) {
175 $copy_usv = copy_file($this->data_path.
'/content_file'.$filename_suffix.
'.php', $this->data_path.
'/.sq_system/.content_file'.$filename_suffix.
'.php');
180 unset($this->_tmp[
'skip_save_system_version_content_file']);
184 $replace_assetids = Array();
185 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
187 foreach ($notice_links as $link) {
188 $replace_assetids[] = $link[
'minorid'];
192 if (!string_to_file(serialize($replace_assetids), $this->data_path.
'/.sq_system/.notice_links')) {
193 trigger_localised_error(
'CORE0048', E_USER_WARNING, $this->name);
213 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
214 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
216 $old_status = $this->status;
217 if (!parent::processStatusChange($new_status, $update_parent)) {
218 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
219 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
227 if ($this->status == SQ_STATUS_LIVE && ($old_status & SQ_SC_STATUS_SAFE_EDITING)) {
229 if (!$edit->createContentLinks($this)) {
230 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
231 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
236 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
237 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
263 public function prepareLink(
Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
266 if ($side_of_link ==
'major' && ($asset instanceof
Content_Type) && $dependant !=
'1' && ($link_type & SQ_SC_LINK_SIGNIFICANT)) {
286 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id);
287 if (!parent::deleteLink($linkid))
return FALSE;
293 $edit_fns->paint($this, TRUE);
294 $output = ob_get_contents();
298 $e =
'/\\.\\/\\?a=([0-9]+)/';
300 preg_match_all($e, $output, $matches);
301 $replace_assetids = $matches[1];
318 SQ_LINK_TYPE_2 => Array(
319 'content_type' => Array(
321 'exclusive' => FALSE,
324 SQ_LINK_NOTICE => Array(
327 'exclusive' => FALSE,
345 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
346 if ($link[
'link_type'] == SQ_LINK_NOTICE) {
347 return 'Linked inside the content as a URL, image, or embedded movie';
349 return parent::describeLink($linkid);
373 if (is_null($keyword_replacements)) {
374 $keyword_replacements = Array();
378 $edit->paint($this, FALSE, TRUE);
379 $temp_raw_content = ob_get_contents();
381 $keywords = retrieve_keywords_replacements($temp_raw_content);
384 if (!empty($keywords)) {
385 $dependant_parent_assetids = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($this->
id,
'', FALSE, FALSE);
389 if (count($dependant_parent_assetids) === 1) {
390 $dependant_parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(array_pop($dependant_parent_assetids));
391 foreach ($keywords as $keyword) {
392 $keyword_replacements[$keyword] = $dependant_parent_asset->getKeywordReplacement($keyword);
394 }
else if (count($dependant_parent_assetids) > 1) {
398 foreach ($keywords as $keyword) {
399 if (0 === strpos($keyword,
'globals_')) {
400 $keyword_replacements[$keyword] =
"%$keyword%";
408 foreach($keyword_replacements as $keyword => $val) {
409 $safe_keyword = htmlentities($keyword);
410 if ($safe_keyword != $keyword) {
411 $keyword_replacements[$safe_keyword] = $val;
412 unset($keyword_replacements[$keyword]);
416 $contextid = (int)$GLOBALS[
'SQ_SYSTEM']->getContextId();
417 $context_suffix = ($contextid === 0) ?
'' : (
'.'.$contextid);
418 $content_file_name =
'content_file'.$context_suffix.
'.php';
419 $default_content_file_name =
'content_file.php';
422 $safe_edit_file_name = $this->data_path.
'/.'.$content_file_name;
423 if (file_exists($safe_edit_file_name) === FALSE) {
424 $safe_edit_file_name = $this->data_path.
'/.'.$default_content_file_name;
426 if (file_exists($safe_edit_file_name) === TRUE) {
429 $sq_asset_url_list = Array();
431 $notice_links = unserialize(file_to_string($this->data_path.
'/.notice_links'));
432 $get_href_ids = $this->
attr(
'shadow_links');
434 foreach ($notice_links as $link_assetid) {
435 $get_href_ids[] = $link_assetid;
438 $sq_asset_url_list = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_unique($get_href_ids));
439 for (reset($sq_asset_url_list); NULL !== ($minorid = key($sq_asset_url_list)); next($sq_asset_url_list)) {
440 if ($sq_asset_url_list[$minorid] ==
'') {
441 $sq_asset_url_list[$minorid] =
'./?a='.$minorid;
446 include($safe_edit_file_name);
447 $content = ob_get_contents();
449 replace_keywords($content, $this->keyword_replacements);
455 if (!isset($this->_tmp[
'asset_url_list'])) {
460 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
461 $get_href_ids = $this->
attr(
'shadow_links');
463 foreach ($notice_links as $link) {
464 $get_href_ids[] = $link[
'minorid'];
467 $this->_tmp[
'asset_url_list'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_unique($get_href_ids));
468 for (reset($this->_tmp[
'asset_url_list']); NULL !== ($minorid = key($this->_tmp[
'asset_url_list'])); next($this->_tmp[
'asset_url_list'])) {
469 if ($this->_tmp[
'asset_url_list'][$minorid] ==
'') {
470 $this->_tmp[
'asset_url_list'][$minorid] =
'./?a='.$minorid;
476 $sq_asset_url_list =& $this->_tmp[
'asset_url_list'];
478 if (SQ_ROLLBACK_VIEW) {
481 $edit->paint($this, FALSE, FALSE);
482 $output = ob_get_contents();
486 foreach ($sq_asset_url_list as $assetid => $href) {
487 if (strpos($assetid,
':') !== FALSE) {
488 $s =
'./?a='.$assetid.
'$';
489 $output = str_replace($s, $href, $output);
491 $e =
"!(/?\./\\?a=$assetid)([^0-9:])!";
492 $output = preg_replace($e, $href.
'\\2', $output);
497 replace_keywords($output, $keyword_replacements);
503 if (!is_file($this->data_path.
'/'.$content_file_name)) {
506 $edit->generateContentFile($this);
509 if (!is_file($this->data_path.
'/'.$content_file_name)) {
510 trigger_localised_error(
'CORE0009', E_USER_WARNING, $this->name);
512 include($this->data_path.
'/'.$content_file_name);
529 protected function _getName($short_name=FALSE, $contextid=NULL)
532 if ($contextid === NULL) {
533 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
537 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
538 if (empty($values) === TRUE) {
539 return parent::_getName($short_name, $contextid);
541 return $values[$this->id];
555 $am = $GLOBALS[
'SQ_SYSTEM']->am;
556 $content_types = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'content_type', FALSE);
557 foreach ($content_types as $type) {
558 $ct = $am->getAsset($type[
'minorid'], $type[
'minor_type_code']);
559 if (!$ct->isEmpty())
return FALSE;