2007-06-04 02:57:21 +00:00
|
|
|
<?php
|
2010-01-05 10:11:53 +00:00
|
|
|
/**
|
|
|
|
* Name: 404 Detector
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* Link: http://code.shishnet.org/shimmie2/
|
|
|
|
* License: GPLv2
|
2010-01-05 13:13:11 +00:00
|
|
|
* Visibility: admin
|
2018-11-11 17:38:32 +00:00
|
|
|
* Description: If no other extension puts anything onto the page, show 404
|
2010-01-05 10:11:53 +00:00
|
|
|
*/
|
2007-06-04 02:57:21 +00:00
|
|
|
|
2012-02-08 12:07:01 +00:00
|
|
|
class Handle404 extends Extension {
|
2010-05-28 02:07:33 +01:00
|
|
|
public function onPageRequest(PageRequestEvent $event) {
|
2012-02-22 09:54:49 +00:00
|
|
|
global $config, $page;
|
2010-05-28 02:07:33 +01:00
|
|
|
// hax.
|
|
|
|
if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
|
|
|
|
$h_pagename = html_escape(implode('/', $event->args));
|
2018-11-11 17:38:32 +00:00
|
|
|
log_debug("handle_404", "Hit 404: $h_pagename");
|
|
|
|
$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-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) {
|
2017-08-24 10:17:24 +01:00
|
|
|
if($block->section == "main" && $block->is_content) $n++; // more hax.
|
2015-08-09 13:39:48 +01:00
|
|
|
}
|
2007-07-16 21:46:41 +00:00
|
|
|
return $n;
|
|
|
|
}
|
2010-05-28 02:07:33 +01:00
|
|
|
|
2017-09-19 18:55:43 +01:00
|
|
|
public function get_priority(): int {return 99;}
|
2007-06-04 02:57:21 +00:00
|
|
|
}
|
2014-04-25 22:54:51 -04:00
|
|
|
|