/** * 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; }
/** * 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 CFreetrixComponent $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 cfreetrixcomponent) { $this->__parent = $parentComponent; } if ($arParams["CACHE_TYPE"] != "Y" && $arParams["CACHE_TYPE"] != "N") { $arParams["CACHE_TYPE"] = "A"; } if ($this->classOfComponent) { /** @var CFreetrixComponent $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 = \Freetrix\Main\Data\StaticHtmlCache::getInstance(); $staticHtmlCache->markNonCacheable(); if (defined("FX_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 = \Freetrix\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) { \Freetrix\Main\Data\AppCacheManifest::getInstance()->generate($dividedData["static"]); } else { \Freetrix\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" => \Freetrix\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 OnChangeFile($path, $site) { $pagesDir = new IO\Directory(IO\Path::convertRelativeToAbsolute(Application::getPersonalRoot()."/html_pages")); if (!$pagesDir->isExists()) { return; } $bytes = 0.0; $domainDirs = $pagesDir->getChildren(); $cachedFile = \Freetrix\Main\Data\StaticHtmlCache::convertUriToPath($path); foreach ($domainDirs as $domainDir) { if ($domainDir->isDirectory()) { $bytes += self::deleteRecursive("/".$domainDir->getName().$cachedFile); } } self::updateQuota(-$bytes); }
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 \Freetrix\Main\Page\FrameHelper $frame */ foreach ($this->frames as $frame) { if ($frame->isStarted() && !$frame->isEnded()) { $frame->end(); } } if (!$this->frameMode) { $staticHtmlCache = \Freetrix\Main\Data\StaticHtmlCache::getInstance(); $staticHtmlCache->markNonCacheable(); if (defined("FX_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; }