/** * OnEndBufferContent handler * @param $content */ public static function onEndBufferContent(&$content) { global $APPLICATION; if (self::getUseAppCache() == true) { //Do we use html5 application cache? \Bitrix\Main\Data\AppCacheManifest::onEndBufferContent($content); } else { \Bitrix\Main\Data\AppCacheManifest::checkObsoleteManifest(); } //it checks if the manifest is still alive. $selfObject = self::getInstance(); $ids = $selfObject->getDynamicIDs(); if (count($ids) > 0) { $match = array(); $regexp = "/##start_frame_cache_(" . implode("|", $ids) . ")##(.+?)##end_frame_cache_(?:" . implode("|", $ids) . ")##/is"; preg_match_all($regexp, $content, $match); /* Notes: $match[0] - array of dynamic blocks with macros' $match[1] - ids of the dynamic blocks $match[2] - array of dynamic blocks */ $count = count($match[1]); if (self::$isBackgroundRequest) { //$fcache->arDynamicData = array_combine($match[1], $match[2]); for ($i = 0; $i < $count; $i++) { $selfObject->arDynamicData[] = array("ID" => $match[1][$i], "CONTENT" => $match[2][$i], "HASH" => md5($match[2][$i])); } } else { $replacedArray = array(); for ($i = 0; $i < $count; $i++) { $replacedArray[] = '<div id="bxdynamic_' . $match[1][$i] . '"></div>'; } $content = str_replace($match[0], $replacedArray, $content); } } if (self::$isBackgroundRequest) { header("Content-Type: application/x-javascript"); $content = array("isManifestUpdated" => \Bitrix\Main\Data\AppCacheManifest::getInstance()->getIsModified(), "dynamicBlocks" => $selfObject->arDynamicData); if (!Application::getInstance()->isUtfMode()) { //TODO I use it because there is no similar method in the new Bitrix Framework yet $content = $APPLICATION->convertCharsetArray($content, SITE_CHARSET, "UTF-8"); } $content = json_encode($content); } }
/** * OnEndBufferContent handler * @param $content */ public static function onEndBufferContent(&$content) { global $APPLICATION; global $USER; if (self::getUseAppCache() == true) { //Do we use html5 application cache? \Bitrix\Main\Data\AppCacheManifest::onEndBufferContent($content); } else { \Bitrix\Main\Data\AppCacheManifest::checkObsoleteManifest(); } //it checks if the manifest is still alive. $selfObject = self::getInstance(); $ids = $selfObject->getDynamicIDs(); if (count($ids) > 0) { $match = array(); $regexp = "/##start_frame_cache_(" . implode("|", $ids) . ")##(.+?)##end_frame_cache_(?:" . implode("|", $ids) . ")##/is"; preg_match_all($regexp, $content, $match); /* Notes: $match[0] - array of dynamic blocks with macros' $match[1] - ids of the dynamic blocks $match[2] - array of dynamic blocks */ $count = count($match[1]); if (self::$isBackgroundRequest) { //$fcache->arDynamicData = array_combine($match[1], $match[2]); for ($i = 0; $i < $count; $i++) { $selfObject->arDynamicData[] = array("ID" => $match[1][$i], "CONTENT" => $match[2][$i], "HASH" => md5($match[2][$i])); } } else { $replacedArray = array(); for ($i = 0; $i < $count; $i++) { $replacedArray[] = '<div id="bxdynamic_' . $match[1][$i] . '"></div>'; } $content = str_replace($match[0], $replacedArray, $content); } } if (self::$isBackgroundRequest) { header("Content-Type: application/x-javascript"); $autoTimeZone = "N"; if (is_object($GLOBALS["USER"])) { $autoTimeZone = trim($USER->GetParam("AUTO_TIME_ZONE")); } $content = array("js" => $APPLICATION->arHeadScripts, "additional_js" => $APPLICATION->arAdditionalJS, "lang" => array('LANGUAGE_ID' => LANGUAGE_ID, 'FORMAT_DATE' => FORMAT_DATE, 'FORMAT_DATETIME' => FORMAT_DATETIME, 'COOKIE_PREFIX' => \COption::GetOptionString("main", "cookie_name", "BITRIX_SM"), 'USER_ID' => $USER->GetID(), 'SERVER_TIME' => time(), 'SERVER_TZ_OFFSET' => date("Z"), 'USER_TZ_OFFSET' => \CTimeZone::GetOffset(), 'USER_TZ_AUTO' => $autoTimeZone == 'N' ? 'N' : 'Y', 'bitrix_sessid' => bitrix_sessid()), "css" => $APPLICATION->GetCSSArray(), "isManifestUpdated" => \Bitrix\Main\Data\AppCacheManifest::getInstance()->getIsModified(), "dynamicBlocks" => $selfObject->arDynamicData); if (!\Bitrix\Main\Application::getInstance()->isUtfMode()) { //TODO I use it because there is no similar method in the new Bitrix Framework yet $content = $APPLICATION->convertCharsetarray($content, SITE_CHARSET, "UTF-8"); } $content = json_encode($content); } }
/** * * 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; }
/** * 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"]; } }