/** * Returns proxy class instance (singleton pattern) * * @return CBitrixCloudCDNConfig * */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new CBitrixCloudCDNConfig(); } return self::$instance; }
/** * Shows information about CDN free space in Admin's informer popup * * @return void */ public function OnAdminInformerInsertItems() { if (IsModuleInstalled('intranet')) { return; } $CDNAIParams = array("TITLE" => GetMessage("BCL_CDN_AI_TITLE"), "COLOR" => "green"); if (self::IsActive()) { $CDNAIParams["FOOTER"] = '<a href="/bitrix/admin/bitrixcloud_cdn.php?lang=' . LANGUAGE_ID . '">' . GetMessage("BCL_CDN_AI_SETT") . '</a>'; $cdn_config = CBitrixCloudCDNConfig::getInstance()->loadFromOptions(); $cdn_quota = $cdn_config->getQuota(); $PROGRESS_TOTAL = $cdn_quota->getAllowedSize(); $PROGRESS_VALUE = $cdn_quota->getTrafficSize(); if ($PROGRESS_TOTAL > 0.0 || $PROGRESS_VALUE > 0.0) { $PROGRESS_AVAILABLE = $PROGRESS_TOTAL - $PROGRESS_VALUE; if ($PROGRESS_AVAILABLE < 0.0) { $PROGRESS_AVAILABLE = 0.0; } $PROGRESS_FREE = 0.0; if ($PROGRESS_TOTAL > 0.0) { $PROGRESS_FREE = round(($PROGRESS_TOTAL - $PROGRESS_VALUE) / $PROGRESS_TOTAL * 100); } $PROGRESS_FREE_BAR = $PROGRESS_FREE > 100.0 ? 100 : intval($PROGRESS_FREE); $PROGRESS_FREE_BAR = $PROGRESS_FREE < 0.0 ? 0 : intval($PROGRESS_FREE_BAR); $CDNAIParams["ALERT"] = false; if ($PROGRESS_FREE < 10.0) { $CDNAIParams["ALERT"] = true; } elseif (!$cdn_config->isActive()) { $CDNAIParams["ALERT"] = true; } $CDNAIParams["HTML"] = ' <div class="adm-informer-item-section"> <span class="adm-informer-item-l"> <span class="adm-informer-strong-text">' . GetMessage("BCL_CDN_AI_USAGE_TOTAL") . '</span> ' . CFile::FormatSize($PROGRESS_TOTAL, 0) . ' </span> <span class="adm-informer-item-r"> <span class="adm-informer-strong-text">' . GetMessage("BCL_CDN_AI_USAGE_AVAIL") . '</span> ' . CFile::FormatSize($PROGRESS_AVAILABLE, 0) . ' </span> </div> <div class="adm-informer-status-bar-block" > <div class="adm-informer-status-bar-indicator" style="width:' . (100 - $PROGRESS_FREE_BAR) . '%; "></div> <div class="adm-informer-status-bar-text">' . (100 - $PROGRESS_FREE) . '%</div> </div> '; } } else { $CDNAIParams["HTML"] = ' <div class="adm-informer-item-section"> <span class="adm-informer-strong-text">' . GetMessage("BCL_CDN_AI_IS_OFF") . '</span> </div> <div class="adm-informer-status-bar-block" > <div class="adm-informer-status-bar-indicator" style="width:0%; "></div> <div class="adm-informer-status-bar-text">0%</div> </div> '; $CDNAIParams["ALERT"] = true; $CDNAIParams["FOOTER"] = '<a href="/bitrix/admin/bitrixcloud_cdn.php?lang=' . LANGUAGE_ID . '">' . GetMessage("BCL_CDN_AI_TURN_ON") . '</a>'; } CAdminInformer::AddItem($CDNAIParams); }
$message = new CAdminMessage(GetMessage("BCL_DISABLE_ERROR"), $e); } } } } } if (is_object($message)) { $bVarsFromForm = true; } else { if (isset($_POST["save"]) && $_GET["return_url"] != "") { LocalRedirect($_GET["return_url"]); } LocalRedirect("/bitrix/admin/bitrixcloud_cdn.php?lang=" . LANGUAGE_ID . ($_GET["return_url"] ? "&return_url=" . urlencode($_GET["return_url"]) : "") . "&" . $tabControl->ActiveTabParam()); } } $cdn_config = CBitrixCloudCDNConfig::getInstance()->loadFromOptions(); $APPLICATION->SetTitle(GetMessage("BCL_TITLE")); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php"; if (is_object($message)) { echo $message->Show(); } if (CBitrixCloudCDN::IsActive()) { try { if ($cdn_config->getQuota()->isExpired()) { $cdn_config->updateQuota(); } $cdn_quota = $cdn_config->getQuota(); if ($cdn_quota->getAllowedSize() > 0.0 || $cdn_quota->getTrafficSize() > 0.0) { CAdminMessage::ShowMessage(array("TYPE" => "PROGRESS", "DETAILS" => '<p><b>' . GetMessage("BCL_CDN_USAGE", array("#TRAFFIC#" => CFile::FormatSize($cdn_quota->getTrafficSize()), "#ALLOWED#" => CFile::FormatSize($cdn_quota->getAllowedSize()))) . '</b></p>#PROGRESS_BAR#', "HTML" => true, "PROGRESS_TOTAL" => $cdn_quota->getAllowedSize(), "PROGRESS_VALUE" => $cdn_quota->getTrafficSize())); } } catch (Exception $e) {
/** * * @param string $name * @param string $value * @param CBitrixCloudCDNConfig $config * @return CBitrixCloudCDNLocation * */ public static function fromOptionValue($name, $value, CBitrixCloudCDNConfig $config) { $values = unserialize($value); $proto = ""; $prefixes = array(); $services = array(); if (is_array($values)) { if (isset($values["prefixes"]) && is_array($values["prefixes"])) { foreach ($values["prefixes"] as $prefix) { $prefixes[] = $prefix; } } if (isset($values["services"]) && is_array($values["services"])) { $services = $values["services"]; } if (isset($values["proto"])) { $proto = $values["proto"]; } } $location = new CBitrixCloudCDNLocation($name, $proto, $prefixes); foreach ($services as $file_class => $server_group) { $location->addService($config->getClassByName($file_class), $config->getServerGroupByName($server_group)); } return $location; }