diff --git a/src/Jirafeau/a.php b/src/Jirafeau/a.php index 65c40e1..2b113c0 100644 --- a/src/Jirafeau/a.php +++ b/src/Jirafeau/a.php @@ -230,12 +230,80 @@ function isKazArchive ($link) { jirafeau_escape ($link ['mime_type']) == T_ARCHIVE_MIME; } +// ======================================== +function getArchiveCacheLastUpdate () { + if (file_exists (FILE_LAST_CACHE)) + return intval (trim (file (FILE_LAST_CACHE)[0])); + return 0; +} +function setArchiveCacheLastUpdate ($time) { + if (!file_exists (VAR_CACHE)) + mkdir (VAR_CACHE, 0755); + file_put_contents (FILE_LAST_CACHE, $time.NL); +} +function getArchiveCacheFromSender ($sender) { + $archives = []; + if (!file_exists (VAR_CACHE.$sender)) + return $archives; + $dir = scandir (VAR_CACHE.$sender); + foreach ($dir as $hash) { + $p = s2p ($hash); + $lines = file (VAR_FILES . $p . $hash); + if (!$lines) + continue; + $archives [] = readArchiveFromLines ($lines); + } + return $archives; +} + +function updateArchiveCacheUpTo ($period) { + if (!file_exists (VAR_CACHE)) + mkdir (VAR_CACHE, 0755); + $minTime = getArchiveCacheLastUpdate (); + $maxTime = time ()-period2seconds ($period); + + $stack = array (VAR_LINKS); + while ( ($d = array_shift ($stack)) && $d != null) { + $dir = scandir ($d); + foreach ($dir as $dirName) { + if (strcmp ($dirName, '.') == 0 || strcmp ($dirName, '..') == 0 || + preg_match ('/\.tmp/i', "$dirName")) { + continue; + } + if (is_dir ($d . $dirName)) { + // Push new found directory. + $stack [] = $d . $dirName . '/'; + continue; + } + $time = filemtime ($d . $dirName); + if ($time < $minTime || $time >= $maxTime) + continue; + // Read link informations. + $l = jirafeau_get_link ($dirName); + if (!count ($l)) + continue; + if (!isKazArchive ($l)) + continue; + $archiveInfo = readArchiveFromLink ($l); + if (!$archiveInfo [T_SENDER]) + continue; + if (!file_exists (VAR_CACHE.$archiveInfo [T_SENDER])) + mkdir (VAR_CACHE.$archiveInfo [T_SENDER], 0755); + touch (VAR_CACHE.$archiveInfo [T_SENDER]."/".$l ['hash']); + } + } + setArchiveCacheLastUpdate ($maxTime); +} + // ======================================== function readArchiveFromLink ($link) { $p = s2p ($link ['hash']); $lines = file (VAR_FILES . $p . $link ['hash']); - $archive = readArchiveFromLines ($lines); - return $archive; + if ($lines) + return readArchiveFromLines ($lines); + global $message; + $message .= "can't read {$linkName}".NL; + return []; } function readArchiveFromLines ($lines) { $archive = []; @@ -383,6 +451,8 @@ function deleteAction ($linkName) { $fileName = $linkName; $fileLink = $link; $fileTime = $fileLink ['upload_date']; + + // XXX $stack = array (VAR_LINKS); while (($d = array_shift ($stack)) && $d != null) { if (!file_exists ($d)) @@ -711,40 +781,17 @@ if (isset ($_REQUEST [A_ACTION])) { setSenderLang ($sender, $matches [1]); $message .= "Votre lang à été mise à jour."; break; + + case preg_match ("/^".A_CACHE."(".implode ("|", array_keys ($periodText)).")$/i", $_REQUEST [A_ACTION], $matches): + updateArchiveCacheUpTo ($matches [1]); + $message .= "Cache mise à jour {$matches [1]}."; + break; } } // list -$archives = []; -$stack = array (VAR_LINKS); -while ( ($d = array_shift ($stack)) && $d != null) { - $dir = scandir ($d); - foreach ($dir as $dirName) { - if (strcmp ($dirName, '.') == 0 || strcmp ($dirName, '..') == 0 || - preg_match ('/\.tmp/i', "$dirName")) { - continue; - } - if (is_dir ($d . $dirName)) { - /* Push new found directory. */ - $stack [] = $d . $dirName . '/'; - continue; - } - /* Read link informations. */ - $l = jirafeau_get_link ($dirName); - if (!count ($l)) - continue; - if (!isKazArchive ($l)) - continue; - $archiveInfo = readArchiveFromLink ($l); - if ($sender != $archiveInfo [T_SENDER]) - continue; - $archiveInfo ['link'] = $dirName; - $archiveInfo ['key'] = $l ['key']; - $archiveInfo ['maxtime'] = $l ['time']; - $archiveInfo ['hash'] = $l ['hash']; - $archives [] = $archiveInfo; - } -} +$archives = getArchiveCacheFromSender ($sender); + displayHeadPage ("Gestion des pièces jointes"); echo str_replace (["___SENDER___", "___ADMIN___", "___DATE___"], [$sender, ($admin ? " (admin)" : ""), jirafeau_get_datetimefield (time ())], @@ -853,6 +900,21 @@ echo ''. ' la page.'; +if ($admin) { + echo + '
'. + 'Mettre à jour le cache jusqu\'à '. + ''. + ''. + ' '. + ''. + '.

'; +} + $userSise = 0; $userTab = []; if ($archives) { diff --git a/src/Jirafeau/lib/template/page.php b/src/Jirafeau/lib/template/page.php index ff177f9..a8a5757 100644 --- a/src/Jirafeau/lib/template/page.php +++ b/src/Jirafeau/lib/template/page.php @@ -115,7 +115,7 @@
- +