speed up a.php
This commit is contained in:
+94
-32
@@ -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
|
||||
'<button type="submit">'.M_REFRESH.'</button>'.
|
||||
' la page.</form>';
|
||||
|
||||
if ($admin) {
|
||||
echo
|
||||
'<form method="post">'.
|
||||
'Mettre à jour le cache jusqu\'à '.
|
||||
'<input type="hidden" name="'.A_SENDER.'" value="'.$sender.'"/>'.
|
||||
'<input type="hidden" name="'.A_TOKEN.'" value="'.$token.'"/>'.
|
||||
'<select name="'.A_ACTION.'" style="width: auto !important;">';
|
||||
foreach ($periodText as $item => $text)
|
||||
echo ' <option value="'.A_CACHE.$item.'">'.$text.'</option>';
|
||||
echo
|
||||
'</select> '.
|
||||
'<button type="submit">'."valider".'</button>'.
|
||||
'.</form><br/>';
|
||||
}
|
||||
|
||||
$userSise = 0;
|
||||
$userTab = [];
|
||||
if ($archives) {
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
<div class="table">
|
||||
<form class="tr" action="<?php echo $_SERVER ['SCRIPT_NAME']; ?>" method="POST">
|
||||
<span class="td"></span>
|
||||
<span class="td"><input name="<?php echo A_NAME;?>" type="text" value="<?php echo $name;?>" placeholder="Mon nuage"/></span>
|
||||
<span class="td"><input name="<?php echo A_NAME;?>" type="text" value="<?php echo $name;?>" placeholder="Nom du nuage"/></span>
|
||||
<span class="td"><input name="<?php echo A_URL;?>" type="text" value="<?php echo $url;?>" placeholder="https://..."/></span>
|
||||
<?php echo getHiddenToken (); ?><?php echo getHiddenLink (); ?>
|
||||
<span class="td"><button class="btn btn-new" onclick="actionUrl (this, false, '<?php echo A_ACTION; ?>', '<?php echo T_ADD_URL; ?>')" ><?php echo L_ADD_URL; ?></button></span>
|
||||
|
||||
Reference in New Issue
Block a user