17 require_once SQ_INCLUDE_PATH.
'/asset.inc';
37 public $keyword_replacements = Array();
48 parent::__construct($assetid);
61 $lock_types = parent::lockTypes();
62 $lock_types[
'content'] = ($lock_types[
'attributes'] | $lock_types[
'links']);
80 public function create(Array &$link, $bc_data=Array())
83 $this->_tmp[
'bodycopy_create_data'] = $bc_data;
85 return parent::create($link);
102 if (!parent::_preCreateCheck($link))
return FALSE;
104 $name = trim($this->
attr(
'name'));
106 trigger_localised_error(
'CORE0083', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
128 $bc_data = $this->_tmp[
'bodycopy_create_data'];
129 unset($this->_tmp[
'bodycopy_create_data']);
131 if (!parent::_createAdditional($link))
return FALSE;
134 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy_div');
135 $bodycopy_div =
new Bodycopy_DIV();
136 $copy_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'',
'sort_order' => 1,
'is_dependant' => 1);
137 $bodycopy_div->setAttrValue(
'name',
'Content DIV');
138 $create_success = $bodycopy_div->create($copy_link, $bc_data);
139 return $create_success;
164 public function prepareLink(
Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
167 if ($side_of_link ==
'major' && ($asset instanceof
Bodycopy_Container) && $dependant !=
'1') {
169 $link_type = SQ_LINK_TYPE_2;
188 SQ_LINK_TYPE_2 => Array(
189 'bodycopy_container' => Array(
191 'exclusive' => FALSE,
210 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
213 if (!create_directory($this->data_path)) {
214 trigger_localised_error(
'CORE0049', E_USER_WARNING, $this->name);
218 switch ($new_status) {
219 case SQ_STATUS_EDITING:
221 if ($this->status == SQ_STATUS_LIVE) {
222 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
223 file_put_contents($this->data_path.
'/.safe_edit_before', serialize($containers));
224 file_put_contents($this->data_path.
'/.safe_edit_after', serialize($containers));
228 if ($this->status == SQ_STATUS_EDITING) {
230 $before_safe_edit = Array();
231 $after_safe_edit = Array();
232 $before_safe_edit_string = file_to_string($this->data_path.
'/.safe_edit_before');
233 $after_safe_edit_string = file_to_string($this->data_path.
'/.safe_edit_after');
235 if (!empty($before_safe_edit_string)) {
236 $before_safe_edit = @unserialize($before_safe_edit_string);
238 if (!empty($after_safe_edit_string)) {
239 $after_safe_edit = @unserialize($after_safe_edit_string);
243 if (!empty($after_safe_edit)) {
244 foreach ($after_safe_edit as $active_link) {
245 if (!$this->
_compareLink($active_link, $before_safe_edit)) {
247 if (isset($active_link[
'linkid'])) {
249 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
251 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
261 if ($this->status == SQ_STATUS_EDITING_APPROVED) {
268 return parent::processStatusChange($new_status, $update_parents);
283 if (!isset($_REQUEST[
'asset_ei_screen'])) {
284 return parent::paintBackend($o);
286 switch ($_REQUEST[
'asset_ei_screen']) {
288 $include_file = trim($_REQUEST[
'popup_file']);
289 $include_dir = dirname(__FILE__).
'/popups/';
290 $dir_listing = scandir($include_dir);
292 if (in_array($include_file, $dir_listing)) {
293 require_once($include_dir.$include_file);
297 return parent::paintBackend($o);
312 if (!isset($_REQUEST[
'asset_ei_screen'])) {
313 return parent::printFrontend();
315 switch ($_REQUEST[
'asset_ei_screen']) {
317 $include_file = trim($_REQUEST[
'popup_file']);
318 $include_dir = dirname(__FILE__).
'/popups/';
319 $dir_listing = scandir($include_dir);
321 if (in_array($include_file, $dir_listing)) {
322 require_once($include_dir.$include_file);
326 return parent::printFrontend();
344 if (is_file($this->data_path.
'/.content_file.php') && $this->useSystemVersion()) {
347 $sq_asset_url_list = Array();
349 $notice_links = unserialize(file_to_string($this->data_path.
'/.notice_links'));
351 $sq_asset_url_list = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_unique($notice_links));
352 for (reset($sq_asset_url_list); NULL !== ($minorid = key($sq_asset_url_list)); next($sq_asset_url_list)) {
353 if ($sq_asset_url_list[$minorid] ==
'') {
354 $sq_asset_url_list[$minorid] =
'./?a='.$minorid;
358 include($this->data_path.
'/.content_file.php');
359 $content = ob_get_contents();
361 replace_keywords($content, $this->keyword_replacements);
370 foreach (array_keys($containers) as $i) {
371 $container =& $containers[$i];
372 $container->printBody($this->keyword_replacements);
391 public function _getName($short_name=FALSE, $contextid=NULL)
394 if ($contextid === NULL) {
395 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
399 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
400 if (empty($values) === TRUE) {
401 return parent::_getName($short_name, $contextid);
403 return $values[$this->id];
419 if (SQ_IN_BACKEND || SQ_IN_LIMBO || !isset($this->_tmp[
'containers'])) {
420 $this->_tmp[
'containers'] = Array();
421 $container_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
422 foreach ($container_links as $container_data) {
423 $this->_tmp[
'containers'][] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($container_data[
'minorid'], $container_data[
'minor_type_code']);
426 return $this->_tmp[
'containers'];
439 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
440 $containers = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE);
441 foreach ($containers as $container_data) {
442 $container = $am->getAsset($container_data[
'minorid'], $container_data[
'minor_type_code']);
443 if (!$container->isEmpty())
return FALSE;
458 require_once SQ_FUDGE_PATH.
'/general/text.inc';
460 $keywords = retrieve_keywords_replacements($content);
491 foreach (array_keys($containers) as $i) {
492 $container =& $containers[$i];
493 $edit = $container->getEditFns();
494 $edit->paint($container, FALSE, TRUE);
496 $contents = ob_get_contents();
514 if (!is_array($replacements))
return FALSE;
515 if (empty($replacements))
return FALSE;
517 $this->keyword_replacements = $replacements;
534 if (!isset($current_link[
'minorid'])) {
539 foreach ($before_links as $before_link) {
540 if (isset($before_link[
'minorid'])) {
541 if ($before_link[
'minorid'] == $current_link[
'minorid']) {
562 if (file_exists($this->data_path.
'/.safe_edit_after')) {
563 unlink($this->data_path.
'/.safe_edit_after');
565 if (file_exists($this->data_path.
'/.safe_edit_before')) {
566 unlink($this->data_path.
'/.safe_edit_before');