f.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. header('Content-Disposition: inline; filename="default_favicon.ico"');
  8. $default_mtime = @filemtime(DEFAULT_FAVICON);
  9. if (!httpConditional($default_mtime, $cacheSeconds, 2)) {
  10. readfile(DEFAULT_FAVICON);
  11. }
  12. }
  13. $id = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '0';
  14. if (!ctype_xdigit($id)) {
  15. $id = '0';
  16. }
  17. $txt = FAVICONS_DIR . $id . '.txt';
  18. $ico = FAVICONS_DIR . $id . '.ico';
  19. $ico_mtime = @filemtime($ico);
  20. $txt_mtime = @filemtime($txt);
  21. header('Content-Type: image/x-icon');
  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. header('Content-Disposition: inline; filename="' . $id . '.ico"');
  40. if (!httpConditional($ico_mtime, mt_rand(14, 21) * 86400, 2)) {
  41. readfile($ico);
  42. }