mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-01-30 08:01:07 -05:00
* Complete PHPStan Level 6 Fix https://github.com/FreshRSS/FreshRSS/issues/4112 And initiate PHPStan Level 7 * PHPStan Level 6 for tests * Use phpstan/phpstan-phpunit * Update to PHPStan version 1.10 * Fix mixed bug * Fix mixed return bug * Fix paginator bug * Fix FreshRSS_UserConfiguration * A couple more Minz_Configuration bug fixes * A few trivial PHPStan Level 7 fixes * A few more simple PHPStan Level 7 * More files passing PHPStan Level 7 Add interface to replace removed class from https://github.com/FreshRSS/FreshRSS/pull/5251 * A few more PHPStan Level 7 preparations * A few last details
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
require(__DIR__ . '/../constants.php');
|
|
require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
|
|
require(LIB_PATH . '/favicons.php');
|
|
require(LIB_PATH . '/http-conditional.php');
|
|
|
|
function show_default_favicon(int $cacheSeconds = 3600): void {
|
|
$default_mtime = @filemtime(DEFAULT_FAVICON) ?: 0;
|
|
if (!httpConditional($default_mtime, $cacheSeconds, 2)) {
|
|
header('Content-Type: image/x-icon');
|
|
header('Content-Disposition: inline; filename="default_favicon.ico"');
|
|
readfile(DEFAULT_FAVICON);
|
|
}
|
|
}
|
|
|
|
$id = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '0';
|
|
if (!ctype_xdigit($id)) {
|
|
$id = '0';
|
|
}
|
|
|
|
$txt = FAVICONS_DIR . $id . '.txt';
|
|
$ico = FAVICONS_DIR . $id . '.ico';
|
|
|
|
$ico_mtime = @filemtime($ico) ?: 0;
|
|
$txt_mtime = @filemtime($txt) ?: 0;
|
|
|
|
if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (mt_rand(15, 20) * 86400))) {
|
|
if ($txt_mtime == false) {
|
|
show_default_favicon(1800);
|
|
exit();
|
|
}
|
|
|
|
// no ico file or we should download a new one.
|
|
$url = file_get_contents($txt);
|
|
if ($url === false) {
|
|
show_default_favicon(1800);
|
|
exit();
|
|
}
|
|
if (!download_favicon($url, $ico)) {
|
|
// Download failed
|
|
if ($ico_mtime == false) {
|
|
show_default_favicon(86400);
|
|
exit();
|
|
} else {
|
|
touch($ico);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!httpConditional($ico_mtime, mt_rand(14, 21) * 86400, 2)) {
|
|
$ico_content_type = 'image/x-icon';
|
|
if (function_exists('mime_content_type')) {
|
|
$ico_content_type = mime_content_type($ico);
|
|
}
|
|
switch ($ico_content_type) {
|
|
case 'image/svg':
|
|
$ico_content_type = 'image/svg+xml';
|
|
break;
|
|
}
|
|
header('Content-Type: ' . $ico_content_type);
|
|
header('Content-Disposition: inline; filename="' . $id . '.ico"');
|
|
readfile($ico);
|
|
}
|