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);
65 $requestUri = ($p = mb_strpos($requestUri,
"?")) ===
false? $requestUri : mb_substr($requestUri, 0, $p);
67 if (isset($options[
"SPA_MAP"]) && is_array($options[
"SPA_MAP"]))
69 foreach ($options[
"SPA_MAP"] as $mask => $postfix)
71 if (preg_match($mask, $requestUri))
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");
173 $folders = array(BX_ROOT, BX_PERSONAL_ROOT);
174 $requestUri =
"/".ltrim($_SERVER[
"REQUEST_URI"],
"/");
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"))
209 $data = substr($data, 10, -8);
212 $data = gzinflate($data);
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"]);
248 unset($_REQUEST[
"bxrand"]);
250 if (isset($_SERVER[
"REQUEST_URI"]))
252 $_SERVER[
"REQUEST_URI"] = preg_replace(
253 "/((?<=\\?)bxrand=\\d+&?|&bxrand=\\d+\$)/",
255 $_SERVER[
"REQUEST_URI"]
257 $_SERVER[
"REQUEST_URI"] = rtrim($_SERVER[
"REQUEST_URI"],
"?&");
260 if (isset($_SERVER[
"QUERY_STRING"]))
262 $_SERVER[
"QUERY_STRING"] = preg_replace(
"/[?&]?bxrand=[0-9]+/",
"", $_SERVER[
"QUERY_STRING"]);
263 $_SERVER[
"QUERY_STRING"] = trim($_SERVER[
"QUERY_STRING"],
"&");
264 if (isset(
$GLOBALS[
"QUERY_STRING"]))
266 $GLOBALS[
"QUERY_STRING"] = $_SERVER[
"QUERY_STRING"];
270 return self::$ajaxRandom;
289 $uri =
"/".trim($uri,
"/");
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))
337 foreach ($params as $key => $value)
339 foreach ($ignoredParams as $ignoredParam)
341 if (strcasecmp($ignoredParam, $key) == 0)
343 unset($params[$key]);
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";
394 $arOptions = array_merge(self::getOptions(), $arOptions);
398 $tempFileName = $fileName.md5(mt_rand()).
".tmp";
401 $fh = fopen($tempFileName,
"wb");
404 $content =
"<?\n\$arHTMLPagesOptions = array(\n";
405 foreach ($arOptions as $key => $value)
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).
"\"";
432 $content .=
"\t),\n";
440 $content .=
");\n?>";
441 $written = fwrite($fh, $content);
442 $len = strlen($content);
443 if ($written === $len)
446 if (file_exists($fileName))
450 rename($tempFileName, $fileName);
451 @chmod($fileName, defined(
"BX_FILE_PERMISSIONS") ? BX_FILE_PERMISSIONS : 0664);
456 if (file_exists($tempFileName))
458 unlink($tempFileName);
462 self::$options = array();
468 $path = str_replace(array(
"\\",
"//"),
"/", $path);
471 if (mb_substr($path, -1) !=
"/")
473 $p = mb_strrpos($path,
"/");
474 $path = mb_substr($path, 0, $p);
477 $path = rtrim($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();
513 if (file_exists($fileName))
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",
583 $arOptions[
"~INCLUDE_MASK"] = array();
585 array(
"\\",
".",
"?",
"*",
"'"),
586 array(
"/",
"\\.",
".",
".*?",
"\\'"),
587 $arOptions[
"INCLUDE_MASK"]
589 $arIncTmp = explode(
";", $inc);
590 foreach ($arIncTmp as $mask)
595 $arOptions[
"~INCLUDE_MASK"][] =
"'^".$mask.
"$'";
599 $arOptions[
"~EXCLUDE_MASK"] = array();
601 array(
"\\",
".",
"?",
"*",
"'"),
602 array(
"/",
"\\.",
".",
".*?",
"\\'"),
603 $arOptions[
"EXCLUDE_MASK"]
605 $arExcTmp = explode(
";", $exc);
606 foreach ($arExcTmp as $mask)
611 $arOptions[
"~EXCLUDE_MASK"][] =
"'^".$mask.
"$'";
615 if (intval($arOptions[
"FILE_QUOTA"]) > 0)
617 $arOptions[
"~FILE_QUOTA"] = doubleval($arOptions[
"FILE_QUOTA"]) * 1024.0 * 1024.0;
621 $arOptions[
"~FILE_QUOTA"] = 0.0;
624 $arOptions[
"INDEX_ONLY"] = isset($arOptions[
"NO_PARAMETERS"]) && ($arOptions[
"NO_PARAMETERS"] ===
"Y");
625 $arOptions[
"~GET"] = array();
626 $onlyParams = explode(
";", $arOptions[
"ONLY_PARAMETERS"]);
627 foreach ($onlyParams as $str)
632 $arOptions[
"~GET"][] = $str;
636 $arOptions[
"~IGNORED_PARAMETERS"] = array();
637 $ignoredParams = explode(
";", $arOptions[
"IGNORED_PARAMETERS"]);
638 foreach ($ignoredParams as $str)
643 $arOptions[
"~IGNORED_PARAMETERS"][] = $str;
647 $arOptions[
"~EXCLUDE_PARAMS"] = array();
648 $excludeParams = explode(
";", $arOptions[
"EXCLUDE_PARAMS"]);
649 foreach ($excludeParams as $str)
654 $arOptions[
"~EXCLUDE_PARAMS"][] = $str;
658 if (defined(
"BX_STARTED"))
660 $arOptions[
"COMPRESS"] =
false;
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';
679 if (file_exists($fileName) && ($contents = file_get_contents($fileName)) !==
false)
681 $result = doubleval($contents);
690 if ($options[
"WRITE_STATISTIC"] ===
"N")
696 if (($handle = @fopen($fileName,
"c+")) ===
false)
701 if (@flock($handle, LOCK_EX))
703 $cacheSize = $bytes ===
false ? 0 : doubleval(fgets($handle)) + doubleval($bytes);
704 $cacheSize = $cacheSize > 0 ? $cacheSize : 0;
707 ftruncate($handle, 0);
708 fwrite($handle, $cacheSize);
709 flock($handle, LOCK_UN);
725 if (file_exists($fileName) && ($contents = file_get_contents($fileName)) !==
false)
727 $fileValues = explode(
",", $contents);
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]),
752 public static function writeStatistic($hits = 0, $writings = 0, $quota = 0, $posts = 0, $files = 0.0)
755 if ($options[
"WRITE_STATISTIC"] ===
"N")
761 if (!file_exists($fileName) || ($fp = @fopen($fileName,
"r+")) ===
false)
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"))
827 \Bitrix\Main\Composite\Engine::onUserLogin();
829 elseif (mb_strtoupper($name) === mb_strtoupper(
"OnUserLogout"))
831 \Bitrix\Main\Composite\Engine::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"];
866 public static function setEnabled($status, $setDefaults =
true)
886 $bytes = Data\FileStorage::deleteRecursive(
"/");
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 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)
$GLOBALS['____1444769544']