示例#1
0
 public function __invoke(Request $request, \Page $page)
 {
     $app = $this->app;
     $pageRevision = $page->getPageRevision();
     // @todo: these are currently unused :S
     $vars = array();
     $options = array();
     // Find language
     $language = $page->getInheritedProperty('Language');
     $fallbackLanguage = $app['fallbackLanguage'];
     if (!$language && $fallbackLanguage) {
         $app->logger->debug('Using fallback language');
         $language = $fallbackLanguage;
     }
     // Set language
     if ($language) {
         $locale = \Curry_Language::setLanguage($language);
         $language = \Curry_Language::getLanguage();
         if ($language) {
             $app->logger->debug('Current language is now ' . $language->getName() . ' (with locale ' . $locale . ')');
         }
     } else {
         $app->logger->debug('Language not set for page');
     }
     // Attempt to render page
     $app->logger->debug('Showing page ' . $page->getName() . ' (PageRevisionId: ' . $pageRevision->getPageRevisionId() . ')');
     $generator = AbstractGenerator::create($app, $pageRevision);
     return $generator->render($vars, $options);
 }
示例#2
0
 /**
  * @param Request $request
  * @return \Page|null
  * @throws \Exception
  */
 public function findPage(Request $request)
 {
     $requestUri = $request->getPathInfo();
     // remove base path
     $baseUrl = URL::getDefaultBaseUrl();
     $basePath = $baseUrl['path'];
     if (strpos($requestUri, $basePath) === 0) {
         $requestUri = substr($requestUri, strlen($basePath));
     }
     // add trailing slash if missing
     if (substr($requestUri, -1) != '/') {
         $requestUri .= '/';
     }
     // use domain mapping to restrict page to a certain page-branch
     $rootPage = null;
     if ($this->app['domainMapping.enabled']) {
         $currentDomain = strtolower($request->server->get('HTTP_HOST'));
         foreach ($this->app['domainMapping.domains'] as $domain) {
             if (strtolower($domain->domain) === $currentDomain || $domain->include_www && strtolower('www.' . $domain->domain) === $currentDomain) {
                 $rootPage = $domain->base_page;
                 break;
             }
         }
         if (!$rootPage && $this->app['domainMapping.default']) {
             $rootPage = $this->app['domainMapping.default'];
         }
         if ($rootPage) {
             $rootPage = \PageQuery::create()->findPk($rootPage);
         }
     }
     // attempt to find page using url
     if ($this->app['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 null;
 }