1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-25 16:00:22 +01:00
vichan/banners.php
boreq 78f1a99820 Updated banners.py
Removed unnecessary import.
Added a function to avoid duplicating code.
2014-09-24 01:37:23 +02:00

32 lines
786 B
PHP

<?php
header("Pragma-directive: no-cache");
header("Cache-directive: no-cache");
header("Cache-control: no-cache");
header("Pragma: no-cache");
header("Expires: 0");
function get_custom_banner(&$b) {
# Validate the board name
if (!(isset($b) && preg_match('/^[a-z0-9]{1,10}$/', $b)))
return null;
# Check if directory exists
$dir = "static/banners/$b/";
if (!is_dir($dir))
return null;
# Return random file if directory is not empty
$banners = array_diff(scandir($dir), array('..', '.'));
if (!$banners)
return null;
$r = array_rand($banners);
return $dir.$banners[$r];
}
$banner = get_custom_banner($_GET['board']);
if ($banner)
header("Location: $banner");
else
header("Location: static/8chan banner.png");