The version of vichan running on lainchan.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

48 lignes
1.3KB

  1. <?php
  2. // This script assumes there is at least one normal (non-priority)
  3. // banner!
  4. // Get the files in a directory, returns null if the directory does
  5. // not exist.
  6. function getFilesInDirectory($dir) {
  7. if (! is_dir($dir)) {
  8. return null;
  9. }
  10. return array_diff(scandir($dir), array('.', '..'));
  11. }
  12. // Serve a random banner and exit.
  13. function serveRandomBanner($dir, $files) {
  14. $name = $files[array_rand($files)];
  15. // snags the extension
  16. $ext = pathinfo($name, PATHINFO_EXTENSION);
  17. // send the right headers
  18. header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1
  19. header('Pragma: no-cache'); // HTTP 1.0
  20. header('Expires: 0'); // Proxies
  21. header("Content-type: image/" . $ext);
  22. header("Content-Disposition: inline; filename=" . $name);
  23. // readfile displays the image, passthru seems to spits stream.
  24. readfile($dir.$name);
  25. exit;
  26. }
  27. // Get all the banners
  28. $bannerDir = "banners/";
  29. $priorityDir = "banners_priority/";
  30. $banners = getFilesInDirectory($bannerDir);
  31. $priority = getFilesInDirectory($priorityDir);
  32. // If there are priority banners, serve 1/3rd of the time.
  33. if($priority !== null && count($priority) !== 0 && rand(0,2) === 0) {
  34. serveRandomBanner($priorityDir, $priority);
  35. }
  36. serveRandomBanner($bannerDir, $banners);
  37. ?>