streams/Code/Module/Xp.php

65 lines
2.1 KiB
PHP
Raw Normal View History

2020-08-25 04:36:56 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2020-08-25 04:36:56 +00:00
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Channel;
use Code\Storage\Stdio;
2020-08-25 04:36:56 +00:00
2021-12-02 23:02:31 +00:00
class Xp extends Controller
{
public function get()
{
if (argc() > 1) {
$path = 'cache/xp/' . substr(argv(1), 0, 2) . '/' . substr(argv(1), 2, 2) . '/' . argv(1);
if (!file_exists($path)) {
// no longer cached for some reason, perhaps expired
$resolution = substr(argv(1), (-2), 2);
2022-08-26 22:37:04 +00:00
if ($resolution && str_starts_with($resolution, '-')) {
2021-12-02 23:02:31 +00:00
switch (substr($resolution, 1, 1)) {
case '4':
2022-01-25 01:26:12 +00:00
$path = Channel::get_default_profile_photo();
2021-12-02 23:02:31 +00:00
break;
case '5':
2022-01-25 01:26:12 +00:00
$path = Channel::get_default_profile_photo(80);
2021-12-02 23:02:31 +00:00
break;
case '6':
2022-01-25 01:26:12 +00:00
$path = Channel::get_default_profile_photo(48);
2021-12-02 23:02:31 +00:00
break;
case '8':
$path = Channel::get_default_cover_photo(850);
break;
2021-12-02 23:02:31 +00:00
default:
break;
}
}
}
if (!file_exists($path)) {
http_status_exit(404, 'Not found');
}
$x = @getimagesize($path);
if ($x) {
header('Content-Type: ' . $x['mime']);
}
$cache = intval(get_config('system', 'photo_cache_time'));
if (!$cache) {
$cache = (3600 * 24); // 1 day
}
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cache) . ' GMT');
// Set browser cache age as $cache. But set timeout of 'shared caches'
// much lower in the event that infrastructure caching is present.
$smaxage = intval($cache / 12);
header('Cache-Control: s-maxage=' . $smaxage . '; max-age=' . $cache . ';');
Stdio::fcopy($path,'php://output');
2021-12-02 23:02:31 +00:00
killme();
}
http_status_exit(404, 'Not found');
}
2020-08-26 01:29:23 +00:00
}