/** * Returns current instance of the StaticHtmlCache. * * @return StaticHtmlCache */ public static function getInstance() { if (!isset(static::$instance)) { static::$instance = new static(); static::$instance->init(); } return static::$instance; }
/** * Returns current instance of the StaticHtmlCache. * * @return StaticHtmlCache */ public static function getInstance() { if (!isset(static::$instance)) { $cacheProvider = static::getCacheProvider(); $privateKey = $cacheProvider !== null ? $cacheProvider->getCachePrivateKey() : null; static::$instance = new static(\CHTMLPagesCache::getRequestUri(), \CHTMLPagesCache::getHttpHost(), \CHTMLPagesCache::getRealPrivateKey($privateKey)); static::$instance->enableDebug(); if ($cacheProvider !== null) { static::$instance->setCacheProvider($cacheProvider); } } return static::$instance; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $dir = $input->getOption('dir'); $tag = $input->getOption('tag'); $cache = Cache::createInstance(); if (empty($dir) && empty($tag)) { Application::getInstance()->getManagedCache()->cleanAll(); $cache->cleanDir(); $cache->cleanDir(false, 'stack_cache'); StaticHtmlCache::getInstance()->deleteAll(); if (Cache::clearCache(true)) { $output->writeln('<info>All Bitrix cache was deleted</info>'); } else { $output->writeln('<error>Error deleting Bitrix cache</error>'); } } if ($dir) { $cache->cleanDir($dir); $output->writeln('<info>Bitrix cache by "/' . BX_ROOT . '/cache/' . $dir . '" dir was deleted</info>'); } if ($tag) { Application::getInstance()->getTaggedCache()->clearByTag($tag); $output->writeln('<info>Bitrix cache by tag "' . $tag . '" was deleted</info>'); } }
/** * Flushes all bitrix cache. * * @return void */ public static function flushAll() { $GLOBALS["CACHE_MANAGER"]->cleanAll(); $GLOBALS["stackCacheManager"]->cleanAll(); $staticHtmlCache = StaticHtmlCache::getInstance(); $staticHtmlCache->deleteAll(); BXClearCache(true); }
public static function deleteUserCache($userId = false) { global $USER; if ($userId === false && $USER->IsAuthorized()) { $userId = $USER->GetID(); } $userId = intval($userId); if ($userId > 0) { $postfix = \CHTMLPagesCache::getSpaPostfix(); $privateKey = self::getUserPrefix($userId); foreach ($postfix as $item) { $realPrivateKey = \CHTMLPagesCache::getRealPrivateKey($privateKey, $item); $staticCache = new StaticHtmlCache("/", null, $realPrivateKey); $staticCache->delete(); } header("X-Bitrix-Composite-Delete:" . md5(\CHTMLPagesCache::getHttpHost() . $privateKey)); } }
function __IncludePHPTemplate(&$arResult, &$arParams, $parentTemplateFolder = "") { /** @noinspection PhpUnusedLocalVariableInspection */ global $APPLICATION, $USER, $DB; if (!$this->__bInited) { return false; } // these vars are used in the template file /** @noinspection PhpUnusedLocalVariableInspection */ $templateName = $this->__name; /** @noinspection PhpUnusedLocalVariableInspection */ $templateFile = $this->__file; /** @noinspection PhpUnusedLocalVariableInspection */ $templateFolder = $this->__folder; /** @noinspection PhpUnusedLocalVariableInspection */ $componentPath = $this->__component->GetPath(); $component =& $this->__component; if ($this->__fileAlt != '') { include $_SERVER["DOCUMENT_ROOT"] . $this->__fileAlt; return null; } $templateData = false; include $_SERVER["DOCUMENT_ROOT"] . $this->__file; /** @var \Bitrix\Main\Page\FrameHelper $frame */ foreach ($this->frames as $frame) { if ($frame->isStarted() && !$frame->isEnded()) { $frame->end(); } } if (!$this->frameMode) { \Bitrix\Main\Data\StaticHtmlCache::applyComponentFrameMode($this->__file); } $component_epilog = $this->__folder . "/component_epilog.php"; if (file_exists($_SERVER["DOCUMENT_ROOT"] . $component_epilog)) { //These will be available with extract then component will //execute epilog without template $component->SetTemplateEpilog(array("epilogFile" => $component_epilog, "templateName" => $this->__name, "templateFile" => $this->__file, "templateFolder" => $this->__folder, "templateData" => $templateData)); } return null; }
if ($arParams["HIDE_EDIT_FORM"] != "Y" && IntVal($arResult["MICROBLOG_USER_ID"]) > 0 && $USER->IsAuthorized()) { ?> <div id="sonet_log_microblog_container"><?php $arBlogComponentParams = array("ID" => "new", "PATH_TO_BLOG" => $APPLICATION->GetCurPageParam("", array("WFILES")), "PATH_TO_POST" => $arParams["PATH_TO_USER_MICROBLOG_POST"], "PATH_TO_GROUP_POST" => $arParams["PATH_TO_GROUP_MICROBLOG_POST"], "PATH_TO_POST_EDIT" => $arParams["PATH_TO_USER_BLOG_POST_EDIT"], "PATH_TO_SMILE" => $arParams["PATH_TO_BLOG_SMILE"], "SET_TITLE" => "N", "GROUP_ID" => $arParams["BLOG_GROUP_ID"], "USER_ID" => $USER->GetID(), "SET_NAV_CHAIN" => "N", "USE_SOCNET" => "Y", "MICROBLOG" => "Y", "USE_CUT" => $arParams["BLOG_USE_CUT"], "NAME_TEMPLATE" => $arParams["NAME_TEMPLATE"], "CHECK_PERMISSIONS_DEST" => $arParams["CHECK_PERMISSIONS_DEST"], "TOP_TABS_VISIBLE" => array_key_exists("TOP_TABS_VISIBLE", $arParams) ? $arParams["TOP_TABS_VISIBLE"] : "Y"); if ($arParams["ENTITY_TYPE"] == SONET_ENTITY_GROUP) { $arBlogComponentParams["SOCNET_GROUP_ID"] = $arParams["GROUP_ID"]; } elseif ($arParams["ENTITY_TYPE"] != SONET_ENTITY_GROUP && $USER->GetID() != $arParams["CURRENT_USER_ID"]) { $arBlogComponentParams["SOCNET_USER_ID"] = $arParams["CURRENT_USER_ID"]; } if (isset($arParams["DISPLAY"])) { $arBlogComponentParams["DISPLAY"] = $arParams["DISPLAY"]; } if (defined("BITRIX24_INDEX_COMPOSITE")) { $arBlogComponentParams["POST_FORM_ACTION_URI"] = "/"; } $staticHtmlCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance(); $staticHtmlCache->disableVoting(); $APPLICATION->IncludeComponent("bitrix:socialnetwork.blog.post.edit", "", $arBlogComponentParams, $component, array("HIDE_ICONS" => "Y")); $staticHtmlCache->enableVoting(); ?> </div><?php } elseif ($arParams["SHOW_EVENT_ID_FILTER"] == "Y") { ?> <div class="feed-filter-fake-cont"></div><?php } if ($arParams["SHOW_EVENT_ID_FILTER"] == "Y") { if ($arParams["IS_CRM"] == "Y") { $liveFeedFilter = new CCrmLiveFeedFilter(array('GridFormID' => '', 'EntityTypeID' => false)); AddEventHandler('socialnetwork', 'OnBeforeSonetLogFilterFill', array($liveFeedFilter, 'OnBeforeSonetLogFilterFill')); } $GLOBALS["APPLICATION"]->IncludeComponent("bitrix:socialnetwork.log.filter", isset($arParams["FILTER_TEMPLATE"]) ? $arParams["FILTER_TEMPLATE"] : ".default", array("arParams" => array_merge($arParams, array("TOP_OUT" => "Y", "USE_TARGET" => !isset($arParams["USE_FILTER_TARGET"]) || $arParams["USE_FILTER_TARGET"] != "N" ? "Y" : "N", "TARGET_ID" => isset($_REQUEST["SONET_FILTER_MODE"]) && $_REQUEST["SONET_FILTER_MODE"] == "AJAX" ? "" : "sonet_blog_form", "USE_SONET_GROUPS" => !isset($arParams["IS_CRM"]) || $arParams["IS_CRM"] != "Y" ? "Y" : "N", "SHOW_FOLLOW" => isset($arParams["SHOW_FOLLOW_FILTER"]) && $arParams["SHOW_FOLLOW_FILTER"] == "N" ? "N" : "Y", "USE_SMART_FILTER" => isset($arResult["USE_SMART_FILTER"]) && $arResult["USE_SMART_FILTER"] == "Y" ? "Y" : "N", "MY_GROUPS_ONLY" => isset($arResult["MY_GROUPS_ONLY"]) && $arResult["MY_GROUPS_ONLY"] == "Y" ? "Y" : "N")), "arResult" => $arResult), null, array("HIDE_ICONS" => "Y"));
/** * @param string $context */ public static function rejectComposite($context = '') { return \Bitrix\Main\Data\StaticHtmlCache::applyComponentFrameMode($context); }
/** * * There are two variants of content's modification in this method. * The first one: * If it's ajax-hit the content will be replaced by json data with dynamic blocks, * javascript files and etc. - dynamic part * * The second one: * If it's simple hit the content will be modified also, * all dynamic blocks will be cutted out of the content - static part. * * @param string $content Html page content. * * @return string */ public function processPageContent($content) { global $APPLICATION; $dividedData = $this->getDividedPageData($content); $htmlCacheChanged = false; if (self::getUseHTMLCache()) { $isLicenseExpired = self::isLicenseExpired(); $staticHTMLCache = StaticHtmlCache::getInstance(); if ($staticHTMLCache->isCacheable()) { $cacheExists = $staticHTMLCache->exists(); if ((!$cacheExists || $staticHTMLCache->getMd5() !== $dividedData["md5"]) && !\CHTMLPagesCache::isIE9()) { if ($cacheExists) { $staticHTMLCache->delete(); } if (!$isLicenseExpired) { $success = $staticHTMLCache->write($dividedData["static"], $dividedData["md5"]); if ($success) { $htmlCacheChanged = true; $staticHTMLCache->setUserPrivateKey(); } } } else { if ($isLicenseExpired) { $staticHTMLCache->delete(); } } $dividedData["static"] = $this->replaceInjections($content); } else { $staticHTMLCache->delete(); return $this->getAjaxError("not_cacheable"); } } if (self::getUseAppCache() == true) { AppCacheManifest::getInstance()->generate($dividedData["static"]); } else { AppCacheManifest::checkObsoleteManifest(); } if (self::isAjaxRequest()) { self::sendRandHeader(); header("Content-Type: application/x-javascript; charset=" . SITE_CHARSET); header("X-Bitrix-Composite: Ajax " . ($htmlCacheChanged ? "(changed)" : "(stable)")); $content = array("js" => $APPLICATION->arHeadScripts, "additional_js" => $APPLICATION->arAdditionalJS, "lang" => \CJSCore::GetCoreMessages(), "css" => $APPLICATION->GetCSSArray(), "htmlCacheChanged" => $htmlCacheChanged, "isManifestUpdated" => AppCacheManifest::getInstance()->getIsModified(), "dynamicBlocks" => $dividedData["dynamic"], "spread" => array_map(array("CUtil", "JSEscape"), $APPLICATION->GetSpreadCookieUrls())); $content = \CUtil::PhpToJSObject($content); } else { $content = $dividedData["static"]; } return $content; }
/** * Function starts the caching block of the component execution. * * @param int|bool $cacheTime * @param mixed $additionalCacheID * @param string|bool $cachePath * @return string * */ public final function startResultCache($cacheTime = false, $additionalCacheID = false, $cachePath = false) { /** @global CMain $APPLICATION */ global $APPLICATION, $CACHE_MANAGER; if (!$this->__bInited) { return null; } if ($this->arParams["CACHE_TYPE"] == "N" || $this->arParams["CACHE_TYPE"] == "A" && COption::getOptionString("main", "component_cache_on", "Y") == "N") { return true; } if ($cacheTime === false) { $cacheTime = intval($this->arParams["CACHE_TIME"]); } $this->__cacheID = $this->getCacheID($additionalCacheID); $this->__cachePath = $cachePath; if ($this->__cachePath === false) { $this->__cachePath = $CACHE_MANAGER->getCompCachePath($this->__relativePath); } $this->__cache = \Bitrix\Main\Data\Cache::createInstance(); if ($this->__cache->startDataCache($cacheTime, $this->__cacheID, $this->__cachePath)) { $this->__NavNum = $GLOBALS["NavNum"]; if (defined("BX_COMP_MANAGED_CACHE") && $this->__cache->isStarted()) { $CACHE_MANAGER->startTagCache($this->__cachePath); } return true; } else { $arCache = $this->__cache->GetVars(); $this->arResult = $arCache["arResult"]; if (array_key_exists("templateCachedData", $arCache)) { $templateCachedData =& $arCache["templateCachedData"]; if ($templateCachedData && is_array($templateCachedData)) { if (array_key_exists("additionalCSS", $templateCachedData) && strlen($templateCachedData["additionalCSS"]) > 0) { $APPLICATION->SetAdditionalCSS($templateCachedData["additionalCSS"]); if ($this->__parent) { $this->__parent->addChildCSS($templateCachedData["additionalCSS"]); } } if (array_key_exists("additionalJS", $templateCachedData) && strlen($templateCachedData["additionalJS"]) > 0) { $APPLICATION->AddHeadScript($templateCachedData["additionalJS"]); if ($this->__parent) { $this->__parent->addChildJS($templateCachedData["additionalJS"]); } } if (array_key_exists("frames", $templateCachedData) && is_array($templateCachedData["frames"])) { foreach ($templateCachedData["frames"] as $frameState) { \Bitrix\Main\Page\FrameHelper::applyCachedData($frameState); } } if (array_key_exists("frameMode", $templateCachedData) && $templateCachedData["frameMode"] === false) { $context = isset($templateCachedData["frameModeCtx"]) ? "(from component cache) " . $templateCachedData["frameModeCtx"] : $this->__name . " - a cached template set frameMode=false"; \Bitrix\Main\Data\StaticHtmlCache::applyComponentFrameMode($context); } if (isset($templateCachedData["externalCss"])) { foreach ($templateCachedData["externalCss"] as $cssPath) { $APPLICATION->SetAdditionalCSS($cssPath); //Check if parent component exists and plug css it to it's "collection" if ($this->__parent) { $this->__parent->addChildCSS($cssPath); } } } if (isset($templateCachedData["externalJs"])) { foreach ($templateCachedData["externalJs"] as $jsPath) { $APPLICATION->AddHeadScript($jsPath); //Check if parent component exists and plug js it to it's "collection" if ($this->__parent) { $this->__parent->addChildJS($jsPath); } } } } if ($templateCachedData["__editButtons"]) { foreach ($templateCachedData["__editButtons"] as $button) { if ($button[0] == 'AddEditAction') { $this->addEditAction($button[1], $button[2], $button[3], $button[4]); } else { $this->addDeleteAction($button[1], $button[2], $button[3], $button[4]); } } } if ($templateCachedData["__view"]) { foreach ($templateCachedData["__view"] as $view_id => $target) { foreach ($target as $view_content) { $APPLICATION->addViewContent($view_id, $view_content[0], $view_content[1]); } } } if (array_key_exists("__NavNum", $templateCachedData)) { $GLOBALS["NavNum"] += $templateCachedData["__NavNum"]; } if (array_key_exists("__children_css", $templateCachedData)) { foreach ($templateCachedData["__children_css"] as $css_url) { $APPLICATION->setAdditionalCSS($css_url); } } if (array_key_exists("__children_js", $templateCachedData)) { foreach ($templateCachedData["__children_js"] as $js_url) { $APPLICATION->addHeadScript($js_url); } } if (array_key_exists("__children_epilogs", $templateCachedData)) { foreach ($templateCachedData["__children_epilogs"] as $component_epilog) { $this->includeComponentEpilog($component_epilog); } } if (array_key_exists("component_epilog", $templateCachedData)) { $this->includeComponentEpilog($templateCachedData["component_epilog"]); } } return false; } }
public static function setCC() { global $APPLICATION; $APPLICATION->set_cookie("CC", "Y"); $APPLICATION->set_cookie("NCC", "", 0); $staticHTMLCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance(); $staticHTMLCache->setUserPrivateKey(); }
/** * Function executes the component. Returns the result of it's execution. * * <p>Note: component must be inited by initComponent method.</p> * @param string $componentTemplate * @param array[string]mixed $arParams * @param CBitrixComponent $parentComponent * @return mixed * */ public final function includeComponent($componentTemplate, $arParams, $parentComponent) { if (!$this->__bInited) { return null; } if ($componentTemplate !== false) { $this->setTemplateName($componentTemplate); } if (is_object($parentComponent) && $parentComponent instanceof cbitrixcomponent) { $this->__parent = $parentComponent; } if ($arParams["CACHE_TYPE"] != "Y" && $arParams["CACHE_TYPE"] != "N") { $arParams["CACHE_TYPE"] = "A"; } if ($this->classOfComponent) { /** @var CBitrixComponent $component */ $component = new $this->classOfComponent($this); $component->arParams = $component->onPrepareComponentParams($arParams); $component->__prepareComponentParams($component->arParams); $component->onIncludeComponentLang(); $result = $component->executeComponent(); $this->__arIncludeAreaIcons = $component->__arIncludeAreaIcons; $frameMode = $component->frameMode; } else { $this->__prepareComponentParams($arParams); $this->arParams = $arParams; $this->includeComponentLang(); $result = $this->__IncludeComponent(); $frameMode = $this->frameMode; } if (!$frameMode) { $staticHtmlCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance(); $staticHtmlCache->markNonCacheable(); if (defined("BX_COMPOSITE_DEBUG") && defined("USE_HTML_STATIC_CACHE") && USE_HTML_STATIC_CACHE == true) { AddMessage2Log("Component: " . $this->__name . "\n" . "Request URI: " . $_SERVER["REQUEST_URI"] . "\n" . "Script: " . (isset($_SERVER["REAL_FILE_PATH"]) ? $_SERVER["REAL_FILE_PATH"] : $_SERVER["SCRIPT_NAME"]), "composite"); } } return $result; }
/** * OnEndBufferContent handler * There are two variants of content's modification in this method. * The first one: * If it's ajax-hit the content will be replaced by json data with dynamic blocks, * javascript files and etc. - dynamic part * * The second one: * If it's simple hit the content will be modified also, * all dynamic blocks will be cutted out of the content - static part. * * @param $content */ public function onEndBufferContent(&$content) { global $APPLICATION; $dividedData = self::getInstance()->getDividedPageData($content); $htmlCacheChanged = false; if (self::getUseHTMLCache()) { $staticHTMLCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance(); if ($staticHTMLCache->isCacheable()) { if (!$staticHTMLCache->isExists() || $staticHTMLCache->getSubstring(-35, 32) !== $dividedData["md5"]) { $staticHTMLCache->delete(); $staticHTMLCache->write($dividedData["static"] . "<!--" . $dividedData["md5"] . "-->"); } $frame = self::getInstance(); $ids = $frame->getDynamicIDs(); foreach ($ids as $i => $id) { if (isset($frame->containers[$id])) { unset($ids[$i]); } } $dividedData["static"] = preg_replace(array('/<!--\'start_frame_cache_(' . implode("|", $ids) . ')\'-->/', '/<!--\'end_frame_cache_(' . implode("|", $ids) . ')\'-->/'), array('<div id="bxdynamic_\\1">', '</div>'), $content); if ($frame->injectedJS) { if (isset($frame->injectedJS["start"])) { $dividedData["static"] = str_replace($frame->injectedJS["start"], "", $dividedData["static"]); } } } elseif (!$staticHTMLCache->isCacheable()) { $staticHTMLCache->delete(); return; } } if (self::getUseAppCache() == true) { \Bitrix\Main\Data\AppCacheManifest::getInstance()->generate($dividedData["static"]); } else { \Bitrix\Main\Data\AppCacheManifest::checkObsoleteManifest(); } if (self::isAjaxRequest()) { header("Content-Type: application/x-javascript; charset=" . SITE_CHARSET); $content = array("js" => $APPLICATION->arHeadScripts, "additional_js" => $APPLICATION->arAdditionalJS, "lang" => \CJSCore::GetCoreMessages(), "css" => $APPLICATION->GetCSSArray(), "htmlCacheChanged" => $htmlCacheChanged, "isManifestUpdated" => \Bitrix\Main\Data\AppCacheManifest::getInstance()->getIsModified(), "dynamicBlocks" => $dividedData["dynamic"], "spread" => array_map(array("CUtil", "JSEscape"), $APPLICATION->GetSpreadCookieUrls())); $content = \CUtil::PhpToJSObject($content); } else { $content = $dividedData["static"]; } }
public static function onBeforeLocalRedirect(&$url, $skip_security_check, $isExternal) { global $APPLICATION; if (!self::isAjaxRequest() || $isExternal && $skip_security_check !== true) { return; } $response = array("error" => true, "reason" => "redirect", "redirect_url" => $url); self::setEnable(false); if ($APPLICATION->buffered) { $APPLICATION->RestartBuffer(); } self::getInstance()->isRedirect = true; StaticHtmlCache::getInstance()->delete(); header("X-Bitrix-Composite: Ajax (error:redirect)"); self::sendRandHeader(); echo \CUtil::PhpToJSObject($response); die; }
function __IncludePHPTemplate(&$arResult, &$arParams, $parentTemplateFolder = "") { /** @noinspection PhpUnusedLocalVariableInspection */ global $APPLICATION, $USER, $DB; if (!$this->__bInited) { return false; } // these vars are used in the template file /** @noinspection PhpUnusedLocalVariableInspection */ $templateName = $this->__name; /** @noinspection PhpUnusedLocalVariableInspection */ $templateFile = $this->__file; /** @noinspection PhpUnusedLocalVariableInspection */ $templateFolder = $this->__folder; /** @noinspection PhpUnusedLocalVariableInspection */ $componentPath = $this->__component->GetPath(); $component =& $this->__component; if ($this->__fileAlt != '') { include $_SERVER["DOCUMENT_ROOT"] . $this->__fileAlt; return null; } $templateData = false; include $_SERVER["DOCUMENT_ROOT"] . $this->__file; /** @var \Bitrix\Main\Page\FrameHelper $frame */ foreach ($this->frames as $frame) { if ($frame->isStarted() && !$frame->isEnded()) { $frame->end(); } } if (!$this->frameMode) { $staticHtmlCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance(); $staticHtmlCache->markNonCacheable(); if (defined("BX_COMPOSITE_DEBUG") && defined("USE_HTML_STATIC_CACHE") && USE_HTML_STATIC_CACHE == true) { AddMessage2Log("Template: " . $this->__file . "\n" . "Request URI: " . $_SERVER["REQUEST_URI"] . "\n" . "Script: " . (isset($_SERVER["REAL_FILE_PATH"]) ? $_SERVER["REAL_FILE_PATH"] : $_SERVER["SCRIPT_NAME"]), "composite"); } } $component_epilog = $this->__folder . "/component_epilog.php"; if (file_exists($_SERVER["DOCUMENT_ROOT"] . $component_epilog)) { //These will be available with extract then component will //execute epilog without template $component->SetTemplateEpilog(array("epilogFile" => $component_epilog, "templateName" => $this->__name, "templateFile" => $this->__file, "templateFolder" => $this->__folder, "templateData" => $templateData)); } return null; }