/** * Walk the site-tree to find a page given a nested path. * @param $path * @return \DataObject|\Page */ public static function page_for_path($path) { $path = trim($path, '/'); if ($path == '') { return \HomePage::get()->first(); } /** @var \Page $page */ $page = null; $parts = explode('/', $path); $children = \Page::get()->filter('ParentID', 0); while ($segment = array_shift($parts)) { if (!($page = $children->find('URLSegment', $segment))) { break; } $children = $page->Children(); } return $page; }
protected function advertisementParent() { $parent = null; if ($this->owner->ParentID) { $parent = SiteTree::get()->byID($this->owner->ParentID); } elseif ($this->owner->URLSegment != "home") { $parent = SiteTree::get()->where("URLSegment = 'home' AND \"ClassName\" <> 'RedirectorPage'")->First(); if (!$parent) { if (class_exists("HomePage")) { $parent = HomePage::get()->First(); } else { $parent = Page::get()->filter(array("URLSegment" => "home"))->First(); } } } if ($parent) { if ($this->classHasAdvertisements($parent->ClassName)) { return $parent; } } }