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