ENHANCEMENT Making ErrorPage static HTML files translatable (#2233)

ENHANCEMENT Added ErrorPage::$static_filepath to flexibly set location of static error pages (defaults to /assets)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@70326 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-01-19 01:25:23 +00:00
parent 56cb10e1c5
commit 7057b56b2c
2 changed files with 41 additions and 2 deletions

View File

@ -22,6 +22,8 @@ class ErrorPage extends Page {
"ShowInSearch" => 0
);
protected static $static_filepath = ASSETS_PATH;
/**
* Ensures that there is always a 404 page
* by checking if there's an instance of
@ -105,7 +107,10 @@ class ErrorPage extends Page {
mkdir(ASSETS_PATH, 02775);
}
if($fh = fopen(ASSETS_PATH . "/error-$this->ErrorCode.html", "w")) {
// if the page is published in a language other than default language,
// write a specific language version of the HTML page
$filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Lang);
if($fh = fopen($filePath, "w")) {
fwrite($fh, $errorContent);
fclose($fh);
}
@ -122,6 +127,39 @@ class ErrorPage extends Page {
return $labels;
}
/**
* Returns an absolute filesystem path to a static error file
* which is generated through {@link publish()}.
*
* @param int $statusCode A HTTP Statuscode, mostly 404 or 500
* @param String $lang A language code in short locale format, e.g. 'de' (Optional)
* @return String
*/
static function get_filepath_for_errorcode($statusCode, $lang = null) {
if(Translatable::is_enabled() && $lang && $lang != Translatable::default_lang()) {
return self::$static_filepath . "/error-{$statusCode}-{$lang}.html";
} else {
return self::$static_filepath . "/error-{$statusCode}.html";
}
}
/**
* Set the path where static error files are saved through {@link publish()}.
* Defaults to /assets.
*
* @param string $path
*/
static function set_static_filepath($path) {
self::$static_filepath = $path;
}
/**
* @return string
*/
static function get_static_filepath($path) {
return self::$static_filepath;
}
}
/**

View File

@ -255,7 +255,8 @@ class Debug {
if(Director::is_ajax()) {
echo $friendlyErrorMessage;
} else {
if(file_exists(ASSETS_PATH . "/error-$statusCode.html")) {
$errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::current_lang());
if(file_exists($errorfilePath)) {
echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html");
} else {
$renderer = new DebugView();