latest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. $v = isset($_REQUEST['v']) ? intval($_REQUEST['v']) : 0;
  3. $ext_regex = ( isset($_REQUEST['format']) && ($_REQUEST['format'] == 'zip') ) ? '\.zip' : '\.tar\.gz';
  4. $ext_regex = ( isset($_REQUEST['format']) && ($_REQUEST['format'] == 'iar') ) ? '\.iar' : $ext_regex;
  5. $filename = 'sloodle';
  6. if ($ext_regex == '\.iar') {
  7. $filename = 'sloodle_rezzer';
  8. }
  9. $fh = opendir('.');
  10. $highest_major = 0;
  11. $highest_minor = 0;
  12. $highest_point = 0;
  13. $highest_filename = '';
  14. while (false !== ($entry = readdir($fh))) {
  15. if (preg_match('/^'.$filename.'_v(\d+)\.(\d+)\.(\d+).*?'.$ext_regex.'$/', $entry, $matches) ) {
  16. $major = $matches[1];
  17. $minor = $matches[2];
  18. $point = $matches[3];
  19. $highest = false;
  20. if ( ($v > 0) && ($major != $v) ) {
  21. continue;
  22. }
  23. if ($major > $highest_major) {
  24. $highest = true;
  25. } else if ( ($major == $highest_major) && ($minor > $highest_minor) ) {
  26. $highest = true;
  27. } else if ( ($major == $highest_major) && ($minor == $highest_minor) && ($point > $highest_point) ) {
  28. $highest = true;
  29. }
  30. if ($highest) {
  31. $highest_major = $major;
  32. $highest_minor = $minor;
  33. $highest_point = $point;
  34. $highest_filename = $entry;
  35. }
  36. }
  37. }
  38. if ($highest_filename != '') {
  39. header('Location: '.$highest_filename);
  40. exit;
  41. }
  42. header('HTTP/1.0 404 Not Found');
  43. print "File not found.";
  44. exit;
  45. ?>