Exemple #1
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  * @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
  * @param string $toStage Place to copy to. Must be a stage name.
  * @param boolean $createNewVersion Set this to true to create a new version number.  By default, the existing version number will be copied over.
  */
 function publish($fromStage, $toStage, $createNewVersion = false)
 {
     // Temporarily log out when producing this page
     $loggedInMember = Member::currentUser();
     Session::clear("loggedInAs");
     $alc_enc = isset($_COOKIE['alc_enc']) ? $_COOKIE['alc_enc'] : null;
     Cookie::set('alc_enc', null);
     $oldStage = Versioned::current_stage();
     // Run the page
     Requirements::clear();
     $controller = new ErrorPage_Controller($this);
     $errorContent = $controller->run(array())->getBody();
     if (!file_exists("../assets")) {
         mkdir("../assets", 02775);
     }
     if ($fh = fopen("../assets/error-{$this->ErrorCode}.html", "w")) {
         fwrite($fh, $errorContent);
         fclose($fh);
     }
     // Restore the version we're currently connected to.
     Versioned::reading_stage($oldStage);
     // Log back in
     if ($loggedInMember) {
         Session::set("loggedInAs", $loggedInMember->ID);
     }
     if (isset($alc_enc)) {
         Cookie::set('alc_enc', $alc_enc);
     }
     return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
 }
 public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL)
 {
     $body = null;
     $lang = i18n::get_locale();
     $path = Config::inst()->get('UniversalErrorPage', 'DefaultPath');
     if (!$path) {
         $path = $this->defaultErrorPagePath;
     }
     $forCode = Config::inst()->get('UniversalErrorPage', $this->ErrorCode);
     $localeForCode = preg_replace('/\\.([a-z]+)$/i', '-' . $lang . '.$1', $forCode);
     $errorPages = array($localeForCode, $forCode, $path . "error-{$this->ErrorCode}-{$lang}.html", $path . "error-{$this->ErrorCode}-{$lang}.php", $path . "error-{$lang}.html", $path . "error-{$lang}.php", $path . 'error.html', $path . 'error.php');
     $this->extend('updateHandleRequest', $errorPages);
     // now check if any of the pages exist
     foreach ($errorPages as $errorPage) {
         if (!$body && file_exists($errorPage)) {
             $ext = pathinfo($errorPage, PATHINFO_EXTENSION);
             if ($ext == 'php') {
                 ob_start();
                 include $errorPage;
                 $body = ob_get_clean();
             } else {
                 $body = file_get_contents($errorPage);
             }
             break;
         }
     }
     if ($body) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($this->ErrorCode);
         $response->setBody($body);
         return $response;
     }
     return parent::handleRequest($request, $model);
 }
 function init()
 {
     parent::init();
     $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
     $page = null;
     //NOTE: this function (Director::urlParam) is depreciated, but should actuall be kept
     $URLSegment = Director::urlParam("URLSegment");
     $Action = Director::urlParam("Action");
     foreach (self::$old_to_new_array as $oldURL => $newURL) {
         if ($URLSegment == $oldURL) {
             $page = DataObject::get_one("SiteTree", "URLSegment = '{$newURL}'");
             Director::redirect($page->Link(), 301);
         } elseif ($URLSegment . "/" . $Action == $oldURL) {
             $page = DataObject::get_one("SiteTree", "URLSegment = '{$newURL}'");
             Director::redirect($page->Link(), 301);
         }
     }
 }
 public function init()
 {
     parent::init();
 }