1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
googlesource.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Source\Google;
4
5use Bitrix\Location\Common\Pool;
6use Bitrix\Location\Entity\Source;
7use Bitrix\Location\Repository\Location\IRepository;
8use Bitrix\Location\Common\CachedPool;
9use Bitrix\Location\StaticMap\ISourceStaticMapService;
10use Bitrix\Main\Data\Cache;
11use Bitrix\Main\EventManager;
12use Bitrix\Main\Web\HttpClient;
13use Bitrix\Main\Config\Option;
14use Bitrix\Main\Loader;
15use Bitrix\Fileman;
16
22class GoogleSource extends Source
23{
27 public function makeRepository(): IRepository
28 {
29 static $result = null;
30
31 if (!is_null($result))
32 {
33 return $result;
34 }
35
36 $httpClient = new HttpClient(
37 [
38 'version' => '1.1',
39 'socketTimeout' => 30,
40 'streamTimeout' => 30,
41 'redirect' => true,
42 'redirectMax' => 5,
43 ]
44 );
45
46 $cacheTTL = 2592000; //month
47 $poolSize = 100;
48 $pool = new Pool($poolSize);
49
50 $cachePool = new CachedPool(
51 $pool,
52 $cacheTTL,
53 'locationSourceGoogleRequester',
54 Cache::createInstance(),
55 EventManager::getInstance()
56 );
57
58 $result = new Repository(
59 $this->getBackendKey(),
60 $httpClient,
61 $this,
62 $cachePool
63 );
64
65 return $result;
66 }
67
69 {
70 return (new SourceStaticMapService($this))->setBackendKey($this->getBackendKey());
71 }
72
76 public function getJSParams(): array
77 {
78 return [
79 'apiKey' => $this->getFrontendKey(),
80 'showPhotos' => $this->config->getValue('SHOW_PHOTOS_ON_MAP'),
81 'useGeocodingService' => $this->config->getValue('USE_GEOCODING_SERVICE'),
82 ];
83 }
84
85 private function getBackendKey(): string
86 {
87 $configKey = $this->config->getValue('API_KEY_BACKEND');
88 if ($configKey)
89 {
90 return (string)$configKey;
91 }
92
93 return (string)Option::get('location', 'google_map_api_key_backend', '');
94 }
95
96 private function getFrontendKey(): string
97 {
98 $key = $this->config->getValue('API_KEY_FRONTEND');
99 if ($key)
100 {
101 return (string)$key;
102 }
103
104 $key = Option::get('location', 'google_map_api_key', '');
105 if ($key !== '')
106 {
107 return (string)$key;
108 }
109
110 if (Loader::includeModule('fileman'))
111 {
112 $key = Fileman\UserField\Types\AddressType::getApiKey();
113 if ($key !== '' && !is_null($key))
114 {
115 return $key;
116 }
117 }
118
119 return '';
120 }
121
127 public function convertLang(string $bitrixLang): string
128 {
129 $langMap = [
130 'br' => 'pt-BR', // Portuguese (Brazil)
131 'la' => 'es', // Spanish
132 'sc' => 'zh-CN', // Chinese (Simplified)
133 'tc' => 'zh-TW', // Chinese (Traditional)
134 'vn' => 'vi', // Vietnamese
135 'ua' => 'uk', // Ukrainian
136 ];
137
138 return $langMap[$bitrixLang] ?? $bitrixLang;
139 }
140
141 public function isAvailable(): bool
142 {
143 return $this->getBackendKey() && $this->getFrontendKey();
144 }
145}
convertLang(string $bitrixLang)
Определения googlesource.php:127
</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(empty($signedUserToken)) $key
Определения quickway.php:257