9 private static $instance;
14 if (!isset(self::$instance))
17 self::$instance =
new $c;
20 return self::$instance;
25 if(array_key_exists(
"max_execution_time",
$params) && intval(
$params[
"max_execution_time"]) > 0)
26 $this->max_execution_time = intval(
$params[
"max_execution_time"]);
31 static::$recalculateDb = $mode;
39 if (static::$recalculateDb && COption::GetOptionInt(
"main",
"disk_space") > 0)
42 SELECT sum(Data_length + Index_length) as TOTAL_LEN
43 FROM information_schema.tables
44 WHERE table_schema = '{$DB->ForSql($DB->DBName)}'
48 $DBSize =
$res[
'TOTAL_LEN'];
51 COption::SetOptionString(
"main_size",
"~db", $DBSize);
53 COption::SetOptionString(
"main_size",
"~db_params", serialize(
$params));
55 static::recalculateDb(
false);
62 return array(
"status" =>
"done",
"size" => $DBSize,
"time" =>
$params[
"time"]);
83 $record =
array(
"size" => COption::GetOptionString(
"main_size",
"~".
$name));
87 if (!is_array($skip_dir))
88 $skip_dir =
array($skip_dir);
89 foreach ($skip_dir as
$key => $path_to_skip_dir)
90 $skip_dir[
$key] = str_replace(
"//",
"/",
$abs_path.$path_to_skip_dir.
"/");
93 if (!empty($record[
"size"]) && !$recount)
95 $record = array_merge(
96 unserialize(COption::GetOptionString(
"main_size",
"~".
$name.
"_params"), [
'allowed_classes' =>
false]),
99 $record[
"path_to_last_file"] = str_replace(
"//",
"/",
$abs_path.$record[
"file"]);
100 if (is_file($record[
"path_to_last_file"]) && $record[
"status"] ==
"c")
103 if (
$res[
"status"] ==
"done" ||
$res[
"status"] ==
"continue")
106 "status" => mb_substr(
$res[
"status"], 0, 1),
107 "file" => str_replace(
$abs_path,
"", str_replace(
"//",
"/",
$res[
"last_file"])),
110 $record[
"size"] = doubleVal($record[
"size"])+doubleVal(
$res[
"size"]);
111 COption::SetOptionString(
"main_size",
"~".
$name, $record[
"size"]);
112 COption::SetOptionString(
"main_size",
"~".
$name.
"_params", serialize($properties));
114 $result[
"size"] = $record[
"size"];
117 elseif ($record[
"status"] ==
"d")
119 return array(
"status" =>
"done",
"last_file" => $record[
"file"],
"size" => $record[
"size"]);
128 if (
$res[
"status"] ==
"done" ||
$res[
"status"] ==
"continue")
131 "status" => mb_substr(
$res[
"status"], 0, 1),
132 "file" => str_replace(
$abs_path,
"", str_replace(
"//",
"/",
$res[
"last_file"])),
135 COption::SetOptionString(
"main_size",
"~".
$name, doubleVal(
$res[
"size"]));
136 COption::SetOptionString(
"main_size",
"~".
$name.
"_params", serialize($properties));
143 return array(
"status" =>
"error");
155 while($file = readdir(
$handle))
157 if($file ==
"." || $file ==
"..")
162 if(is_dir(
$path.$file))
164 if (is_array($skip_dir) && (in_array(str_replace(
"//",
"/",
$path.$file.
"/"), $skip_dir)))
170 $res = array_merge(
$res, $res_rec[
"tree"]);
171 $size += doubleVal($res_rec[
"size"]);
172 if ($res_rec[
"status"] ==
"continue")
174 $res_rec[
"tree"] =
$res;
175 $res_rec[
"size"] = doubleVal($size);
182 $size += filesize(
$path.$file);
183 if ($check_time && intval(microtime(
true) -
START_EXEC_TIME) >= $this->max_execution_time)
185 return array(
"tree" =>
$res,
"status" =>
"continue",
"last_file" =>
$path.$file,
"size" => $size);
193 return array(
"status" =>
"error");
195 return array(
"tree" =>
$res,
"status" =>
"done",
"last_file" =>
$path.$file,
"size" => $size);
201 $path_to_last_file = str_replace(
"//",
"/", $path_to_last_file);
202 $path_to_lf = str_replace(
$path,
"", $path_to_last_file);
206 $path_tree = explode(
"/", $path_to_lf);
207 while ($lf = array_pop($path_tree))
209 $path_to_dir = str_replace(
"//",
"/",
$path.implode(
"/", $path_tree).
"/");
210 $handle = @opendir($path_to_dir);
214 while($file = readdir(
$handle))
216 if($file ==
"." || $file ==
".." || $search)
223 if(is_dir($path_to_dir.$file))
225 if (is_array($skip_dir) && (in_array(str_replace(
"//",
"/",
$path.$file.
"/"), $skip_dir)))
230 $res = array_merge(
$res, $res_rec[
"tree"]);
231 $size += doubleVal($res_rec[
"size"]);
232 if ($res_rec[
"status"] ==
"continue")
234 $res_rec[
"tree"] =
$res;
235 $res_rec[
"size"] = doubleVal($size);
242 $res[] = $path_to_dir.$file;
243 $size += filesize($path_to_dir.$file);
244 if ($check_time && intval(microtime(
true) -
START_EXEC_TIME) >= $this->max_execution_time)
246 return array(
"tree" =>
$res,
"status" =>
"continue",
"last_file" => $path_to_dir.$file,
"size" => $size);
253 return array(
"tree" =>
$res,
"status" =>
"done",
"last_file" =>
$path.$file,
"size" => $size);
258 if ((COption::GetOptionInt(
"main",
"disk_space") <= 0))
261 if ($id !=
"files" && (!is_dir(
$_SERVER[
'DOCUMENT_ROOT'].
"/".$id)))
262 return array(
"status" =>
"error");
282 if (COption::GetOptionInt(
"main",
"disk_space") <= 0)
285 $this->LAST_ERROR =
"";
288 if (COption::GetOptionInt(
"main_size",
"~db") <= 0)
290 static::recalculateDb();
293 $quota = doubleVal(COption::GetOptionInt(
"main",
"disk_space")*1024*1024 -
294 COption::GetOptionInt(
"main_size",
"~db") -
295 COption::GetOptionInt(
"main_size",
"~files"));
302 $this->LAST_ERROR =
GetMessage(
"MAIN_QUOTA_BAD");
303 $arMsg[] =
array(
"id"=>
"QUOTA_BAD",
"text"=>
GetMessage(
"MAIN_QUOTA_BAD"));
306 $GLOBALS[
"APPLICATION"]->ThrowException($e);
313 if (COption::GetOptionInt(
"main",
"disk_space") <= 0)
320 $size = mb_strlen(implode(
"", $size));
321 elseif (doubleval($size) > 0)
322 $size = doubleval($size);
324 $size = mb_strlen($size);
326 $size = doubleval($size);
328 $name = mb_strtolower(
$type) ==
"db" ?
"db" :
"files";
330 if (in_array(mb_strtolower(
$action),
array(
"delete",
"del")))
332 COption::SetOptionString(
"main_size",
"~".
$name,
333 doubleval(COption::GetOptionInt(
"main_size",
"~".
$name) - $size));
336 if (in_array(mb_strtolower(
$action),
array(
"update",
"insert",
"add",
"copy")))
338 COption::SetOptionString(
"main_size",
"~".
$name,
339 doubleval(COption::GetOptionInt(
"main_size",
"~".
$name) + $size));
347 if (COption::GetOptionInt(
"main",
"disk_space") <= 0)
350 if (defined(
"SKIP_DISK_QUOTA_CHECK") && constant(
"SKIP_DISK_QUOTA_CHECK") ===
true)
355 if ($quota ===
true || $quota ===
false)
371 $size = mb_strlen(serialize(
$params));
374 return ((
double)$quota - $size) > 0;
378 if (((
double)$quota - mb_strlen(
$params)) > 0)
static recalculateDb(bool $mode=true)
Recount($id, $recount=false)
GetDirListSimple($path, $check_time=true, $skip_dir=false)
__construct($params=array())
SetDirSize($path="", $name="", $recount=false, $skip_dir=false)
static UpdateDiskQuota($type, $size, $action)
GetDirListFromLastFile($path, $path_to_last_file="", $check_time=true, $skip_dir=false)
CheckDiskQuota($params=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
$GLOBALS['_____370096793']