2007-06-04 02:57:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Handle404 extends Extension {
|
|
|
|
public function receive_event($event) {
|
|
|
|
if(is_a($event, 'PageRequestEvent')) {
|
2007-07-17 07:45:35 +00:00
|
|
|
$page = $event->page;
|
2007-06-04 02:57:21 +00:00
|
|
|
// hax.
|
2007-07-16 21:46:41 +00:00
|
|
|
if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
|
2007-07-20 23:25:22 +00:00
|
|
|
$h_pagename = html_escape($event->page_name);
|
2007-06-04 02:57:21 +00:00
|
|
|
header("HTTP/1.0 404 Page Not Found");
|
|
|
|
$page->set_title("404");
|
|
|
|
$page->set_heading("404 - No Handler Found");
|
2007-06-30 01:19:11 +00:00
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Explanation", "No handler could be found for the page '$h_pagename'"));
|
2007-06-04 02:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 21:46:41 +00:00
|
|
|
|
|
|
|
private function count_main($blocks) {
|
|
|
|
$n = 0;
|
|
|
|
foreach($blocks as $block) {
|
|
|
|
if($block->section == "main") $n++; // more hax.
|
|
|
|
}
|
|
|
|
return $n;
|
|
|
|
}
|
2007-06-04 02:57:21 +00:00
|
|
|
}
|
2007-07-16 21:46:41 +00:00
|
|
|
add_event_listener(new Handle404(), 99); // hax++
|
2007-06-04 02:57:21 +00:00
|
|
|
?>
|