Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_standard.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page.inc';
19 require_once SQ_FUDGE_PATH.'/general/text.inc';
20 
32 class Page_Standard extends Page
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
59  protected function _createAdditional(Array &$link, $args=Array())
60  {
61  if (!parent::_createAdditional($link)) return FALSE;
62 
63  // add a bodycopy to this page when creating
64  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
65  $bodycopy = new Bodycopy();
66  $copy_link = Array('asset' => &$this, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
67 
68  $bodycopy->setAttrValue('name', 'Page Contents');
69  if ($bodycopy->create($copy_link, $args)) {
70  $child_bodycopy = $GLOBALS['SQ_SYSTEM']->am->getLink($bodycopy->id, SQ_LINK_TYPE_2, 'bodycopy_div');
71  $GLOBALS['SQ_SYSTEM']->am->releaseLock($child_bodycopy['minorid'], 'attributes');
72  return TRUE;
73  }
74  return FALSE;
75 
76  }//end _createAdditional()
77 
78 
99  public function prepareLink(Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
100  {
101  // if a bodycopy is linking to us then we need to make it a dependant link
102  if ($side_of_link == 'major' && ($asset instanceof Bodycopy) && $dependant != '1') {
103  $dependant = '1';
104  return TRUE;
105  }
106 
107  return FALSE;
108 
109  }//end prepareLink()
110 
111 
120  public function isDeletableLink($linkid)
121  {
122  // the only reason why we would object to this link being
123  // deleted is if it is the bodycopy linked to us
124  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, 'major', NULL, '1', '1');
125  if (!$GLOBALS['SQ_PURGING_TRASH'] && (!empty($bodycopy_link) && $bodycopy_link[0]['linkid'] == $linkid)) {
126  return translate('core_error_bodycopy_link_cannot_delete');
127  }
128 
129  return parent::isDeletableLink($linkid);
130 
131  }//end isDeletableLink()
132 
133 
141  public function _getAllowedLinks()
142  {
143  $page_links = parent::_getAllowedLinks();
144  $page_links[SQ_LINK_TYPE_1]['calendar_event_single'] = Array('card' => 'M', 'exclusive' => FALSE);
145  $page_links[SQ_LINK_TYPE_1]['calendar_event_recurring'] = Array('card' => 'M', 'exclusive' => FALSE);
146  $page_links[SQ_LINK_TYPE_2]['calendar_event_single'] = Array('card' => 'M', 'exclusive' => FALSE);
147  $page_links[SQ_LINK_TYPE_2]['calendar_event_recurring'] = Array('card' => 'M', 'exclusive' => FALSE);
148  $page_links[SQ_LINK_TYPE_2]['bodycopy'] = Array('card' => 1, 'exclusive' => TRUE);
149  $page_links[SQ_LINK_NOTICE]['calendar_event_single'] = Array('card' => 'M', 'exclusive' => FALSE);
150  $page_links[SQ_LINK_NOTICE]['calendar_event_recurring'] = Array('card' => 'M', 'exclusive' => FALSE);
151  return $page_links;
152 
153  }//end _getAllowedLinks()
154 
155 
164  public function paintBackend(Backend_Outputter $o)
165  {
166  if (isset($_GET['sq_from_frontend'])) {
167 
168  $bodycopy = $this->getBodycopy();
169  if (is_null($bodycopy)) {
170  trigger_localised_error('CORE0016', $this->name.'"', E_USER_ERROR);
171  return FALSE;
172  }
173  $o->addFormActionGetVar('assetid', $bodycopy->id);
174 
175  // fudge the navigation history a little
176  if (!isset($_SESSION['sq_nav_history'])) {
177  $_SESSION['sq_nav_history'] = Array();
178  $nav_pos = 0;
179  } else {
180  $nav_pos = count($_SESSION['sq_nav_history']) - 1;
181  }
182  $_SESSION['sq_nav_history'][$nav_pos] = Array('assetid' => $this->id, 'screen' => 'details');
183 
184  $bodycopy->paintBackend($o);
185 
186  } else {
187 
188  parent::paintBackend($o);
189  }
190 
191  }//end paintBackend()
192 
193 
200  public function printBody()
201  {
202  // start performance mode timer
203  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this);
204 
205  $contextid = $GLOBALS['SQ_SYSTEM']->getContextId();
206  if ($contextid === 0) {
207  $cache_key = 'default';
208  } else {
209  $cache_key = 'default.'.$contextid;
210  }
211 
212  $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cache_manager');
213  $cached_contents = $cm->loadFromCache($this->id, $this->type(), $cache_key);
214 
215 
216  // if the cache is empty, go ahead and regenerate a new version
217  if ($cached_contents === FALSE) {
218  $bodycopy = $this->getBodycopy();
219  if (is_null($bodycopy)) return;
220  ob_start();
221  // set the keyword replacements
222  $keywords = $bodycopy->getKeywords();
223  $replacements = Array();
224  foreach ($keywords as $word) {
225  $replacements[$word] = $this->getKeywordReplacement($word);
226  }
227  $bodycopy->setKeywordReplacements($replacements);
228 
229  $bodycopy->printBody();
230  $cm->saveToCache($this->id, $this->type(), $cache_key, ob_get_contents());
231  ob_end_flush();
232  } else {
233  echo $cached_contents;
234  }
235 
236  // end performance mode timer
237  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this);
238 
239  }//end printBody()
240 
241 
250  public function initLimbo()
251  {
252  $lm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('layout_manager');
253  $screen = array_get_index($_REQUEST, 'asset_ei_screen', 'details');
254 
255  // Look for a layout for the details screen
256  $layout_pattern = 'layout::'.$this->type().'::details';
257  $lookup_values = $this->getLookupValues(TRUE, $layout_pattern);
258  $details_layout = '';
259  foreach ($lookup_values as $values) {
260  foreach ($values as $look_key => $look_value) {
261  if (isset($look_value['value'])) {
262  $details_layout = $look_value['value'];
263  }
264  }
265  }
266 
267  if (!empty($details_layout) && ($details_layout > 0)) {
268  parent::initLimbo();
269  } else if ($lm->hasLayout($this, $screen)) {
270  // Otherwise lookup layout manager
271  parent::initLimbo();
272  } else {
273  $bodycopy = $this->getBodycopy();
274  if (!is_null($bodycopy)) {
275  $edit_interface = $bodycopy->getEI();
276  $available_screens = array_keys(array_merge($edit_interface->getScreens(), $edit_interface->_edit_fns->static_screens));
277  if (in_array($screen, $available_screens)) {
278  $GLOBALS['SQ_SYSTEM']->backend->out->addFormActionGetVar('assetid', $bodycopy->id);
279  $GLOBALS['SQ_SYSTEM']->backend->out->addHiddenField('backend_assetid', $bodycopy->id);
280  $bodycopy->initLimbo();
281  } else {
282  parent::initLimbo();
283  }
284  }
285  }
286 
287  }//end initLimbo()
288 
289 
296  public function getContent()
297  {
298  $bodycopy = $this->getBodycopy();
299  if (is_null($bodycopy)) return '';
300  $contents = $bodycopy->getRawBodycopyContent();
301 
302  return $contents;
303 
304  }//end getContent()
305 
306 
313  public function lockTypes()
314  {
315  $lock_types = parent::lockTypes();
316  $lock_types['content'] = ($lock_types['attributes'] | $lock_types['links']);
317  return $lock_types;
318 
319  }//end lockTypes()
320 
321 
330  public function getEditingLocks(Array $keywords)
331  {
332  $locks = Array();
333  if (!is_array($keywords) || empty($keywords)) {
334  return Array();
335  }
336  if (!in_array('contents', $keywords)) return Array();
337  return Array('content');
338 
339  }//end getEditingLocks()
340 
341 
348  public function getBodycopy()
349  {
350  $null = NULL;
351  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, '', 'major');
352  if (empty($link)) return $null;
353  $bodycopy = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
354  return $bodycopy;
355 
356  }//end getBodycopy()
357 
358 
368  public function getCustomKeywordReplacements($keywords, $invoke_backend = FALSE)
369  {
370  if (!is_array($keywords) || empty($keywords)) {
371  return Array();
372  }
373  $print_commit_button = FALSE;
374 
375  $replacements = Array();
376  foreach ($keywords as $keyword) {
377  switch ($keyword) {
378  case 'contents' :
379  $bodycopy = $this->getBodycopy();
380  if (is_null($bodycopy)) continue;
381  $edit = $bodycopy->getEditFns();
382  if (!$invoke_backend) {
383  $o = $GLOBALS['SQ_SYSTEM']->backend->out ;
384  } else {
385  require_once SQ_INCLUDE_PATH.'/backend_outputter.inc';
386  $o = new Backend_Outputter();
387  }
388  ob_start();
389  if ($edit->paintBodycopy($bodycopy, $o, $bodycopy->getPrefix())) {
390  $print_commit_button = TRUE;
391  }
392  $replacements[$keyword] = ob_get_contents();
393  ob_end_clean();
394  break;
395 
396  default:
397  $replacements[$keyword] = '';
398  break;
399  }//end switch
400  }//end foreach
401 
402  return Array('replacements' => $replacements, 'print_commit_button' => $print_commit_button);
403 
404  }//end getCustomKeywordReplacements()
405 
406 
416  public function processCustomKeywords(Array $keywords)
417  {
418  if (!is_array($keywords) || empty($keywords)) {
419  return Array();
420  }
421 
422  foreach ($keywords as $keyword) {
423  switch ($keyword) {
424  case 'contents' :
425  $bodycopy = $this->getBodycopy();
426  if (is_null($bodycopy)) continue;
427  $edit = $bodycopy->getEditFns();
428  $edit->processBodycopy($bodycopy, $GLOBALS['SQ_SYSTEM']->backend->out, $bodycopy->getPrefix());
429  break;
430  }
431  }
432 
433  return TRUE;
434 
435  }//end processCustomKeywords()
436 
437 
438 }//end class
439 
440 ?>