Example #1
0
 /**
  * Execute actions.
  */
 public function preShow()
 {
     parent::preShow();
     Page::setRevisionType(Page::WORKING_REVISION);
 }
Example #2
0
 /**
  * Handle the specified request.
  *
  * @param Curry_Request $request
  */
 public function handle(Curry_Request $request)
 {
     trace_notice('Starting request at ' . $request->getUri());
     if (Curry_Core::$config->curry->autoPublish) {
         $this->autoPublish();
     }
     $page = null;
     $vars = array('curry' => array());
     $options = array();
     $forceShow = false;
     $showWorking = false;
     if (Curry_Core::$config->curry->setup) {
         die('Site is not yet configured, go to admin.php and configure your site.');
     }
     // check if we have a valid backend-user logged in
     $validUser = !!User::getUser();
     if ($validUser) {
         // check for inline-admin
         $adminNamespace = new Zend_Session_Namespace('Curry_Admin');
         if (Curry_Core::$config->curry->liveEdit && !$request->getParam('curry_force_show')) {
             if ($request->hasParam('curry_inline_admin')) {
                 $adminNamespace->inlineAdmin = $request->getParam('curry_inline_admin') ? true : false;
             }
             if ($adminNamespace->inlineAdmin) {
                 $options['inlineAdmin'] = true;
                 $forceShow = true;
                 $showWorking = true;
                 Curry_InlineAdmin::$active = true;
             }
         }
         // show working revision? (default is published)
         if ($request->getParam('curry_show_working')) {
             $forceShow = true;
             $showWorking = true;
         }
         // show inactive pages?
         if ($request->getParam('curry_force_show')) {
             $forceShow = true;
         }
         if ($showWorking) {
             Page::setRevisionType(Page::WORKING_REVISION);
         }
     }
     // Maintenance enabled?
     if (Curry_Core::$config->curry->maintenance->enabled && !$forceShow) {
         Curry_Core::log("Maintenance enabled");
         header('HTTP/1.1 503 Service Temporarily Unavailable');
         header('Status: 503 Service Temporarily Unavailable');
         header('Retry-After: 3600');
         $message = 'Page is down for maintenance, please check back later.';
         if (Curry_Core::$config->curry->maintenance->message) {
             $message = Curry_Core::$config->curry->maintenance->message;
         }
         $page = Curry_Core::$config->curry->maintenance->page;
         if ($page !== null) {
             $page = PageQuery::create()->findPk((int) $page);
         }
         if (!$page) {
             die($message);
         }
         $vars['curry']['MaintenanceMessage'] = $message;
     }
     // Check force domain?
     if (Curry_Core::$config->curry->forceDomain && !$forceShow) {
         $uri = $request->getUri();
         $url = parse_url(Curry_Core::$config->curry->baseUrl);
         if (strcasecmp($_SERVER['HTTP_HOST'], $url['host']) !== 0) {
             $location = substr(Curry_Core::$config->curry->baseUrl, 0, -1) . $uri;
             header("Location: " . $location, true, 301);
             exit;
         }
     }
     // Parameters to show a single module
     if ($request->getParam('curry_show_page_module_id')) {
         $options['pageModuleId'] = $request->getParam('curry_show_page_module_id');
     }
     if (isAjax() && $request->getParam('curry_ajax_page_module_id')) {
         $options['pageModuleId'] = $request->getParam('curry_ajax_page_module_id');
     }
     // Attempt to find cached page
     if ($request->getMethod() === 'GET') {
         $time = microtime(true);
         $cacheName = __CLASS__ . '_Page_' . md5($request->getUri());
         if (($cache = Curry_Core::$cache->load($cacheName)) !== false) {
             trace_notice('Using cached page content');
             foreach ($cache['headers'] as $header) {
                 header($header);
             }
             echo $cache['content'];
             Curry_Core::triggerHook('Curry_Application::render', $cache['page_id'], $cache['page_revision_id'], microtime(true) - $time, 0);
             return;
         }
     }
     // attempt to find the requested page
     if (!$page) {
         try {
             $page = $this->findPage($request);
             $page = $this->redirectPage($page, $request);
         } catch (Exception $e) {
             Curry_Core::log('Error when trying to find page: ' . $e->getMessage(), Zend_Log::ERR);
             $page = null;
         }
         // make sure page is enabled
         if ($page instanceof Page && !$forceShow && !$page->getEnabled()) {
             Curry_Core::log('Page is not accessible', Zend_Log::ERR);
             $page = null;
         }
     }
     // Page was not found, attempt to find 404 page
     if (!$page) {
         header("HTTP/1.1 404 Not Found");
         if (Curry_Core::$config->curry->errorPage->notFound) {
             $page = PageQuery::create()->findPk(Curry_Core::$config->curry->errorPage->notFound);
             if (!$page || !$page->getEnabled()) {
                 throw new Exception('Page not found, additionally the page-not-found page could not be found.');
             }
         } else {
             die('Page not found');
         }
     }
     // Set language
     $language = $page->getInheritedProperty('Language');
     $fallbackLanguage = Curry_Core::$config->curry->fallbackLanguage;
     if ($language) {
         $this->setLanguage($language);
     } else {
         if ($fallbackLanguage) {
             trace_warning('Using fallback language');
             $this->setLanguage($fallbackLanguage);
         } else {
             trace_warning('Language not set for page');
         }
     }
     // Attempt to render page
     try {
         $this->render($page->getPageRevision(), $request, $vars, $options);
     } catch (Curry_Exception_Unauthorized $e) {
         Curry_Core::log($e->getMessage(), Zend_Log::ERR);
         if (!headers_sent()) {
             header("HTTP/1.1 " . $e->getStatusCode() . " " . $e->getMessage());
         }
         if (Curry_Core::$config->curry->errorPage->unauthorized) {
             Curry_Core::log('Showing unauthorized page', Zend_Log::NOTICE);
             $page = PageQuery::create()->findPk(Curry_Core::$config->curry->errorPage->unauthorized);
             if (!$page) {
                 throw new Exception('Unauthorized page not found');
             }
             try {
                 $vars = array('curry' => array('error' => array('Message' => $e->getMessage(), 'Trace' => $e->getTraceAsString())));
                 $options = array();
                 $this->render($page->getPageRevision(), $request, $vars, $options);
             } catch (Exception $e2) {
                 Curry_Core::log('An error occured while trying to generate the unauthorized page: ' . $e2->getMessage(), Zend_Log::ERR);
                 throw $e;
             }
         } else {
             throw $e;
         }
     } catch (Curry_Exception_HttpError $e) {
         Curry_Core::log($e->getMessage(), Zend_Log::ERR);
         if (!headers_sent()) {
             header("HTTP/1.1 " . $e->getStatusCode() . " " . $e->getMessage());
         }
     } catch (Exception $e) {
         Curry_Core::log($e->getMessage(), Zend_Log::ERR);
         if (!headers_sent()) {
             header("HTTP/1.1 500 Internal server error");
         }
         if (Curry_Core::$config->curry->errorNotification) {
             Curry_Core::sendErrorNotification($e);
         }
         if (Curry_Core::$config->curry->errorPage->error) {
             Curry_Core::log('Trying to show error page', Zend_Log::NOTICE);
             $page = PageQuery::create()->findPk(Curry_Core::$config->curry->errorPage->error);
             if (!$page) {
                 throw new Exception('Error page not found');
             }
             try {
                 $vars = array('curry' => array('error' => array('Message' => $e->getMessage(), 'Trace' => $e->getTraceAsString())));
                 $options = array();
                 $this->render($page->getPageRevision(), $request, $vars, $options);
             } catch (Exception $e2) {
                 Curry_Core::log('An error occured, additionally an error occured while trying to generate the error page: ' . $e2->getMessage(), Zend_Log::ERR);
                 throw $e;
             }
         } else {
             throw $e;
         }
     }
 }