1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-25 16:00:22 +01:00
vichan/404.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2014-09-25 01:41:23 +02:00
<?php
2014-11-21 13:05:20 +01:00
require_once "inc/functions.php";
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
2014-09-25 01:41:23 +02:00
$dir = "static/404/";
2014-09-25 01:41:23 +02:00
if (!is_dir($dir))
mkdir($dir);
2014-09-26 00:40:43 +02:00
if ($config['cache']['enabled']) {
$files = cache::get('notfound_files');
}
if (!isset($files) or !$files) {
$files = array_diff(scandir($dir), array('..', '.'));
if ($config['cache']['enabled']) {
cache::set('notfound_files', $files);
}
}
if (count($files) == 0) {
$errorimage = false;
} else {
$errorimage = $files[array_rand($files)];
}
2014-09-25 01:41:23 +02:00
$page = <<<EOT
<div class="ban">
<p style="text-align:center"><img src="/static/404/{$errorimage}" style="width:100%"></p>
</div>
2014-09-28 04:39:41 +02:00
<script type="text/javascript">
if (localStorage.favorites) {
var faves = JSON.parse(localStorage.favorites);
$.each(faves, function(k, v) {
if ((window.location.pathname === '/' + v + '/') || (window.location.pathname === '/' + v)) {
2014-09-28 04:39:41 +02:00
faves.pop(v);
localStorage.favorites = JSON.stringify(faves);
2014-09-28 04:47:36 +02:00
alert('As /' + v + '/ no longer exists, it has been removed from your favorites.');
2014-09-28 04:39:41 +02:00
}
})
}
</script>
2014-09-25 01:41:23 +02:00
EOT;
echo Element("page.html", array("config" => $config, "body" => $errorimage ? $page : "", "title" => "404 Not Found"));