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']); } } }
function find_page_by_uri($uri) { global $__FROG_CONN__; $uri = trim($uri, '/'); $has_behavior = false; // adding the home root $urls = array_merge(array(''), explode_uri($uri)); $url = ''; $page = new stdClass(); $page->id = 0; $parent = false; foreach ($urls as $page_slug) { $url = ltrim($url . '/' . $page_slug, '/'); if ($page = find_page_by_slug($page_slug, $parent)) { // check for behavior if ($page->behavior_id != '') { // add a instance of the behavior with the name of the behavior $params = explode_uri(substr($uri, strlen($url))); $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params); return $page; } } else { break; } $parent = $page; } // foreach return !$page && $has_behavior ? $parent : $page; }
protected function loadBehavior($behavior, $options = array()) { $behavior = Inflector::camelize($behavior); Behavior::load($behavior); return $this->{$behavior} = new $behavior($this, $options); }
public static function findByUri($uri, $class = __CLASS__) { //print "Page::findByUri($uri)"; $uri = trim($uri, '/'); $has_behavior = false; $urls = array_merge(array(''), explode_uri($uri)); $url = ''; $parent = new Page(); $parent->id(0); foreach ($urls as $page_slug) { $url = ltrim($url . '/' . $page_slug, '/'); if ($page = Page::findBySlugAndParentId($page_slug, $parent->id())) { if ($page->behaviorId()) { $has_behavior = true; // add a instance of the behavior with the name of the behavior $params = explode_uri(substr($uri, strlen($url))); print_r($params); $page->behavior(Behavior::load($page->behaviorId(), $page, $params)); return $page; } } else { break; } $parent = $page; } return !$page && $has_behavior ? $parent : $page; }
/** * Finds a Page record based on it's path. * * @param string $path path/to/page * @param bool $all flag for returning all status types * @return mixed Page object or false */ public static function findByPath($path, $all = false) { $path = trim($path, '/'); $has_behavior = false; // adding the home root $slugs = array_merge(array(''), explode_path($path)); $url = ''; $page = new stdClass(); $page->id = 0; $parent = false; foreach ($slugs as $slug) { $url = ltrim($url . '/' . $slug, '/'); $page = self::findBySlug($slug, $parent, $all); if ($page instanceof Page) { // check for behavior if ($page->behavior_id != '') { // add an instance of the behavior with the name of the behavior $params = explode_path(substr($path, strlen($url))); $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params); return $page; } } else { break; } $parent = $page; } // foreach return $page; }
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; }
/** * * @param string $uri * @param boolean $include_hidden * @param Model_Page_Front $parent * @return \Model_Page_Front */ public static function find($uri, $include_hidden = TRUE, Model_Page_Front $parent = NULL) { if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start(__CLASS__, __METHOD__); } $uri = trim($uri, '/'); $urls = preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY); if ($parent === NULL) { $urls = array_merge(array(''), $urls); } $url = ''; $page = new stdClass(); $page->id = 0; foreach ($urls as $page_slug) { $url = ltrim($url . '/' . $page_slug, '/'); if ($page = self::findBySlug($page_slug, $parent, $include_hidden)) { if (!empty($page->behavior_id)) { $behavior = Behavior::load($page->behavior_id, $page, $url, $uri); if ($behavior !== NULL) { $page->_behavior = $behavior; if (isset($benchmark)) { Profiler::stop($benchmark); } self::$_initial_page = $page; return $page; } } } else { break; } $parent = $page; } self::$_initial_page = $page; if (isset($benchmark)) { Profiler::stop($benchmark); } return $page; }