1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
remotedictionary.php
См. документацию.
1<?php
8
9namespace Bitrix\Rest\Dictionary;
10
11use Bitrix\Main\Application;
12use Bitrix\Main\ArgumentException;
13use Bitrix\Main\Event;
14use Bitrix\Main\Loader;
15use Bitrix\Main\Localization\Loc;
16use Bitrix\Main\Type\Dictionary;
17use Bitrix\Main\Web\HttpClient;
18use Bitrix\Main\Web\Json;
19use Bitrix\Main\Web\Uri;
20
22{
23 const ID = 'generic';
24
25 const CACHE_TTL = 86400;
26 const CACHE_PREFIX = 'rest_dictionary_v2';
27
28 protected $baseUrl = array(
29 'ru' => 'https://www.bitrix24.ru/util/',
30 'ua' => 'https://www.bitrix24.eu/util/',
31 'by' => 'https://www.bitrix24.by/util/',
32 'in' => 'https://www.bitrix24.in/util/',
33 'en' => 'https://www.bitrix24.com/util/',
34 'de' => 'https://www.bitrix24.de/util/',
35 'kz' => 'https://www.bitrix24.kz/util/',
36 'br' => 'https://www.bitrix24.com.br/util/',
37 'pl' => 'https://www.bitrix24.pl/util/',
38 'fr' => 'https://www.bitrix24.fr/util/',
39 'la' => 'https://www.bitrix24.es/util/',
40 'eu' => 'https://www.bitrix24.eu/util/',
41 'cn' => 'https://www.bitrix24.cn/util/',
42 'tc' => 'https://www.bitrix24.cn/util/',
43 'sc' => 'https://www.bitrix24.cn/util/',
44 'tr' => 'https://www.bitrix24.com.tr/util/',
45 );
46 protected $language = null;
47
48 public function __construct()
49 {
50 $this->language = LANGUAGE_ID;
51
52 $values = $this->init();
53
54 parent::__construct($values);
55 }
56
57 public function setLanguage($language)
58 {
59 if($language !== $this->language)
60 {
61 $this->language = $language;
62 $this->set($this->init());
63 }
64 }
65
66 protected function init()
67 {
68 $managedCache = Application::getInstance()->getManagedCache();
69 if($managedCache->read(static::CACHE_TTL, $this->getCacheId()))
70 {
71 $dictionary = $managedCache->get($this->getCacheId());
72 }
73 else
74 {
75 $dictionary = $this->load();
76
77 $managedCache->set($this->getCacheId(), $dictionary);
78 }
79
80 $event = new Event('rest', 'onRemoteDictionaryLoad', array(
81 'ID' => static::ID,
82 'DICTIONARY' => &$dictionary
83 ));
84 $event->send();
85
86 return $dictionary;
87 }
88
89 protected function load()
90 {
91 $httpClient = new HttpClient();
92
93 $uri = $this->getDictionaryUri();
94
95 $httpResult = $httpClient->get($uri->getLocator());
96
97 try
98 {
99 $result = Json::decode($httpResult);
100 }
101 catch(ArgumentException $e)
102 {
103 $result = null;
104 }
105
106 return $result;
107 }
108
109 protected function getCacheId()
110 {
111 return static::CACHE_PREFIX.'/'.static::ID.'/'.$this->language;
112 }
113
118 protected function getDictionaryUri()
119 {
120 $lang = Application::getInstance()->getLicense()->getRegion();
121
122 $baseUrl = array_key_exists($lang, $this->baseUrl)
123 ? $this->baseUrl[$lang]
124 : $this->baseUrl[Loc::getDefaultLang($lang)];
125
126 $uri = new Uri($baseUrl);
127 $uri->addParams(array(
128 'type' => static::ID,
129 'lng' => $this->language,
130 ));
131
132 return $uri;
133 }
134}
Определения event.php:5
Определения uri.php:17
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
if(!defined('SITE_ID')) $lang
Определения include.php:91
$event
Определения prolog_after.php:141