forked from loic-fontaine-msr/habitv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
last.php
62 lines (53 loc) · 1.99 KB
/
last.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
55
56
57
58
59
60
61
62
<?php
$directory="repository/com/dabi/habitv/habiTv";
$autoriseSnapshot=true;
function startsWith($haystack, $needle)
{
return $needle === "" || strpos($haystack, $needle) === 0;
}
function endsWith($haystack, $needle)
{
return $needle === "" || substr($haystack, -strlen($needle)) === $needle;
}
function checkPath($path)
{
return $_GET['snapshot']=="true" || strpos($path,'SNAPSHOT') == false;
}
function checkFile($path)
{
return strpos($path,"habiTv") !== false && endsWith($path,".jar");
}
function lastModifiedInFolder($folderPath) {
/* First we set up the iterator */
$iterator = new RecursiveDirectoryIterator($folderPath);
$directoryIterator = new RecursiveIteratorIterator($iterator);
/* Sets a var to receive the last modified filename */
$lastModifiedFile = "";
/* Then we walk through all the files inside all folders in the base folder */
foreach ($directoryIterator as $name => $object) {
//echo $lastModifiedFile;
/* In the first iteration, we set the $lastModified */
if (empty($lastModifiedFile) && checkFile($name) && checkPath($name)) {
$lastModifiedFile = $name;
}
else {
$dateModifiedCandidate = filemtime($lastModifiedFile);
$dateModifiedCurrent = filemtime($name);
/* If the file we thought to be the last modified
was modified before the current one, then we set it to the current */
if ($dateModifiedCandidate < $dateModifiedCurrent && checkFile($name) && checkPath($name)) {
$lastModifiedFile = $name;
}
}
}
/* If the $lastModifiedFile isn't set, there were no files
we throw an exception */
if (empty($lastModifiedFile)) {
//throw new Exception("No files in the directory");
}
return $lastModifiedFile;
}
//echo lastModifiedInFolder($directory);
header("Location: ".lastModifiedInFolder($directory));
die();
?>