Improve 404 page performance so it can actually be used

This commit is contained in:
8chan 2014-09-28 02:21:34 +00:00
parent 700f24f179
commit c9a2fe5343

39
404.php
View File

@ -1,33 +1,34 @@
<?php <?php
include "inc/functions.php"; include "inc/functions.php";
include "inc/cache.php";
if(!file_exists("404/")) $dir = "static/404/";
mkdir("404/");
$cache = new Cache; if (!is_dir($dir))
$cache->init(); mkdir($dir);
if($cache->get("404glob") == false){ if ($config['cache']['enabled']) {
$files = glob("404/*.*"); $files = cache::get('notfound_files');
$cache->set("404glob", $files); }
}else
$files = $cache->get("404glob");
if(count($files) == 0) if (!isset($files) or !$files) {
$errorimage = ""; $files = array_diff(scandir($dir), array('..', '.'));
else
if ($config['cache']['enabled']) {
cache::set('notfound_files', $files);
}
}
if (count($files) == 0) {
$errorimage = false;
} else {
$errorimage = $files[array_rand($files)]; $errorimage = $files[array_rand($files)];
}
$page = <<<EOT $page = <<<EOT
<center>
<div class="ban"> <div class="ban">
<h2>404 Not Found</h2> <p style="text-align:center"><img src="/static/404/{$errorimage}" style="width:100%"></p>
<img src="{$errorimage}" style="width: 700px;">
</div> </div>
</center>
EOT; EOT;
echo Element("page.html", array("config" => $config, "body" => $page, "title" => "")); echo Element("page.html", array("config" => $config, "body" => $errorimage ? $page : "", "title" => "404 Not Found"));