98 $manifest = static::getInstance();
99 $files = $manifest->getFilesFromContent($content);
101 $this->isModified =
false;
106 $curManifestId = $this->getManifestID($this->pageURI, $this->receivedCacheParams);
107 if ($curManifestId != $manifestId)
109 self::removeManifestById($curManifestId);
113 $currentHashSum = md5(serialize($files[
"FULL_FILE_LIST"]) . serialize($this->fallbackPages) . serialize($this->network) . serialize($this->excludeImagePatterns));
115 if (!$manifestCache || $manifestCache[
"FILE_HASH"] != $currentHashSum || self::$debug)
117 $this->isModified =
true;
118 $this->
setFiles($files[
"FULL_FILE_LIST"]);
123 "FILE_HASH" => $currentHashSum,
124 "EXCLUDE_PATTERNS_HASH"=> md5(serialize($this->excludeImagePatterns)),
125 "FILE_DATA" => Array(
126 "FILE_TIMESTAMPS" => $files[
"FILE_TIMESTAMPS"],
127 "CSS_FILE_IMAGES" => $files[
"CSS_FILE_IMAGES"]
133 $this->writeManifestCache($arFields);
137 $jsFields = json_encode($arFields);
138 $fileCount = count($this->files);
139 $params = json_encode($this->params);
140 $fileCountImages = 0;
141 foreach ($arFields[
"FILE_DATA"][
"CSS_FILE_IMAGES"] as $file=>$images)
143 if (is_array($images))
145 $fileCountImages += count($images);
152 console.log(
"-------APPLICATION CACHE DEBUG INFO------");
153 console.log(
"File count:", $fileCount);
154 console.log(
"Image file count:", $fileCountImages);
155 console.log(
"Params:", $params);
156 console.log(
"Detail:", $jsFields);
157 console.log(
"--------------------------------------------");
160 $jsContent = str_replace(array(
"\n",
"\t"),
"", $debugOutput);
161 $content = str_replace(self::DEBUG_HOLDER, $jsContent, $content);
176 $server = \Bitrix\Main\Context::getCurrent()->getServer();
178 $appCacheUrl = $server->get(
"HTTP_BX_APPCACHE_URL");
179 $appCacheParams = $server->get(
"HTTP_BX_APPCACHE_PARAMS");
180 if ($appCacheUrl <>
'')
183 $selfObject->setIsSided(
true);
184 $selfObject->setPageURI($appCacheUrl);
187 $params = json_decode($appCacheParams,
true);
189 if (!is_array($params))
194 $selfObject->setReceivedCacheParams($params);
199 $selfObject->setPageURI($server->get(
"REQUEST_URI"));
203 $APPLICATION->SetPageProperty(
"manifest",
" manifest=\"" . self::getManifestCheckFile() .
"?manifest_id=" . $selfObject->getCurrentManifestID() .
"\"");
207 Asset::getInstance()->addString(
"<script type=\"text/javascript\">".self::DEBUG_HOLDER.
"</script>");
211 "PAGE_URL" => $selfObject->getPageURI(),
212 "PARAMS" => $selfObject->getAdditionalParams(),
217 return (is_array($params) ? $params : array());
256 $manifestText =
"CACHE MANIFEST\n\n";
257 $manifestText .= $this->getManifestDescription();
258 $manifestText .=
"#files" .
"\n\n";
259 $manifestText .= implode(
"\n", $this->files) .
"\n\n";
260 $manifestText .=
"NETWORK:\n";
261 $manifestText .= implode(
"\n", $this->network) .
"\n\n";
262 $manifestText .=
"FALLBACK:\n\n";
263 $countFallback = count($this->fallbackPages);
264 for ($i = 0; $i < $countFallback; $i++)
266 $manifestText .= $this->fallbackPages[$i][
"online"] .
" " . $this->fallbackPages[$i][
"offline"] .
"\n";
269 return $manifestText;
282 $arFilesByType = Array();
283 $arExtensions = Array(
"js",
"css");
284 $extension_regex =
"(?:" . implode(
"|", $arExtensions) .
")";
285 $findImageRegexp =
"/
291 |jsUtils\\.loadJSFile\\(
292 |background\\s*:\\s*url\\(
295 ([^?'\"]+\\.) #href body
296 (" . $extension_regex .
") #extentions
297 (|\\?\\d+|\\?v=\\d+) #params
301 preg_match_all($findImageRegexp, $content, $match);
304 $extension = $match[4];
306 $linkCount = count($link);
308 "FULL_FILE_LIST" => array(),
309 "FILE_TIMESTAMPS" => array(),
310 "CSS_FILE_IMAGES" => array()
312 for ($i = 0; $i < $linkCount; $i++)
314 $fileData[
"FULL_FILE_LIST"][] = $files[] = $link[$i] . $extension[$i] . $params[$i];
315 $fileData[
"FILE_TIMESTAMPS"][$link[$i] . $extension[$i]] = $params[$i];
316 $arFilesByType[$extension[$i]][] = $link[$i] . $extension[$i];
320 $excludePatternsHash = md5(serialize($this->excludeImagePatterns));
322 if (array_key_exists(
"css", $arFilesByType))
324 $findImageRegexp =
'#([;\s:]*(?:url|@import)\s*\(\s*)(\'|"|)(.+?)(\2)\s*\)#si';
325 if(!empty($this->excludeImagePatterns))
327 $findImageRegexp =
'#([;\s:]*(?:url|@import)\s*\(\s*)(\'|"|)((?:(?!'.implode(
"|",$this->excludeImagePatterns).
').)+?)(\2)\s*\)#si';
330 $cssCount = count($arFilesByType[
"css"]);
331 for ($j = 0; $j < $cssCount; $j++)
333 $cssFilePath = $arFilesByType[
"css"][$j];
334 if ($manifestCache[
"FILE_DATA"][
"FILE_TIMESTAMPS"][$cssFilePath] != $fileData[
"FILE_TIMESTAMPS"][$cssFilePath]
335 ||$excludePatternsHash != $manifestCache[
"EXCLUDE_PATTERNS_HASH"]
339 $fileContent =
false;
340 $fileUrl = parse_url($cssFilePath);
343 if($file->getExtension() !==
"css")
346 if ($file->isExists() && $file->isReadable())
348 $fileContent = $file->getContents();
350 elseif ($fileUrl[
"scheme"])
353 $req->http_timeout = 20;
354 $fileContent = $req->Get($cssFilePath);
357 if ($fileContent !=
false)
359 $cssFileRelative = new \Bitrix\Main\IO\File($cssFilePath);
360 $cssPath = $cssFileRelative->getDirectoryName();
361 preg_match_all($findImageRegexp, $fileContent, $match);
362 $matchCount = count($match[3]);
363 for ($k = 0; $k < $matchCount; $k++)
366 $file = self::replaceUrlCSS($match[3][$k], addslashes($cssPath));
368 if (!in_array($file, $files) && !mb_strpos($file,
";base64"))
370 $fileData[
"FULL_FILE_LIST"][] = $files[] = $file;
371 $fileData[
"CSS_FILE_IMAGES"][$cssFilePath][] = $file;
378 $fileData[
"CSS_FILE_IMAGES"][$cssFilePath] = $manifestCache[
"FILE_DATA"][
"CSS_FILE_IMAGES"][$cssFilePath];
379 if (is_array($manifestCache[
"FILE_DATA"][
"CSS_FILE_IMAGES"][$cssFilePath]))
381 $fileData[
"FULL_FILE_LIST"] = array_merge($fileData[
"FULL_FILE_LIST"], $manifestCache[
"FILE_DATA"][
"CSS_FILE_IMAGES"][$cssFilePath]);
614 $server = \Bitrix\Main\Context::getCurrent()->getServer();
615 $appCacheUrl = $server->get(
"HTTP_BX_APPCACHE_URL");
616 $appCacheParams = $server->get(
"HTTP_BX_APPCACHE_PARAMS");
619 $params = json_decode($appCacheParams,
true);
621 if (!is_array($params))
626 static::clear($appCacheUrl, $params);