diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index ed01cec1..200121a1 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -5,22 +5,38 @@ * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Visibility: admin - * Description: Shows an error message when the user views a page with no content + * Description: If Shimmie can't handle a request, check static files; if that fails, show a 404 */ class Handle404 extends Extension { public function onPageRequest(PageRequestEvent $event) { - global $page; + global $config, $page; // hax. if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) { $h_pagename = html_escape(implode('/', $event->args)); - log_debug("handle_404", "Hit 404: $h_pagename"); - - $page->add_http_header("HTTP/1.0 404 Page Not Found",5); - $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'")); + $f_pagename = preg_replace("/[^a-z\.]+/", "_", $h_pagename); + $theme_name = $config->get_string("theme", "default"); + + if(file_exists("themes/$theme_name/$f_pagename")) { + header("Cache-control: public, max-age=600"); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 600) . ' GMT'); + $page->set_mode("data"); + $page->set_data(file_get_contents("themes/$theme_name/$f_pagename")); + } + else if(file_exists("lib/static/$f_pagename")) { + header("Cache-control: public, max-age=600"); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 600) . ' GMT'); + $page->set_mode("data"); + $page->set_data(file_get_contents("lib/static/$f_pagename")); + } + else { + log_debug("handle_404", "Hit 404: $h_pagename"); + $page->add_http_header("HTTP/1.0 404 Page Not Found",5); + $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'")); + } } } diff --git a/lib/static/README.txt b/lib/static/README.txt new file mode 100644 index 00000000..fa7c2e9e --- /dev/null +++ b/lib/static/README.txt @@ -0,0 +1,4 @@ +These files can be overriden by placing files in +themes/$your_theme/filename.foo. For example if +you want your theme "radiance" to have a custom +favicon, place it in themes/radiance/favicon.ico diff --git a/favicon.ico b/lib/static/favicon.ico similarity index 100% rename from favicon.ico rename to lib/static/favicon.ico diff --git a/favicon.png b/lib/static/favicon.png similarity index 100% rename from favicon.png rename to lib/static/favicon.png diff --git a/lib/static/favicon.svg b/lib/static/favicon.svg new file mode 100644 index 00000000..1f32fcbe --- /dev/null +++ b/lib/static/favicon.svg @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/favicon_64.png b/lib/static/favicon_64.png similarity index 100% rename from favicon_64.png rename to lib/static/favicon_64.png diff --git a/lib/static/robots.txt b/lib/static/robots.txt new file mode 100644 index 00000000..9a42a35c --- /dev/null +++ b/lib/static/robots.txt @@ -0,0 +1,8 @@ +User-agent: * +# comment lists change all the time, crawlers should +# index individual image's comments +Disallow: /comment/ +# next and prev are just CPU-heavier ways of getting +# to the same images that the index shows +Disallow: /post/next/ +Disallow: /post/prev/