Source of file UniversalErrorPage.php
Size: 2,754 Bytes - Last Modified: 2021-12-23T10:03:08+00:00
/var/www/docs.ssmods.com/process/src/code/pages/UniversalErrorPage.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | <?php class UniversalErrorPage extends ErrorPage { private static $description = 'Use a shared HTML or PHP file on the server to display the error'; public function requireDefaultRecords() { if (Config::inst()->get('UniversalErrorPage', 'ConvertOnDevBuild')) { $ErrorPages = ErrorPage::get()->filter('ClassName','ErrorPage'); foreach ($ErrorPages as $ErrorPage) { $ErrorPage->ClassName = 'UniversalErrorPage'; $ErrorPage->write(); $ErrorPage->doPublish(); DB::alteration_message("#$ErrorPage->ID $ErrorPage->Title changed to UniversalErrorPage.", "changed"); } } } /** * Stop the static html file being created in assets * TODO: This does not prevent /dev/build from creating them... */ public function writeStaticPage() { return true; } } /** * Controller for UniversalErrorPage. * * @package cms */ class UniversalErrorPage_Controller extends ErrorPage_Controller { private $defaultErrorPagePath = '/var/www/error_pages/'; 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); } } |