23 lines
638 B
PHP
23 lines
638 B
PHP
<?php
|
|
// Serves an 88x31 button from the local cache (see inc/buttons.php).
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
$h = $_GET['h'] ?? '';
|
|
$file = DATA_DIR . '/buttons/' . $h;
|
|
if (!preg_match('/^[0-9a-f]{32}$/', $h) || !is_file($file)) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
$raw = (string) file_get_contents($file);
|
|
$nl = strpos($raw, "\n");
|
|
$type = $nl !== false ? substr($raw, 0, $nl) : '';
|
|
if (!preg_match('#^image/[\w.+-]+$#', $type)) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
header('Content-Type: ' . $type);
|
|
header('Cache-Control: public, max-age=31536000, immutable'); // URL carries ?v=<mtime>
|
|
echo substr($raw, $nl + 1);
|