f.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. require(__DIR__ . '/../constants.php');
  3. require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
  4. require(LIB_PATH . '/favicons.php');
  5. require(LIB_PATH . '/http-conditional.php');
  6. function show_default_favicon($cacheSeconds = 3600) {
  7. $default_mtime = @filemtime(DEFAULT_FAVICON);
  8. if (!httpConditional($default_mtime, $cacheSeconds, 2)) {
  9. header('Content-Type: image/x-icon');
  10. header('Content-Disposition: inline; filename="default_favicon.ico"');
  11. readfile(DEFAULT_FAVICON);
  12. }
  13. }
  14. $id = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '0';
  15. if (!ctype_xdigit($id)) {
  16. $id = '0';
  17. }
  18. $txt = FAVICONS_DIR . $id . '.txt';
  19. $ico = FAVICONS_DIR . $id . '.ico';
  20. $ico_mtime = @filemtime($ico);
  21. $txt_mtime = @filemtime($txt);
  22. if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (mt_rand(15, 20) * 86400))) {
  23. if ($txt_mtime == false) {
  24. show_default_favicon(1800);
  25. exit();
  26. }
  27. // no ico file or we should download a new one.
  28. $url = file_get_contents($txt);
  29. if (!download_favicon($url, $ico)) {
  30. // Download failed
  31. if ($ico_mtime == false) {
  32. show_default_favicon(86400);
  33. exit();
  34. } else {
  35. touch($ico);
  36. }
  37. }
  38. }
  39. if (!httpConditional($ico_mtime, mt_rand(14, 21) * 86400, 2)) {
  40. $ico_content_type = 'image/x-icon';
  41. if (function_exists('mime_content_type')) {
  42. $ico_content_type = mime_content_type($ico);
  43. }
  44. switch ($ico_content_type) {
  45. case 'image/svg':
  46. $ico_content_type = 'image/svg+xml';
  47. break;
  48. }
  49. header('Content-Type: ' . $ico_content_type);
  50. header('Content-Disposition: inline; filename="' . $id . '.ico"');
  51. readfile($ico);
  52. }