f.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require('../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. global $default_favicon;
  8. header('Content-Disposition: inline; filename="default_favicon.ico"');
  9. $default_mtime = @filemtime($default_favicon);
  10. if (!httpConditional($default_mtime, $cacheSeconds, 2)) {
  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. header('Content-Type: image/x-icon');
  23. if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (rand(15, 20) * 86400))) {
  24. if ($txt_mtime == false) {
  25. show_default_favicon(1800);
  26. exit();
  27. }
  28. // no ico file or we should download a new one.
  29. $url = file_get_contents($txt);
  30. if (!download_favicon($url, $ico)) {
  31. // Download failed
  32. if ($ico_mtime == false) {
  33. show_default_favicon(86400);
  34. exit();
  35. } else {
  36. touch($ico);
  37. }
  38. }
  39. }
  40. header('Content-Disposition: inline; filename="' . $id . '.ico"');
  41. if (!httpConditional($ico_mtime, rand(14, 21) * 86400, 2)) {
  42. readfile($ico);
  43. }