1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
audiocall.php
См. документацию.
1<?php
8
10
13
18
19Loc::loadMessages(__FILE__);
20
26{
27 const AUDIO_DIR = 'https://dl.bitrix24.com/sender/audiocall/';
28 const RU_AUDIO_DIR = 'https://repos.1c-bitrix.ru/sender/audiocall/';
29 const METADATA_FILE = 'https://dl.bitrix24.com/sender/audiocall/metadata.json';
30 const RU_METADATA_FILE = 'https://repos.1c-bitrix.ru/sender/audiocall/metadata.json';
31
32 public static function getAudioDir()
33 {
34 if (\Bitrix\Sender\Integration\Bitrix24\Service::isRegionRussian(true))
35 {
36 return self::RU_AUDIO_DIR;
37 }
38
39 return static::AUDIO_DIR;
40 }
41
42 public static function getMetadataFile()
43 {
44 if (\Bitrix\Sender\Integration\Bitrix24\Service::isRegionRussian(true))
45 {
46 return self::RU_METADATA_FILE;
47 }
48
49 return static::METADATA_FILE;
50 }
51
55 public static function getSupportedLangs()
56 {
57 $data = self::getMetadata();
58 return $data ? $data['langs'] : [];
59 }
60
69 public static function onPresetTemplateList($templateType = null, $templateId = null, $messageCode = null)
70 {
71 if ($templateType && $templateType !== 'BASE')
72 {
73 return array();
74 }
75 if ($messageCode && $messageCode !== Message\iBase::CODE_AUDIO_CALL)
76 {
77 return array();
78 }
79
80 return static::getTemplates($templateId);
81 }
82
88 public static function getAudioFileUrlByCode($code)
89 {
90 if (!self::presetExists($code))
91 {
92 return false;
93 }
94 $filePath = static::getAudioDir() . static::getCodeWithLang($code) . '.mp3';
95 return $filePath;
96 }
97
103 public static function presetExists($code)
104 {
106 }
107
113 public static function getDurationByCode($code)
114 {
115 $code = self::getCodeWithLang($code);
116 $data = self::getMetadata();
117 return $data['durations'][$code] ?? false;
118 }
119
124 public static function getDefaultCode()
125 {
126 $messageCode = Message\iBase::CODE_AUDIO_CALL;
127 foreach (Texts::getListByType($messageCode) as $item)
128 {
129 $code = mb_strtolower($item['CODE']);
130 if (self::presetExists($code))
131 {
132 return $code;
133 }
134 }
135 return false;
136 }
137
143 private static function getCodeWithLang($code)
144 {
145 $lang = self::getLang();
146 return $lang . '_' . $code;
147 }
148
153 private static function getLang()
154 {
155 $lang = mb_strtolower(LANGUAGE_ID);
156 $supportedLangs = static::getSupportedLangs();
157 $lang = in_array($lang, $supportedLangs) ? $lang : array_shift($supportedLangs);
158 return $lang;
159 }
160
166 private static function getTemplates($templateId = null)
167 {
168 $result = [];
169 $messageCode = Message\iBase::CODE_AUDIO_CALL;
170
171 foreach (Texts::getListByType($messageCode) as $item)
172 {
173 $code = mb_strtolower($item['CODE']);
174 $presetCode = mb_strtolower($messageCode."_".$code);
175 if (!self::presetExists($code))
176 {
177 continue;
178 }
179 if($templateId && $presetCode !== $templateId)
180 {
181 continue;
182 }
183
184 $result[] = array(
185 'ID' => $presetCode,
186 'TYPE' => Type::getCode(Type::BASE),
187 'MESSAGE_CODE' => array($messageCode),
188 'VERSION' => 2,
189 'HOT' => $item['HOT'],
190 'ICON' => $item['ICON'],
191
192 'NAME' => $item['NAME'],
193 'DESC' => $item['DESC'],
194 'FIELDS' => array(
195 'AUDIO_FILE' => [
196 'CODE' => 'AUDIO_FILE',
197 'VALUE' => static::getAudioFileUrlByCode($code),
198 ],
199 ),
200 );
201 }
202
203 return $result;
204 }
205
211 private static function getMetadata()
212 {
213 static $failed = false;
214 if ($failed)
215 {
216 return false;
217 }
218
219 $cacheTtl = 86400; // 24 hours
220 $cacheId = 'sender_audiocall_metadata';
221 $cachePath = '/sender/audiocall_metadata/';
222 $cache = \Bitrix\Main\Application::getInstance()->getCache();
223 if($cache->initCache($cacheTtl, $cacheId, $cachePath))
224 {
225 return $cache->getVars();
226 }
227 else
228 {
229 $result = false;
230
231 $cache->startDataCache();
232
233 $request = new HttpClient([
234 "socketTimeout" => 5,
235 "streamTimeout" => 5,
236 ]);
237 $request->get(static::getMetadataFile());
238 if($request->getStatus() == 200)
239 {
240 try
241 {
242 $result = Json::decode($request->getResult());
243 }
244 catch (ArgumentException $e)
245 {
246 }
247 }
248 if (is_array($result))
249 {
250 $cache->endDataCache($result);
251 }
252 else
253 {
254 $failed = true;
255 $cache->abortDataCache();
256 }
257 return $result;
258 }
259 }
260}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
getCode()
Определения error.php:54
Определения json.php:9
static getDurationByCode($code)
Определения audiocall.php:113
static getAudioFileUrlByCode($code)
Определения audiocall.php:88
static onPresetTemplateList($templateType=null, $templateId=null, $messageCode=null)
Определения audiocall.php:69
static presetExists($code)
Определения audiocall.php:103
static getListByType($type)
Определения texts.php:64
$templateId
Определения component_props2.php:51
$data['IS_AVAILABLE']
Определения .description.php:13
</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
const CODE_AUDIO_CALL
Определения ibase.php:23
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(!defined('SITE_ID')) $lang
Определения include.php:91
Определения collection.php:2
Определения adapter.php:9