Пример #1
0
 /**
  *
  * @param string &$content
  * @return void
  *
  */
 public function OnEndBufferContent(&$content)
 {
     if (isset($_GET["nocdn"])) {
         return;
     }
     self::$proto = CMain::IsHTTPS() ? "https" : "http";
     self::$config = CBitrixCloudCDNConfig::getInstance()->loadFromOptions();
     if (self::$config->isExpired()) {
         if (self::$config->lock()) {
             try {
                 try {
                     $delayExpiration = true;
                     self::$config = CBitrixCloudCDNConfig::getInstance()->loadRemoteXML();
                     self::$config->saveToOptions();
                     self::$config->unlock();
                 } catch (CBitrixCloudException $e) {
                     //In case of documented XML error we'll disable CDN
                     if ($e->getErrorCode() !== "") {
                         self::SetActive(false);
                         $delayExpiration = false;
                     }
                     throw $e;
                 }
             } catch (exception $e) {
                 if ($delayExpiration) {
                     self::$config->setExpired(time() + 1800);
                 }
                 CAdminNotify::Add(array("MESSAGE" => GetMessage("BCL_CDN_NOTIFY", array("#HREF#" => "/bitrix/admin/bitrixcloud_cdn.php?lang=" . LANGUAGE_ID)), "TAG" => "bitrixcloud_off", "MODULE_ID" => "bitrixcloud", "ENABLE_CLOSE" => "Y"));
                 self::$config->unlock();
                 return;
             }
         }
     }
     if (!self::$config->isActive()) {
         return false;
     }
     $sites = self::$config->getSites();
     if (defined("ADMIN_SECTION")) {
         if (!isset($sites["admin"])) {
             return;
         }
     } elseif (defined("SITE_ID")) {
         if (!isset($sites[SITE_ID])) {
             return;
         }
     } else {
         return;
     }
     self::$ajax = preg_match("/<head>/i", substr($content, 0, 512)) === 0;
     $arPrefixes = array_map(array("CBitrixCloudCDN", "_preg_quote"), self::$config->getLocationsPrefixes());
     $arExtensions = array_map(array("CBitrixCloudCDN", "_preg_quote"), self::$config->getLocationsExtensions());
     if (!empty($arPrefixes) && !empty($arExtensions)) {
         $prefix_regex = "(?:" . implode("|", $arPrefixes) . ")";
         $extension_regex = "(?:" . implode("|", $arExtensions) . ")";
         $regex = "/\n\t\t\t\t((?i:\n\t\t\t\t\thref=\n\t\t\t\t\t|src=\n\t\t\t\t\t|BX\\.loadCSS\\(\n\t\t\t\t\t|BX\\.loadScript\\(\n\t\t\t\t\t|jsUtils\\.loadJSFile\\(\n\t\t\t\t\t|background\\s*:\\s*url\\(\n\t\t\t\t))                                                   #attribute\n\t\t\t\t(\"|')                                               #open_quote\n\t\t\t\t(" . $prefix_regex . ")                                  #prefix\n\t\t\t\t([^?'\"]+\\.)                                        #href body\n\t\t\t\t(" . $extension_regex . ")                               #extension\n\t\t\t\t(|\\?\\d+|\\?v=\\d+)                                 #params\n\t\t\t\t(\\2)                                                #close_quote\n\t\t\t/x";
         $content = preg_replace_callback($regex, array("CBitrixCloudCDN", "_filter"), $content);
     }
 }
Пример #2
0
 /**
  *
  * @param string &$content
  * @return void
  *
  */
 public function OnEndBufferContent(&$content)
 {
     if (isset($_GET["nocdn"])) {
         return;
     }
     $appCache = \Bitrix\Main\Data\AppCacheManifest::getInstance();
     if ($appCache->isEnabled()) {
         return;
     }
     self::$proto = CMain::IsHTTPS() ? "https" : "http";
     self::$config = CBitrixCloudCDNConfig::getInstance()->loadFromOptions();
     if (self::$config->isExpired()) {
         if (!self::updateConfig()) {
             return;
         }
     }
     if (!self::$config->isActive()) {
         return;
     }
     $sites = self::$config->getSites();
     $siteId = defined("ADMIN_SECTION") ? "admin" : (defined("SITE_ID") ? SITE_ID : "");
     if (!isset($sites[$siteId])) {
         return;
     }
     self::$ajax = preg_match("/<head>/i", substr($content, 0, 1024)) === 0;
     $arPrefixes = array_map(array("CBitrixCloudCDN", "_preg_quote"), self::$config->getLocationsPrefixes(self::$config->isKernelRewriteEnabled(), self::$config->isContentRewriteEnabled()));
     $arExtensions = array_map(array("CBitrixCloudCDN", "_preg_quote"), self::$config->getLocationsExtensions());
     if (!empty($arPrefixes) && !empty($arExtensions)) {
         $prefix_regex = "(?:" . implode("|", $arPrefixes) . ")";
         $extension_regex = "(?i:" . implode("|", $arExtensions) . ")";
         $regex = "/\n\t\t\t\t((?i:\n\t\t\t\t\thref=\n\t\t\t\t\t|src=\n\t\t\t\t\t|BX\\.loadCSS\\(\n\t\t\t\t\t|BX\\.loadScript\\(\n\t\t\t\t\t|BX\\.getCDNPath\\(\n\t\t\t\t\t|jsUtils\\.loadJSFile\\(\n\t\t\t\t\t|background\\s*:\\s*url\\(\n\t\t\t\t\t|image\\s*:\\s*url\\(\n\t\t\t\t\t|'SRC':\n\t\t\t\t))                                                   #attribute\n\t\t\t\t(\"|')                                               #open_quote\n\t\t\t\t(" . $prefix_regex . ")                                  #prefix\n\t\t\t\t([^?'\"]+\\.)                                        #href body\n\t\t\t\t(" . $extension_regex . ")                               #extension\n\t\t\t\t(|\\?\\d+|\\?v=\\d+)                                 #params\n\t\t\t\t(\\2)                                                #close_quote\n\t\t\t/x";
         $content = preg_replace_callback($regex, array("CBitrixCloudCDN", "_filter"), $content);
     }
 }