2namespace Bitrix\Main\Composite;
14 private static $options =
array();
15 private static $isAjaxRequest =
null;
16 private static $ajaxRandom =
null;
24 if (self::isSpaMode())
26 return ($options[
"SPA_REQUEST_URI"] ??
"/");
30 return (
$_SERVER[
"REQUEST_URI"] ??
'');
43 return preg_replace(
"/:(80|443)$/",
"",
$host ===
null ? (
$_SERVER[
"HTTP_HOST"] ??
'') :
$host);
54 if (isset($options[
"DOMAINS"]) && is_array($options[
"DOMAINS"]))
56 $domains = array_values($options[
"DOMAINS"]);
59 return array_map(
array(__CLASS__,
"getHttpHost"), $domains);
67 if (isset($options[
"SPA_MAP"]) && is_array($options[
"SPA_MAP"]))
69 foreach ($options[
"SPA_MAP"] as $mask => $postfix)
84 if (isset($options[
"SPA_MAP"]) && is_array($options[
"SPA_MAP"]))
86 return array_values($options[
"SPA_MAP"]);
94 if (self::isSpaMode())
97 if ($postfix !==
null)
99 $privateKey .= $postfix;
109 if (isset($options[
"COOKIE_PK"]) && array_key_exists($options[
"COOKIE_PK"], $_COOKIE))
111 return $_COOKIE[$options[
"COOKIE_PK"]];
120 if (isset($options[
"COOKIE_PK"]) && $options[
"COOKIE_PK"] <>
'')
122 setcookie($options[
"COOKIE_PK"], $prefix, $expire,
"/",
false,
false,
true);
129 if (isset($options[
"COOKIE_PK"]) && $options[
"COOKIE_PK"] <>
'')
131 setcookie($options[
"COOKIE_PK"],
"", 0,
"/");
142 if (self::$isAjaxRequest ===
null)
144 self::$isAjaxRequest =
145 (isset(
$_SERVER[
"HTTP_BX_ACTION_TYPE"]) &&
$_SERVER[
"HTTP_BX_ACTION_TYPE"] ===
"get_dynamic") ||
146 (defined(
"actionType") && constant(
"actionType") ===
"get_dynamic");
149 return self::$isAjaxRequest;
155 (isset(
$_SERVER[
"HTTP_BX_CACHE_MODE"]) &&
$_SERVER[
"HTTP_BX_CACHE_MODE"] ===
"APPCACHE") ||
156 (defined(
"CACHE_MODE") && constant(
"CACHE_MODE") ===
"APPCACHE");
162 (isset(
$_SERVER[
"HTTP_BX_CACHE_MODE"]) &&
$_SERVER[
"HTTP_BX_CACHE_MODE"] ===
"HTMLCACHE") ||
163 (defined(
"CACHE_MODE") && constant(
"CACHE_MODE") ===
"HTMLCACHE");
175 foreach ($folders as $folder)
177 $folder = rtrim($folder,
"/").
"/";
178 if (strncmp(
$requestUri, $folder, mb_strlen($folder)) == 0)
191 return isset($options[
"SPA_MODE"]) && $options[
"SPA_MODE"] ===
"Y";
204 if (function_exists(
"gzdecode"))
225 if (self::$ajaxRandom ===
null)
230 return self::$ajaxRandom;
240 if (!array_key_exists(
"bxrand", $_GET) || !preg_match(
"/^[0-9]+$/", $_GET[
"bxrand"]))
245 self::$ajaxRandom = $_GET[
"bxrand"];
247 unset($_GET[
"bxrand"]);
252 $_SERVER[
"REQUEST_URI"] = preg_replace(
253 "/((?<=\\?)bxrand=\\d+&?|&bxrand=\\d+\$)/",
260 if (isset(
$_SERVER[
"QUERY_STRING"]))
262 $_SERVER[
"QUERY_STRING"] = preg_replace(
"/[?&]?bxrand=[0-9]+/",
"",
$_SERVER[
"QUERY_STRING"]);
264 if (isset(
$GLOBALS[
"QUERY_STRING"]))
270 return self::$ajaxRandom;
290 $parts = explode(
"?",
$uri, 2);
292 $uriPath = $parts[0];
293 $uriPath = preg_replace(
"~/index\\.(php|html)$~i",
"", $uriPath);
294 $uriPath = rtrim(str_replace(
"..",
"__", $uriPath),
"/");
295 $uriPath .=
"/index";
298 $queryString = str_replace(
".",
"_", $queryString);
304 $host = preg_replace(
"/:(\\d+)\$/",
"-\\1",
$host);
307 $privateKey = preg_replace(
"~[^a-z0-9/_]~i",
"", (
string)$privateKey);
308 if ($privateKey <>
'')
310 $privateKey =
"/".trim($privateKey,
"/");
313 $cacheKey =
$host.$uriPath.
"@".$queryString.$privateKey.
".html";
315 return str_replace(
array(
"?",
"*"),
"_", $cacheKey);
320 if (!is_string($queryString) || $queryString ===
"")
326 parse_str($queryString,
$params);
329 $ignoredParams = isset($options[
"~IGNORED_PARAMETERS"]) && is_array($options[
"~IGNORED_PARAMETERS"])
330 ? $options[
"~IGNORED_PARAMETERS"] :
array();
332 if (empty($ignoredParams) || empty(
$params))
339 foreach ($ignoredParams as $ignoredParam)
341 if (strcasecmp($ignoredParam,
$key) == 0)
349 return http_build_query(
$params,
"",
"&");
358 return file_exists(self::getEnabledFilePath());
372 return $_SERVER[
"DOCUMENT_ROOT"].BX_PERSONAL_ROOT.
"/html_pages/.enabled";
377 return $_SERVER[
"DOCUMENT_ROOT"].BX_PERSONAL_ROOT.
"/html_pages/.config.php";
382 return $_SERVER[
"DOCUMENT_ROOT"].BX_PERSONAL_ROOT.
"/html_pages/.size";
398 $tempFileName =
$fileName.md5(mt_rand()).
".tmp";
401 $fh = fopen($tempFileName,
"wb");
404 $content =
"<?\n\$arHTMLPagesOptions = array(\n";
407 if (is_integer(
$key))
413 $phpKey =
"\"".self::escapePHPString(
$key).
"\"";
416 if (is_array($value))
418 $content .=
"\t".$phpKey.
" => array(\n";
419 foreach ($value as $key2 =>
$val)
421 if (is_integer($key2))
427 $phpKey2 =
"\"".self::escapePHPString($key2).
"\"";
443 if ($written === $len)
451 @chmod(
$fileName, defined(
"BX_FILE_PERMISSIONS") ? BX_FILE_PERMISSIONS : 0664);
456 if (file_exists($tempFileName))
458 unlink($tempFileName);
462 self::$options =
array();
471 if (!str_ends_with(
$path,
"/"))
485 if (!file_exists(
$path))
487 return mkdir(
$path, defined(
"BX_DIR_PERMISSIONS") ? BX_DIR_PERMISSIONS : 0755,
true);
490 return is_dir(
$path);
495 $from =
array(
"\\",
"\$",
"\"");
496 $to =
array(
"\\\\",
"\\\$",
"\\\"");
497 return str_replace($from, $to,
$str);
506 if (!empty(self::$options))
508 return self::$options;
511 $arHTMLPagesOptions =
array();
518 $compile = !empty(array_diff(self::getCompiledOptions(), array_keys($arHTMLPagesOptions)));
519 $arHTMLPagesOptions = $arHTMLPagesOptions + self::getDefaultOptions();
525 if (isset($arHTMLPagesOptions[
"AUTO_COMPOSITE"]) && $arHTMLPagesOptions[
"AUTO_COMPOSITE"] ===
"Y")
527 $arHTMLPagesOptions[
"FRAME_MODE"] =
"Y";
528 $arHTMLPagesOptions[
"FRAME_TYPE"] =
"DYNAMIC_WITH_STUB";
529 $arHTMLPagesOptions[
"AUTO_UPDATE"] =
"Y";
532 self::$options = $arHTMLPagesOptions;
534 return self::$options;
542 private static function getDefaultOptions()
545 "INCLUDE_MASK" =>
"/*",
546 "EXCLUDE_MASK" =>
"/bitrix/*; /404.php; ",
548 "BANNER_BGCOLOR" =>
"#E94524",
549 "BANNER_STYLE" =>
"white",
550 "STORAGE" =>
"files",
551 "ONLY_PARAMETERS" =>
"id; ELEMENT_ID; SECTION_ID; PAGEN_1; ",
552 "IGNORED_PARAMETERS" =>
553 "utm_source; utm_medium; utm_campaign; utm_content; fb_action_ids; ".
554 "utm_term; yclid; gclid; _openstat; from; ".
555 "referrer1; r1; referrer2; r2; referrer3; r3; ",
556 "WRITE_STATISTIC" =>
"Y",
557 "EXCLUDE_PARAMS" =>
"ncc; ",
562 private static function getCompiledOptions()
573 "IGNORED_PARAMETERS",
574 "~IGNORED_PARAMETERS",
585 array(
"\\",
".",
"?",
"*",
"'"),
586 array(
"/",
"\\.",
".",
".*?",
"\\'"),
589 $arIncTmp = explode(
";", $inc);
590 foreach ($arIncTmp as $mask)
595 $arOptions[
"~INCLUDE_MASK"][] =
"'^".$mask.
"$'";
601 array(
"\\",
".",
"?",
"*",
"'"),
602 array(
"/",
"\\.",
".",
".*?",
"\\'"),
605 $arExcTmp = explode(
";", $exc);
606 foreach ($arExcTmp as $mask)
611 $arOptions[
"~EXCLUDE_MASK"][] =
"'^".$mask.
"$'";
626 $onlyParams = explode(
";",
$arOptions[
"ONLY_PARAMETERS"]);
627 foreach ($onlyParams as
$str)
637 $ignoredParams = explode(
";",
$arOptions[
"IGNORED_PARAMETERS"]);
638 foreach ($ignoredParams as
$str)
648 $excludeParams = explode(
";",
$arOptions[
"EXCLUDE_PARAMS"]);
649 foreach ($excludeParams as
$str)
658 if (defined(
"BX_STARTED"))
661 $arOptions[
"STORE_PASSWORD"] = \COption::GetOptionString(
"main",
"store_password",
"Y");
662 $cookie_prefix = \COption::GetOptionString(
'main',
'cookie_name',
'BITRIX_SM');
663 $arOptions[
"COOKIE_LOGIN"] = $cookie_prefix.
'_LOGIN';
664 $arOptions[
"COOKIE_PASS"] = $cookie_prefix.
'_UIDH';
665 $arOptions[
"COOKIE_NCC"] = $cookie_prefix.
'_NCC';
666 $arOptions[
"COOKIE_CC"] = $cookie_prefix.
'_CC';
667 $arOptions[
"COOKIE_PK"] = $cookie_prefix.
'_PK';
690 if ($options[
"WRITE_STATISTIC"] ===
"N")
704 $cacheSize = $cacheSize > 0 ? $cacheSize : 0;
729 "HITS" => intval($fileValues[0]),
730 "MISSES" => intval($fileValues[1]),
731 "QUOTA" => intval($fileValues[2]),
732 "POSTS" => intval($fileValues[3]),
733 "FILE_SIZE" => doubleval($fileValues[4]),
755 if ($options[
"WRITE_STATISTIC"] ===
"N")
766 if (@flock($fp, LOCK_EX))
768 $fileValues = explode(
",", fgets($fp));
769 $cacheSize = (isset($fileValues[4]) ? doubleval($fileValues[4]) + doubleval(
$files) : doubleval(
$files));
770 $newFileValues =
array(
771 $hits ===
false ? 0 : (isset($fileValues[0]) ? intval($fileValues[0]) + $hits : $hits),
772 $writings ===
false ? 0 : (isset($fileValues[1]) ? intval($fileValues[1]) + $writings : $writings),
773 $quota ===
false ? 0 : (isset($fileValues[2]) ? intval($fileValues[2]) + $quota : $quota),
774 $posts ===
false ? 0 : (isset($fileValues[3]) ? intval($fileValues[3]) + $posts : $posts),
775 $files ===
false ? 0 : ($cacheSize > 0 ? $cacheSize : 0),
780 fwrite($fp, implode(
",", $newFileValues));
798 $cacheQuota = doubleval($compositeOptions[
"~FILE_QUOTA"]);
801 $cacheSize = $cacheSize !==
false ? $cacheSize : 0.0;
803 return ($cacheSize + doubleval($requiredFreeSpace)) < $cacheQuota;
825 if (mb_strtoupper(
$name) === mb_strtoupper(
"OnUserLogin"))
829 elseif (mb_strtoupper(
$name) === mb_strtoupper(
"OnUserLogout"))
841 $url = filter_var(
$url, FILTER_SANITIZE_URL);
842 $url = trim(
$url,
" \t\n\r\0\x0B/\\");
843 $components = parse_url(
$url);
844 if (isset($components[
"host"]) && !empty($components[
"host"]))
846 return $components[
"host"];
848 elseif (isset($components[
"path"]) && !empty($components[
"path"]))
850 return $components[
"path"];
888 if (class_exists(
"cdiskquota"))
890 \CDiskQuota::updateDiskQuota(
"file",
$bytes,
"delete");
899if (!class_exists(
"CHTMLPagesCache",
false))
901 class_alias(
"Bitrix\\Main\\Composite\\Helper",
"CHTMLPagesCache");
static deleteRecursive($relativePath="", $validTime=0)
static install($setDefaults=true)
static setEnabled($status, $setDefaults=true)
static getDomainName($url)
static removeIgnoredParams($queryString)
static updateCacheFileSize($bytes=0.0)
static setUserPrivateKey($prefix, $expire=0)
static makeDirPath($path)
static isCompositeEnabled()
static getConfigFilePath()
static __callStatic($name, $arguments)
static convertUriToPath($uri, $host=null, $privateKey=null)
static isCompositeRequest()
static deleteUserPrivateKey()
static getEnabledFilePath()
static getHttpHost($host=null)
static isAppCacheRequest()
static getRealPrivateKey($privateKey=null, $postfix=null)
static getUserPrivateKey()
static getCacheFileSize()
static checkQuota($requiredFreeSpace=0)
static updateQuota($bytes)
static setOptions($arOptions=array())
static getSpaPostfixByUri($requestUri)
static escapePHPString($str)
static compileOptions(&$arOptions)
static writeStatistic($hits=0, $writings=0, $quota=0, $posts=0, $files=0.0)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']