public function __construct(&$page, $params) { /* Execute this behaviour only if page equals the current page. */ if (url_match($page->getUri())) { if ($child = $page->children(array('limit' => 1))) { header('Location: ' . $child->url()); die; } } else { // find called page foreach ($params as $slug) { $page = Page::findBySlug($slug, $page); } // if found if ($page instanceof Page) { // check for behavior if ($page->behavior_id != '') { // add a instance of the behavior with the name of the behavior $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params); } } else { // not found page_not_found($_SERVER['REQUEST_URI']); } } }
/** * Display the specified page. * * @param int $id * @return Response */ public function show($slug) { $page = Page::findBySlug($slug)->published()->first(); if ($page) { return View::make('pages.templates.' . $page->template, compact('page')); } else { return View::make('layouts.unpublished'); } }
public function __construct(&$page, $params) { $this->page =& $page; $this->params = $params; switch (count($params)) { case 0: break; // main page of calendar behaviour, don't change anything // main page of calendar behaviour, don't change anything case 1: // there's one parameter after slash $slug = $params[0]; /* We try to find a subpage of the calendar page, so the event's page can be customized */ $page_found = Page::findBySlug($slug, $this->page, true); /* A subpage is found, so display it */ if (is_a($page_found, "Page")) { $this->page = $page_found; } elseif (CalendarPlugin::validateDateString($slug, CALENDAR_SQL_DATE_FORMAT)) { $date = new DateTime($slug); $events = CalendarEvent::findEventsByDate($date); $this->page->title = $date->format(CALENDAR_DISPLAY_DATE_FORMAT); $this->beginCapture(); CalendarPlugin::showEvents($events); $this->endCapture(); } elseif (is_numeric($slug) && ($event = CalendarEvent::findById((int) $slug))) { $this->page->title = $event->getTitle(); $this->beginCapture(); CalendarPlugin::showEvent($event); $this->endCapture(); } else { $this->pageNotFound(); } break; case 2: // there're two parameters after slash $year = (int) $params[0]; $month = (int) $params[1]; $date = new DateTime(); $date->setDate($year, $month, 1); $this->beginCapture(); CalendarPlugin::showCalendar($this->page->slug, $date); $this->endCapture(); break; default: $this->pageNotFound(); } }
public function __construct(&$page, $params) { $this->page =& $page; $this->params = $params; switch (count($params)) { case 0: break; case 1: $slug = $params[0]; /* We try to find a subpage of the calendar page, so the event's page can be customized */ $page_found = Page::findBySlug($slug, $this->page, true); if (is_a($page_found, "Page")) { $this->page = $page_found; } else { /* A subpage is not found, so try to parse a date and then create an event's page */ try { $datetime = new DateTime($slug); } catch (Exception $e) { pageNotFound(); exit; } $events = CalendarEvent::findEventsByDate($datetime->format('Y-m-d')); $this->page->title = strftime("%x", $datetime->getTimestamp()); /* The date should be localized */ $this->beginCapture(); showEvents($events); $this->endCapture(); } break; case 2: $year = $params[0]; $month = $params[1]; $this->beginCapture(); $this->showCalendarForMonth($year, $month); $this->endCapture(); break; default: pageNotFound(); exit; } }
/** * This function should no longer be used. * * @deprecated * @see Page::findBySlug() */ function find_page_by_slug($slug, &$parent, $all = false) { return Page::findBySlug($slug, $parent, $all); }
private function _displayPage($slug) { if (!($this->page = Page::findBySlug($slug, $this->page, true))) { pageNotFound($slug); } }
public static function findByUri($uri, $all = false) { // echo "findByUri: ".$uri; global $__CMS_CONN__; $uri = trim($uri, '/'); $has_behavior = false; // adding the home root $urls = array_merge(array(''), Dispatcher::splitUrl($uri)); $url = ''; $page = new stdClass(); $page->id = 0; $parent = false; foreach ($urls as $page_slug) { $url = ltrim($url . '/' . $page_slug, '/'); if ($page = Page::findBySlug($page_slug, $parent, $all)) { // check for behavior if ($page->behavior_id != '') { // add a instance of the behavior with the name of the behavior $params = Dispatcher::splitUrl(substr($uri, strlen($url))); $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params); return $page; } } else { break; } $parent = $page; } // foreach //echo "<br/> return: ".(( ! $page && $has_behavior) ? $parent->id: $page->id)."<br/>"; return !$page && $has_behavior ? $parent : $page; }
private function _displayPage($slug) { if (!($this->page = Page::findBySlug($slug, $this->page))) { page_not_found(); } }