/** * Initializes the application. Sets up default routes. */ public function __construct() { if (Curry_Core::$config->curry->pageCache && class_exists('Page')) { Page::getCachedPages(); } $this->addRoute(new Curry_Route_ModelRoute()); $this->addRoute(new Curry_Route_Page()); Curry_URL::setReverseRouteCallback(array($this, 'reverseRoute')); }
/** * Perform routing. * * @param Curry_Request $request * @return Page|bool */ public function route(Curry_Request $request) { $requestUri = $request->getUrl()->getPath(); // add trailing slash if missing if ($requestUri && substr($requestUri, -1) != '/') { $requestUri .= '/'; } // use domain mapping to restrict page to a certain page-branch $rootPage = null; if (Curry_Core::$config->curry->domainMapping->enabled) { $currentDomain = strtolower($_SERVER['HTTP_HOST']); foreach (Curry_Core::$config->curry->domainMapping->domains as $domain) { if (strtolower($domain->domain) === $currentDomain || $domain->include_www && strtolower('www.' . $domain->domain) === $currentDomain) { $rootPage = $domain->base_page; break; } } if (!$rootPage && Curry_Core::$config->curry->domainMapping->default) { $rootPage = Curry_Core::$config->curry->domainMapping->default; } if ($rootPage) { $rootPage = PageQuery::create()->findPk($rootPage); } } // attempt to find page using url if (Curry_Core::$config->curry->pageCache) { $pages = array(); $allPages = Page::getCachedPages(); foreach ($allPages as $page) { if ($page->getUrl() == $requestUri) { if (!$rootPage || $rootPage->isAncestorOf($page) || $rootPage->getPageId() == $page->getPageId()) { $pages[] = $page; } } } } else { $pages = PageQuery::create()->filterByUrl($requestUri)->_if($rootPage)->branchOf($rootPage)->_endif()->joinWith('Page.ActivePageRevision apr', Criteria::LEFT_JOIN)->find(); } if (count($pages) > 1) { throw new Exception('URL refers to multiple pages: ' . $requestUri); } else { if (count($pages) == 1) { return $pages[0]; } } return false; }