function CheckCacheFiles_Rec($strDir) { global $iGoodNum, $iOldNum, $iEmptyDirNum, $dLog; if ($handle = @opendir($strDir)) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") continue; if (is_dir($strDir."/".$file)) { CheckCacheFiles_Rec($strDir."/".$file); } elseif (is_file($strDir."/".$file)) { $ext = ""; $ext_pos = bxstrrpos($file, "."); if ($ext_pos!==false) $ext = substr($file, $ext_pos + 1); $bCacheExp = False; if ($ext=="html") $bCacheExp = CPageCache::IsCacheExpired($strDir."/".$file); elseif ($ext=="php") $bCacheExp = CPHPCache::IsCacheExpired($strDir."/".$file); if ($bCacheExp) { $iOldNum++; @unlink($strDir."/".$file); } else { $iGoodNum++; } } } @closedir($handle); } clearstatcache(); $bEmptyFolder = True; if ($handle = @opendir($strDir)) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") continue; $bEmptyFolder = False; break; } } if ($bEmptyFolder) { $iEmptyDirNum++; @rmdir($strDir); } }
function BXClearCache($full = false, $initdir = "") { if ($full !== true && $full !== false && $initdir === "" && is_string($full)) { $initdir = $full; $full = true; } $res = true; if ($full === true) { $obCache = new CPHPCache(); $obCache->CleanDir($initdir, "cache"); } $path = $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/cache" . $initdir; if (is_dir($path) && ($handle = opendir($path))) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") { continue; } if (is_dir($path . "/" . $file)) { if (!BXClearCache($full, $initdir . "/" . $file)) { $res = false; } else { @chmod($path . "/" . $file, BX_DIR_PERMISSIONS); //We suppress error handle here because there may be valid cache files in this dir @rmdir($path . "/" . $file); } } elseif ($full) { @chmod($path . "/" . $file, BX_FILE_PERMISSIONS); if (!unlink($path . "/" . $file)) { $res = false; } } elseif (substr($file, -5) == ".html") { if (CPageCache::IsCacheExpired($path . "/" . $file)) { @chmod($path . "/" . $file, BX_FILE_PERMISSIONS); if (!unlink($path . "/" . $file)) { $res = false; } } } elseif (substr($file, -4) == ".php") { if (CPHPCache::IsCacheExpired($path . "/" . $file)) { @chmod($path . "/" . $file, BX_FILE_PERMISSIONS); if (!unlink($path . "/" . $file)) { $res = false; } } } else { //We should skip unknown file //it will be deleted with full cache cleanup } } closedir($handle); } return $res; }