PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/main.site.selector/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 91 lines | 80 code | 11 blank | 0 comment | 27 complexity | b33243ab4c720a1c20b6cfbb20f69138 MD5 | raw file
  1. <?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?><?
  2. if (!is_array($arParams["SITE_LIST"]) || count($arParams["SITE_LIST"]) == 0 || $arParams["SITE_LIST"][0] == "*all*")
  3. {
  4. $bSiteAll = true;
  5. $arParams["SITE_LIST"] = array();
  6. }
  7. else
  8. {
  9. $bSiteAll = false;
  10. }
  11. $arParams["CACHE_TIME"] = is_set($arParams, "CACHE_TIME") ? intval($arParams["CACHE_TIME"]) : 86400;
  12. $bCache = $arParams["CACHE_TIME"] > 0 && ($arParams["CACHE_TYPE"] == "Y" || ($arParams["CACHE_TYPE"] == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "Y"));
  13. if ($bCache)
  14. {
  15. $arCacheParams = array();
  16. foreach ($arParams as $key => $value) if (mb_substr($key, 0, 1) != "~") $arCacheParams[$key] = $value;
  17. $cache = new CPHPCache;
  18. $CACHE_ID = SITE_ID."|".$componentName."|".md5(serialize($arCacheParams))."|".$USER->GetGroups();
  19. $CACHE_PATH = "/".SITE_ID.CComponentEngine::MakeComponentPath($componentName);
  20. }
  21. if ($bCache && $cache->InitCache($arParams["CACHE_TIME"], $CACHE_ID, $CACHE_PATH))
  22. {
  23. $vars = $cache->GetVars();
  24. $arResult = $vars["arResult"];
  25. }
  26. else
  27. {
  28. if ($bCache)
  29. {
  30. $cache->StartDataCache();
  31. }
  32. $extranetSiteId = (
  33. IsModuleInstalled('extranet')
  34. ? COption::GetOptionString("extranet", "extranet_site")
  35. : false
  36. );
  37. $rsSite = CSite::GetList("sort", "asc", $arFilter=array("ACTIVE" => "Y"));
  38. $arResult["SITES"] = array();
  39. while ($arSite = $rsSite->GetNext())
  40. {
  41. if (
  42. (
  43. !$extranetSiteId
  44. || $arSite["LID"] != $extranetSiteId
  45. )
  46. && (
  47. $bSiteAll
  48. || in_array($arSite["LID"], $arParams["SITE_LIST"])
  49. )
  50. )
  51. {
  52. if ($arSite['DOMAINS'] <> '')
  53. {
  54. $arSite['DOMAINS'] = explode("\n", $arSite['DOMAINS']);
  55. foreach ($arSite['DOMAINS'] as $key => $domain)
  56. {
  57. $arSite['DOMAINS'][$key] = trim($domain);
  58. }
  59. }
  60. $arResult["SITES"][] = array(
  61. "LID" => $arSite["LID"],
  62. "NAME" => $arSite["NAME"],
  63. "LANG" => $arSite["LANGUAGE_ID"],
  64. "DIR" => $arSite["DIR"],
  65. "DOMAINS" => $arSite["DOMAINS"],
  66. "CURRENT" => $arSite["LID"] == SITE_ID ? "Y" : "N",
  67. );
  68. }
  69. }
  70. if ($bCache)
  71. {
  72. $cache->EndDataCache(
  73. array(
  74. "arResult" => $arResult,
  75. )
  76. );
  77. }
  78. }
  79. $this->IncludeComponentTemplate();
  80. ?>