2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-08-07 14:53:59 -05:00
|
|
|
|
2020-02-23 18:46:27 +00:00
|
|
|
class FourOhFour extends Extension
|
2019-05-28 17:59:38 +01:00
|
|
|
{
|
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
|
|
{
|
2019-10-02 11:23:57 +01:00
|
|
|
global $page;
|
2019-05-28 17:59:38 +01:00
|
|
|
// hax.
|
2019-06-18 20:58:28 -05:00
|
|
|
if ($page->mode == PageMode::PAGE && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
|
2019-05-28 17:59:38 +01:00
|
|
|
$h_pagename = html_escape(implode('/', $event->args));
|
2020-02-23 18:46:27 +00:00
|
|
|
log_debug("four_oh_four", "Hit 404: $h_pagename");
|
2019-05-28 17:59:38 +01:00
|
|
|
$page->set_code(404);
|
|
|
|
$page->set_title("404");
|
|
|
|
$page->set_heading("404 - No Handler Found");
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Explanation", "No handler could be found for the page '$h_pagename'"));
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 21:46:41 +00:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
private function count_main($blocks)
|
|
|
|
{
|
|
|
|
$n = 0;
|
|
|
|
foreach ($blocks as $block) {
|
|
|
|
if ($block->section == "main" && $block->is_content) {
|
|
|
|
$n++;
|
|
|
|
} // more hax.
|
|
|
|
}
|
|
|
|
return $n;
|
|
|
|
}
|
2010-05-28 02:07:33 +01:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
public function get_priority(): int
|
|
|
|
{
|
|
|
|
return 99;
|
|
|
|
}
|
2007-06-04 02:57:21 +00:00
|
|
|
}
|