'HandleCleanUp', 'cleanup2'=>'HandleCleanUp')); SDVA($HandleAuth, array('cleanup' => 'admin', 'cleanup2' => 'admin')); SDVA($CleanUpDirs, array( 'uploads' => 0, 'wiki.d' => 0, )); SDV($CleanUpKeepDays, 30); function HandleCleanUp($pagename, $auth="admin") { global $CleanUpDirs, $CleanUpKeepDays, $CleanUpKeepTime, $Now, $action, $HTMLStartFmt, $HTMLEndFmt, $PageCacheDir, $PageListCacheDir; # ask for admin password if needed $page = RetrieveAuthPage($pagename,$auth,true,READPAGE_CURRENT); if(!$page) exit(); $CleanUpKeepTime = ($CleanUpKeepDays>0)? $Now-$CleanUpKeepDays*86400 : false; PrintFmt($pagename,$HTMLStartFmt); $preview = $wouldbe = ""; if($action == 'cleanup') { $preview = "PREVIEW"; $wouldbe = "would be"; } echo "

CleanUp $preview

\n"; $all = 0; foreach($CleanUpDirs as $dir=>$enabled) { if(! $enabled) continue; list($cnt, $html) = CleanUpDir($dir); if(!$cnt) continue; $all += $cnt; echo $html; @flush(); } if(!$all) { echo "No files to clean up. Great!"; } else echo $action == 'cleanup2' ? "Finished ($all deleted files)." : FmtPageName("Click here to proceed with actual deleting of the $all above files.", $pagename); PrintFmt($pagename,$HTMLEndFmt); } function CleanUpDir($dir) { $fp = @opendir($dir); if (!$fp) { return; } global $CleanUpKeepTime, $LastModTime, $action; $cnt = 0; $html = "
$dir:
\n"; while ( ($file = readdir($fp)) !== false) { if ($file[0] == '.') continue; if (is_dir("$dir/$file")) { list($n, $h) = CleanUpDir("$dir/$file"); $cnt += $n; $html .= $h; continue; } if ($LastModTime && substr($file, -6) == ',cache') { if(@filemtime("$dir/$file") >= $LastModTime) continue; } elseif (preg_match('/,(del-)?(\\d+)$/', $file, $m)) { if ($CleanUpKeepTime && (int)$m[2]>$CleanUpKeepTime) continue; } else continue; $cnt++; if ($action == 'cleanup') { $html .= "$file would be deleted.
\n"; } elseif ( @unlink("$dir/$file") ) { $html .= "$file deleted.
\n"; } else $html .= "**** $file NOT deleted (unlink failed).
\n"; } closedir($fp); if(!$cnt) return array(0, ''); $wouldbe = ($action == 'cleanup') ? "would be" : ""; $html .= "
$cnt files $wouldbe deleted.
"; return array($cnt, $html); }