protected function deleteOneDir($etime = 0) { $bDeleteFromQueue = false; $con = Main\Application::getConnection(); $rs = $con->query("SELECT SITE_ID, CACHE_SALT, RELATIVE_PATH, TAG from b_cache_tag WHERE TAG='*'", 0, 1); if ($ar = $rs->fetch()) { $dirName = Main\Loader::getDocumentRoot() . $ar["RELATIVE_PATH"]; if ($ar["RELATIVE_PATH"] != '' && file_exists($dirName)) { $dh = opendir($dirName); if (is_resource($dh)) { $counter = 0; while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { DeleteDirFilesEx($ar["RELATIVE_PATH"] . "/" . $file); $counter++; if (time() > $etime) { break; } } } closedir($dh); if ($counter == 0) { rmdir($dirName); $bDeleteFromQueue = true; } } } else { $bDeleteFromQueue = true; } if ($bDeleteFromQueue) { $con->queryExecute("DELETE FROM b_cache_tag\n\t\t\t\t\tWHERE SITE_ID = '" . $con->getSqlHelper()->forSql($ar["SITE_ID"]) . "'\n\t\t\t\t\tAND CACHE_SALT = '" . $con->getSqlHelper()->forSql($ar["CACHE_SALT"]) . "'\n\t\t\t\t\tAND RELATIVE_PATH = '" . $con->getSqlHelper()->forSql($ar["RELATIVE_PATH"]) . "'"); } } }
/** * Returns server document root. * * @return null|string */ public static function getDocumentRoot() { static $documentRoot = null; if ($documentRoot != null) { return $documentRoot; } $context = Application::getInstance()->getContext(); if ($context != null) { $server = $context->getServer(); if ($server != null) { return $documentRoot = $server->getDocumentRoot(); } } return Loader::getDocumentRoot(); }
private function getPath($path) { $path = Main\Loader::getDocumentRoot() . $path; return preg_replace("'[\\\\/]+'", "/", $path); }