move static files into lib/static, and allow different themes to override them

This commit is contained in:
Shish 2012-02-22 09:54:49 +00:00
parent 6110be6af9
commit 5e8560facb
7 changed files with 103 additions and 9 deletions

View File

@ -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'"));
}
}
}

4
lib/static/README.txt Normal file
View File

@ -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

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

66
lib/static/favicon.svg Normal file
View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
width="16"
height="16"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient3780">
<stop
id="stop3782"
style="stop-color:#646464;stop-opacity:1"
offset="0" />
<stop
id="stop3784"
style="stop-color:#969696;stop-opacity:1"
offset="1" />
</linearGradient>
<linearGradient
x1="7.5"
y1="13.5"
x2="6.5"
y2="1.5"
id="linearGradient3786"
xlink:href="#linearGradient3780"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(0.5,1036.8622)" />
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-1036.3622)"
id="layer1">
<path
d="m 1.5,1050.8622 0,-10 3,-3 10,0 0,10 -3,3 z"
id="path2998"
style="fill:url(#linearGradient3786);fill-opacity:1;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="m 1.5,1040.8622 10,0 0,10"
id="path3000"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="m 11.5,1040.8622 3,-3"
id="path3002"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

8
lib/static/robots.txt Normal file
View File

@ -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/