|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ErrorPage holds the content for the page of an error response. |
|
4
|
|
|
* Renders the page on each publish action into a static HTML file |
|
5
|
|
|
* within the assets directory, after the naming convention |
|
6
|
|
|
* /assets/error-<statuscode>.html. |
|
7
|
|
|
* This enables us to show errors even if PHP experiences a recoverable error. |
|
8
|
|
|
* ErrorPages |
|
9
|
|
|
* |
|
10
|
|
|
* @see Debug::friendlyError() |
|
11
|
|
|
* |
|
12
|
|
|
* @package cms |
|
13
|
|
|
*/ |
|
14
|
|
|
class PageNotFound extends ErrorPage |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
public static $icon = "mysite/images/treeIcons/PageNotFound"; |
|
17
|
|
|
|
|
18
|
|
|
public static $hide_ancestor = "ErrorPage"; |
|
19
|
|
|
|
|
20
|
|
|
public function doPublish() |
|
21
|
|
|
{ |
|
22
|
|
|
parent::doPublish(); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
/** |
|
26
|
|
|
* Controller for ErrorPages. |
|
27
|
|
|
* @package cms |
|
28
|
|
|
*/ |
|
29
|
|
|
class PageNotFound_Controller extends ErrorPage_Controller |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
private static $old_to_new_array = array(); |
|
32
|
|
|
|
|
33
|
|
|
public static function set_old_to_new_array(array $a) |
|
34
|
|
|
{ |
|
35
|
|
|
self::$old_to_new_array = $a; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function init() |
|
39
|
|
|
{ |
|
40
|
|
|
parent::init(); |
|
41
|
|
|
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
|
|
|
|
|
|
42
|
|
|
$page = null; |
|
|
|
|
|
|
43
|
|
|
//NOTE: this function (Director::urlParam) is depreciated, but should actuall be kept |
|
44
|
|
|
$URLSegment = Director::urlParam("URLSegment"); |
|
|
|
|
|
|
45
|
|
|
$Action = Director::urlParam("Action"); |
|
|
|
|
|
|
46
|
|
|
foreach (self::$old_to_new_array as $oldURL => $newURL) { |
|
47
|
|
|
if ($URLSegment == $oldURL) { |
|
48
|
|
|
$page = DataObject::get_one("SiteTree", "URLSegment = '$newURL'"); |
|
49
|
|
|
Director::redirect($page->Link(), 301); |
|
50
|
|
|
} elseif ($URLSegment."/".$Action == $oldURL) { |
|
51
|
|
|
$page = DataObject::get_one("SiteTree", "URLSegment = '$newURL'"); |
|
52
|
|
|
Director::redirect($page->Link(), 301); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.