1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
app.php
См. документацию.
1<?php
8
9namespace Bitrix\Im;
10
11use Bitrix\ImBot\Bot\Giphy;
12use Bitrix\Main,
13 Bitrix\Main\Localization\Loc,
14 Bitrix\Main\DB\Exception;
15Loc::loadMessages(__FILE__);
16
17class App
18{
19 const CACHE_TTL = 31536000;
20 const CACHE_PATH = '/bx/im/app/';
21
22 public static function register(array $fields)
23 {
24 $moduleId = $fields['MODULE_ID'];
25 if ($moduleId == '')
26 {
27 return false;
28 }
29
30 $iframe = '';
31 $iframeWidth = 350;
32 $iframeHeight = 250;
33 $iframePopup = 'N';
34 $jscommand = isset($fields['JS'])? $fields['JS']: '';
35
36 if (isset($fields['IFRAME']) && $fields['IFRAME'])
37 {
38 $check = parse_url($fields['IFRAME']);
39 if (!isset($check['scheme']) && !isset($check['host']))
40 {
41 if (mb_strpos($fields['IFRAME'], '/desktop_app/iframe/') !== 0)
42 {
43 return false;
44 }
45 }
46 else if (!in_array($check['scheme'], Array('http', 'https')) || empty($check['host']))
47 {
48 return false;
49 }
50 $iframe = $fields['IFRAME'].(isset($check['query'])? '&': '?');
51 if (isset($fields['IFRAME_WIDTH']))
52 {
53 $iframeWidth = intval($fields['IFRAME_WIDTH']) > 250? $fields['IFRAME_WIDTH']: 250;
54 }
55 if (isset($fields['IFRAME_HEIGHT']))
56 {
57 $iframeHeight = intval($fields['IFRAME_HEIGHT']) > 50? $fields['IFRAME_HEIGHT']: 50;
58 }
59 $iframePopup = isset($fields['IFRAME_POPUP']) && $fields['IFRAME_POPUP'] == 'Y'? 'Y': $iframePopup;
60 }
61 else if (!$jscommand)
62 {
63 return false;
64 }
65
66 $code = $fields['CODE'];
67 if (!$code)
68 {
69 return false;
70 }
71
72 $iconFileId = intval($fields['ICON_ID']);
73
74 $botId = isset($fields['BOT_ID'])? intval($fields['BOT_ID']): 0;
75 $hash = isset($fields['HASH']) && !empty($fields['HASH'])? mb_substr($fields['HASH'], 0, 32) : md5($botId.$fields['CODE'].\CMain::GetServerUniqID());
76 $context = isset($fields['CONTEXT'])? $fields['CONTEXT']: 'ALL';
77 $registered = isset($fields['REGISTERED']) && $fields['REGISTERED'] == 'N'? 'N': 'Y';
78 $hidden = isset($fields['HIDDEN']) && $fields['HIDDEN'] == 'Y'? 'Y': 'N';
79 if ($botId > 0 && (!\Bitrix\Im\User::getInstance($botId)->isExists() || !\Bitrix\Im\User::getInstance($botId)->isBot()))
80 {
81 $botId = 0;
82 }
83
84 $extranetSupport = isset($fields['EXTRANET_SUPPORT']) && $fields['EXTRANET_SUPPORT'] == 'Y'? 'Y': 'N';
85 $livechatSupport = isset($fields['LIVECHAT_SUPPORT']) && $fields['LIVECHAT_SUPPORT'] == 'Y'? 'Y': 'N';
86
87 /* vars for module install */
88 $class = isset($fields['CLASS'])? $fields['CLASS']: '';
89 $methodLangGet = isset($fields['METHOD_LANG_GET'])? $fields['METHOD_LANG_GET']: '';
90
91 /* vars for rest install */
92 $restAppId = isset($fields['APP_ID'])? $fields['APP_ID']: '';
93 $langSet = isset($fields['LANG'])? $fields['LANG']: Array();
94
95 if ($moduleId == 'rest')
96 {
97 if (empty($langSet))
98 {
99 return false;
100 }
101 }
102 else
103 {
104 if (empty($class) || empty($methodLangGet))
105 {
106 return false;
107 }
108 }
109
110 $apps = self::getListCache();
111 foreach ($apps as $cmd)
112 {
113 if ($botId)
114 {
115 if ($botId == $cmd['BOT_ID'] && $code == $cmd['CODE'])
116 {
117 return $cmd['ID'];
118 }
119 }
120 else if ($restAppId)
121 {
122 if ($restAppId == $cmd['APP_ID'] && $code == $cmd['CODE'])
123 {
124 return $cmd['ID'];
125 }
126 }
127 else if ($moduleId == $cmd['MODULE_ID'] && $code == $cmd['CODE'])
128 {
129 return $cmd['ID'];
130 }
131 }
132
133 $result = \Bitrix\Im\Model\AppTable::add(Array(
134 'HASH' => $hash,
135 'BOT_ID' => $botId,
136 'MODULE_ID' => $moduleId,
137 'CODE' => $code,
138 'ICON_FILE_ID' => $iconFileId,
139 'CONTEXT' => mb_strtolower($context),
140 'HIDDEN' => $hidden,
141 'REGISTERED' => $registered,
142 'IFRAME' => $iframe,
143 'IFRAME_WIDTH' => $iframeWidth,
144 'IFRAME_HEIGHT' => $iframeHeight,
145 'IFRAME_POPUP' => $iframePopup,
146 'JS' => $jscommand,
147 'EXTRANET_SUPPORT' => $extranetSupport,
148 'LIVECHAT_SUPPORT' => $livechatSupport,
149 'CLASS' => $class,
150 'METHOD_LANG_GET' => $methodLangGet,
151 'APP_ID' => $restAppId
152 ));
153
154 if (!$result->isSuccess())
155 return false;
156
157 $cache = \Bitrix\Main\Data\Cache::createInstance();
158 $cache->cleanDir(self::CACHE_PATH);
159
160 $appId = $result->getId();
161
162 if ($moduleId == 'rest')
163 {
164 foreach ($langSet as $lang)
165 {
166 if (!isset($lang['LANGUAGE_ID']) || empty($lang['LANGUAGE_ID']))
167 continue;
168
169 if (!isset($lang['TITLE']) && empty($lang['TITLE']))
170 continue;
171
172 try
173 {
174 \Bitrix\Im\Model\AppLangTable::add(array(
175 'APP_ID' => $appId,
176 'LANGUAGE_ID' => mb_strtolower($lang['LANGUAGE_ID']),
177 'TITLE' => $lang['TITLE'],
178 'DESCRIPTION' => $lang['DESCRIPTION'],
179 'COPYRIGHT' => $lang['COPYRIGHT']
180 ));
181 }
182 catch(Exception $e)
183 {
184 }
185 }
186 }
187
188 return $appId;
189 }
190
191 public static function unRegister(array $app)
192 {
193 $appId = intval($app['ID']);
194 $moduleId = isset($app['MODULE_ID'])? $app['MODULE_ID']: '';
195 $restAppId = isset($app['APP_ID'])? $app['APP_ID']: '';
196
197 if (intval($appId) <= 0)
198 return false;
199
200 if (!isset($app['FORCE']) || $app['FORCE'] == 'N')
201 {
202 $icons = self::getListCache();
203 if (!isset($icons[$appId]))
204 return false;
205
206 if ($moduleId <> '' && $icons[$appId]['MODULE_ID'] != $moduleId)
207 return false;
208
209 if ($restAppId <> '' && $icons[$appId]['APP_ID'] != $restAppId)
210 return false;
211 }
212
213 \Bitrix\Im\Model\AppTable::delete($appId);
214
215 $orm = \Bitrix\Im\Model\AppLangTable::getList(Array(
216 'filter' => Array('=APP_ID' => $appId)
217 ));
218 while ($row = $orm->fetch())
219 {
220 \Bitrix\Im\Model\AppLangTable::delete($row['ID']);
221 }
222
223 $cache = \Bitrix\Main\Data\Cache::createInstance();
224 $cache->cleanDir(self::CACHE_PATH);
225
226 if (\Bitrix\Main\Loader::includeModule('pull'))
227 {
228 \CPullStack::AddShared(Array(
229 'module_id' => 'im',
230 'command' => 'appDeleteIcon',
231 'params' => Array(
232 'iconId' => $appId
233 ),
234 'extra' => \Bitrix\Im\Common::getPullExtra()
235 ));
236 }
237
238 return true;
239 }
240
241 public static function update(array $app, array $updateFields)
242 {
243 $appId = intval($app['ID']);
244 $userId = intval($app['USER_ID']);
245 $moduleId = isset($app['MODULE_ID'])? $app['MODULE_ID']: '';
246 $restAppId = isset($app['APP_ID'])? $app['APP_ID']: '';
247
248 if (intval($appId) <= 0)
249 return false;
250
251 $apps = self::getListCache();
252 if (!isset($apps[$appId]))
253 return false;
254
255 if ($moduleId <> '' && $apps[$appId]['MODULE_ID'] != $moduleId)
256 return false;
257
258 if ($restAppId <> '' && $apps[$appId]['APP_ID'] != $restAppId)
259 return false;
260
261 if (isset($updateFields['LANG']) && $apps[$appId]['MODULE_ID'] == 'rest')
262 {
263 $orm = \Bitrix\Im\Model\AppLangTable::getList(Array(
264 'filter' => Array('=APP_ID' => $appId)
265 ));
266 while ($row = $orm->fetch())
267 {
268 \Bitrix\Im\Model\AppLangTable::delete($row['ID']);
269 }
270 foreach ($updateFields['LANG'] as $lang)
271 {
272 if (!isset($lang['LANGUAGE_ID']) || empty($lang['LANGUAGE_ID']))
273 continue;
274
275 if (!isset($lang['TITLE']) && empty($lang['TITLE']))
276 continue;
277
278 try
279 {
280 \Bitrix\Im\Model\AppLangTable::add(array(
281 'APP_ID' => $appId,
282 'LANGUAGE_ID' => mb_strtolower($lang['LANGUAGE_ID']),
283 'TITLE' => $lang['TITLE'],
284 'DESCRIPTION' => $lang['DESCRIPTION'],
285 'COPYRIGHT' => $lang['COPYRIGHT']
286 ));
287 }
288 catch(Exception $e)
289 {
290 }
291 }
292 }
293
294 $update = Array();
295 if (isset($updateFields['CONTEXT']) && !empty($updateFields['CONTEXT']))
296 {
297 $update['CONTEXT'] = mb_strtolower($updateFields['CONTEXT']);
298 }
299 if (isset($updateFields['HASH']) && !empty($updateFields['HASH']))
300 {
301 $update['HASH'] = $updateFields['HASH'];
302 }
303 if (isset($updateFields['HIDDEN']))
304 {
305 $update['HIDDEN'] = $updateFields['HIDDEN'] == 'Y'? 'Y': 'N';
306 }
307 if (isset($updateFields['REGISTERED']))
308 {
309 $update['REGISTERED'] = $updateFields['REGISTERED'] == 'N'? 'N': 'Y';
310 }
311 if (isset($updateFields['IFRAME']) && !empty($updateFields['IFRAME']))
312 {
313 $check = parse_url($updateFields['IFRAME']);
314 if (!isset($check['scheme']) && !isset($check['host']))
315 {
316 if (mb_strpos($updateFields['IFRAME'], '/desktop_app/iframe/') !== 0)
317 {
318 return false;
319 }
320 }
321 else if (!in_array($check['scheme'], Array('http', 'https')) || empty($check['host']))
322 {
323 return false;
324 }
325 $update['IFRAME'] = $updateFields['IFRAME'].(isset($check['query'])? '&': '?');
326 }
327 else if (isset($updateFields['JS']) && !empty($updateFields['JS']))
328 {
329 $update['JS'] = $updateFields['JS'];
330 }
331 if (isset($updateFields['IFRAME_WIDTH']))
332 {
333 $update['IFRAME_WIDTH'] = intval($updateFields['IFRAME_WIDTH']) > 250? intval($updateFields['IFRAME_WIDTH']): 250;
334 }
335 if (isset($updateFields['IFRAME_HEIGHT']))
336 {
337 $update['IFRAME_HEIGHT'] = intval($updateFields['IFRAME_HEIGHT']) > 50? intval($updateFields['IFRAME_HEIGHT']): 50;
338 }
339 if (isset($updateFields['IFRAME_POPUP']))
340 {
341 $update['IFRAME_POPUP'] = $updateFields['IFRAME_POPUP'] == 'Y'? 'Y': 'N';
342 }
343 if (isset($updateFields['ICON_ID']) && $updateFields['ICON_ID'])
344 {
345 $update['ICON_FILE_ID'] = intval($updateFields['ICON_ID']);
346 }
347 if (isset($updateFields['CLASS']) && !empty($updateFields['CLASS']))
348 {
349 $update['CLASS'] = $updateFields['CLASS'];
350 }
351 if (isset($updateFields['METHOD_LANG_GET']))
352 {
353 $update['METHOD_LANG_GET'] = $updateFields['METHOD_LANG_GET'];
354 }
355 if (isset($updateFields['EXTRANET_SUPPORT']))
356 {
357 $update['EXTRANET_SUPPORT'] = $updateFields['EXTRANET_SUPPORT'] == 'Y'? 'Y': 'N';
358 }
359 if (isset($updateFields['LIVECHAT_SUPPORT']))
360 {
361 $update['LIVECHAT_SUPPORT'] = $updateFields['LIVECHAT_SUPPORT'] == 'Y'? 'Y': 'N';
362 }
363
364 if (!empty($update))
365 {
366 \Bitrix\Im\Model\AppTable::update($appId, $update);
367
368 $cache = \Bitrix\Main\Data\Cache::createInstance();
369 $cache->cleanDir(self::CACHE_PATH);
370 }
371
372 if (\Bitrix\Main\Loader::includeModule('pull'))
373 {
374 if (
375 $update['REGISTERED']
376 || $update['DOMAIN_HASH']
377 || $update['CONTEXT']
378 || $update['IFRAME']
379 || $update['JS']
380 || $update['IFRAME_WIDTH']
381 || $update['IFRAME_HEIGHT']
382 || $update['IFRAME_POPUP']
383 )
384 {
385 \CPullStack::AddShared(Array(
386 'module_id' => 'im',
387 'command' => 'appUpdateIcon',
388 'params' => Array(
389 'iconId' => $appId,
390 'userId' => $userId,
391 'domainHash' => $update['HASH'],
392 'context' => $update['CONTEXT'],
393 'js' => $update['JS'],
394 'iframe' => $update['IFRAME'],
395 'iframeWidth' => $update['IFRAME_WIDTH'],
396 'iframeHeight' => $update['IFRAME_HEIGHT'],
397 'iframePopup' => $update['IFRAME_POPUP'],
398 ),
399 'extra' => \Bitrix\Im\Common::getPullExtra()
400 ));
401 }
402 else if ($update['ICON_ID'])
403 {
404 }
405 else
406 {
407 \CPullStack::AddShared(Array(
408 'module_id' => 'im',
409 'command' => 'appDeleteIcon',
410 'params' => Array(
411 'iconId' => $appId
412 ),
413 'extra' => \Bitrix\Im\Common::getPullExtra()
414 ));
415 }
416 }
417
418 return true;
419 }
420
421 public static function addToken(array $params)
422 {
423 $botId = intval($params['BOT_ID']);
424 $userId = intval($params['USER_ID']);
425
426 if (!$botId && !$userId || empty($params['DIALOG_ID']))
427 {
428 return false;
429 }
430
431 Bot\Token::add($botId, $params['DIALOG_ID']);
432 Bot\Token::add($userId, $params['DIALOG_ID']);
433
434 if (!Common::isChatId($params['DIALOG_ID']))
435 {
436 Bot\Token::add($botId, $params['USER_ID']);
437 }
438
439 return true;
440 }
441
442 public static function addMessage(array $app, array $messageFields)
443 {
444 $appId = intval($app['ID']);
445 $moduleId = isset($app['MODULE_ID'])? $app['MODULE_ID']: '';
446 $restAppId = isset($app['APP_ID'])? $app['APP_ID']: '';
447
448 if ($appId <= 0)
449 return false;
450
451 $apps = self::getListCache();
452 if (!isset($apps[$appId]))
453 return false;
454
455 if ($moduleId <> '' && $apps[$appId]['MODULE_ID'] != $moduleId)
456 return false;
457
458 if ($restAppId <> '' && $apps[$appId]['APP_ID'] != $restAppId)
459 return false;
460
461 $botId = intval($apps[$appId]['BOT_ID']);
462
463 if (Common::isChatId($messageFields['DIALOG_ID']))
464 {
465 $chatId = \Bitrix\Im\Dialog::getChatId($messageFields['DIALOG_ID']);
466 $relations = \CIMChat::GetRelationById($chatId, false, true, false);
467 }
468 else
469 {
470 $userId = intval($messageFields['DIALOG_ID']);
471 if (!$userId || $botId == $userId)
472 {
473 return false;
474 }
475 $relations = \CIMChat::GetPrivateRelation($botId, $userId);
476 }
477
478 if ($botId && !Bot\Token::isActive($botId, $messageFields['DIALOG_ID']))
479 {
480 return false;
481 }
482
483 $messageFields['ATTACH'] = $messageFields['ATTACH']? $messageFields['ATTACH']: null;
484 $messageFields['KEYBOARD'] = $messageFields['KEYBOARD']? $messageFields['KEYBOARD']: null;
485
486 $fromUserId = isset($messageFields['FROM_USER_ID'])? $messageFields['FROM_USER_ID']: $botId;
487
488 if (Common::isChatId($messageFields['DIALOG_ID']))
489 {
490 $chatId = \Bitrix\Im\Dialog::getChatId($messageFields['DIALOG_ID']);
491 if ($chatId <= 0)
492 return false;
493
494 if (isset($relations[$fromUserId]) && $messageFields['SYSTEM'] != 'Y')
495 {
496 $ar = Array(
497 "FROM_USER_ID" => $fromUserId,
498 "TO_CHAT_ID" => $chatId,
499 "ATTACH" => $messageFields['ATTACH'],
500 "KEYBOARD" => $messageFields['KEYBOARD'],
501 );
502 if (isset($messageFields['MESSAGE']))
503 {
504 $ar['MESSAGE'] = $messageFields['MESSAGE'];
505 }
506 }
507 else
508 {
509 $ar = Array(
510 "FROM_USER_ID" => isset($relations[$fromUserId])? $fromUserId: 0,
511 "TO_CHAT_ID" => $chatId,
512 "ATTACH" => $messageFields['ATTACH'],
513 "KEYBOARD" => $messageFields['KEYBOARD'],
514 "SYSTEM" => 'Y',
515 );
516 if (isset($messageFields['MESSAGE']))
517 {
518 $ar['MESSAGE'] = $messageFields['MESSAGE'];
519 }
520
521 $ar['MESSAGE'] = "[B]".$apps[$appId]['TITLE']."[/B]\n".$ar['MESSAGE'];
522 }
523
524 if (isset($messageFields['URL_PREVIEW']) && $messageFields['URL_PREVIEW'] == 'N')
525 {
526 $ar['URL_PREVIEW'] = 'N';
527 }
528
529 $ar['SKIP_USER_CHECK'] = 'Y';
530 $ar['SKIP_COMMAND'] = 'Y';
531
532 $id = \CIMChat::AddMessage($ar);
533 }
534 else
535 {
536 $userId = intval($messageFields['DIALOG_ID']);
537 \CModule::IncludeModule('imbot');
538
539 if (isset($relations[$fromUserId]) && $messageFields['SYSTEM'] != 'Y')
540 {
541 $ar = Array(
542 "FROM_USER_ID" => $fromUserId,
543 "TO_USER_ID" => $userId,
544 "ATTACH" => $messageFields['ATTACH'],
545 "KEYBOARD" => $messageFields['KEYBOARD'],
546 );
547 if (isset($messageFields['MESSAGE']))
548 {
549 $ar['MESSAGE'] = $messageFields['MESSAGE'];
550 }
551 }
552 else
553 {
554 $ar = Array(
555 "FROM_USER_ID" => isset($relations[$fromUserId])? $fromUserId: 0,
556 "TO_USER_ID" => $userId,
557 "ATTACH" => $messageFields['ATTACH'],
558 "KEYBOARD" => $messageFields['KEYBOARD'],
559 "SYSTEM" => "Y",
560 );
561 if (isset($messageFields['MESSAGE']))
562 {
563 $ar['MESSAGE'] = $messageFields['MESSAGE'];
564 }
565
566 $ar['MESSAGE'] = "[B]".$apps[$appId]['TITLE']."[/B]\n".$ar['MESSAGE'];
567 }
568
569 if (isset($messageFields['URL_PREVIEW']) && $messageFields['URL_PREVIEW'] == 'N')
570 {
571 $ar['URL_PREVIEW'] = 'N';
572 }
573
574 $ar['SKIP_COMMAND'] = 'Y';
575 $id = \CIMMessage::Add($ar);
576 }
577
578 return $id;
579 }
580
581 public static function getListCache($lang = LANGUAGE_ID)
582 {
583 $cache = \Bitrix\Main\Data\Cache::createInstance();
584 if($cache->initCache(self::CACHE_TTL, 'list_v3_'.$lang, self::CACHE_PATH))
585 {
586 $result = $cache->getVars();
587 }
588 else
589 {
590 $loadRestLang = false;
591 $result = Array();
592 $orm = \Bitrix\Im\Model\AppTable::getList();
593 while ($row = $orm->fetch())
594 {
595 if ($row['ICON_FILE_ID'])
596 {
597 $image = \CFile::ResizeImageGet(
598 $row['ICON_FILE_ID'],
599 array('width' => 108, 'height' => 66),
601 false,
602 false,
603 true
604 );
605 $row['ICON_URL'] = empty($image['src'])? '': $image['src'];
606 }
607 else
608 {
609 $row['ICON_URL'] = '';
610 }
611
612 if (!empty($row['CLASS']) && !empty($row['METHOD_LANG_GET']))
613 {
614 if (\Bitrix\Main\Loader::includeModule($row['MODULE_ID']) && class_exists($row["CLASS"]) && method_exists($row["CLASS"], $row["METHOD_LANG_GET"]))
615 {
616 $localize = call_user_func_array(array($row["CLASS"], $row["METHOD_LANG_GET"]), Array($row['CODE'], $lang));
617 if ($localize)
618 {
619 $row['TITLE'] = $localize['TITLE'];
620 $row['DESCRIPTION'] = $localize['DESCRIPTION'];
621 $row['COPYRIGHT'] = $localize['COPYRIGHT'];
622 }
623 else
624 {
625 $row['METHOD_LANG_GET'] = '';
626 }
627 }
628 else
629 {
630 $row['METHOD_LANG_GET'] = '';
631 }
632 }
633 else
634 {
635 $row['TITLE'] = '';
636 $row['DESCRIPTION'] = '';
637 $row['COPYRIGHT'] = '';
638
639 if ($row['MODULE_ID'] == 'rest')
640 {
641 $loadRestLang = true;
642 }
643 }
644 $result[$row['ID']] = $row;
645 }
646
647 if ($loadRestLang)
648 {
649 $langSet = Array();
650 $orm = \Bitrix\Im\Model\AppLangTable::getList();
651 while ($row = $orm->fetch())
652 {
653 if (!isset($result[$row['APP_ID']]))
654 continue;
655
656 $langSet[$row['APP_ID']][$row['LANGUAGE_ID']]['TITLE'] = $row['TITLE'];
657 $langSet[$row['APP_ID']][$row['LANGUAGE_ID']]['DESCRIPTION'] = $row['DESCRIPTION'];
658 $langSet[$row['APP_ID']][$row['LANGUAGE_ID']]['COPYRIGHT'] = $row['COPYRIGHT'];
659 }
660
661 $langAlter = \Bitrix\Im\Bot::getDefaultLanguage();
662 foreach ($result as $appId => $commandData)
663 {
664 if (isset($langSet[$appId][$lang]))
665 {
666 $result[$appId]['TITLE'] = $langSet[$appId][$lang]['TITLE'];
667 $result[$appId]['DESCRIPTION'] = $langSet[$appId][$lang]['DESCRIPTION'];
668 $result[$appId]['COPYRIGHT'] = $langSet[$appId][$lang]['COPYRIGHT'];
669 }
670 else if (isset($langSet[$appId][$langAlter]))
671 {
672 $result[$appId]['TITLE'] = $langSet[$appId][$langAlter]['TITLE'];
673 $result[$appId]['DESCRIPTION'] = $langSet[$appId][$langAlter]['DESCRIPTION'];
674 $result[$appId]['COPYRIGHT'] = $langSet[$appId][$langAlter]['COPYRIGHT'];
675 }
676 else if (isset($langSet[$appId]))
677 {
678 $langSetCommand = array_values($langSet[$appId]);
679 $result[$appId]['TITLE'] = $langSetCommand[0]['TITLE'];
680 $result[$appId]['DESCRIPTION'] = $langSetCommand[0]['DESCRIPTION'];
681 $result[$appId]['COPYRIGHT'] = $langSetCommand[0]['COPYRIGHT'];
682 }
683 }
684
685 foreach ($result as $key => $value)
686 {
687 if (empty($value['TITLE']))
688 {
689 $row['METHOD_LANG_GET'] = '';
690 }
691 }
692 }
693
694 $cache->startDataCache();
695 $cache->endDataCache($result);
696 }
697
699 }
700
701 protected static function filterList(array $list): array
702 {
703 if (!Main\Loader::includeModule('imbot') || !Giphy::getBotId() || Giphy::isAvailable())
704 {
705 return $list;
706 }
707
708 foreach ($list as $appId => $app)
709 {
710 if ((int)$app['BOT_ID'] === Giphy::getBotId())
711 {
712 $list[$appId]['HIDDEN'] = 'Y';
713 }
714 }
715
716 return $list;
717 }
718
719 public static function getListForJs($lang = LANGUAGE_ID)
720 {
721 $apps = self::getListCache($lang);
722
723 $userId = $GLOBALS['USER']? $GLOBALS['USER']->GetId(): 0;
724 $isExtranet = $userId && \Bitrix\Im\User::getInstance($userId)->isExtranet();
725 $isConnector = $userId && \Bitrix\Im\User::getInstance($userId)->isConnector();
726
727 $result = Array();
728 foreach ($apps as $app)
729 {
730 if ($isConnector && $app['LIVECHAT_SUPPORT'] != 'Y')
731 continue;
732 else if ($isExtranet && $app['EXTRANET_SUPPORT'] != 'Y')
733 continue;
734
735 $botData = \Bitrix\Im\Bot::getCache($app['BOT_ID']);
736 $result[] = Array(
737 'id' => $app['ID'],
738 'botId' => $app['BOT_ID'],
739 'botCode' => htmlspecialcharsbx($botData['CODE'] ?? ''),
740 'domainHash' => self::getDomainHash($app['HASH']),
741 'userHash' => self::getUserHash($userId, $app['HASH']),
742 'code' => htmlspecialcharsbx($app['CODE']),
743 'url' => $app['ICON_URL'],
744 'iframe' => $app['IFRAME'],
745 'iframeWidth' => $app['IFRAME_WIDTH'],
746 'iframeHeight' => $app['IFRAME_HEIGHT'],
747 'iframePopup' => $app['IFRAME_POPUP'] == 'Y',
748 'js' => $app['JS'],
749 'context' => mb_strtolower($app['CONTEXT']),
750 'hidden' => $app['HIDDEN'] == 'Y',
751 'title' => $app['TITLE'],
752 'description' => $app['DESCRIPTION'],
753 'copyright' => $app['COPYRIGHT'],
754 );
755 }
756
757 return $result;
758 }
759
760 public static function getUserHash($userId, $hash = 'register')
761 {
762 if ($hash == 'register')
763 $result = md5($userId.\CMain::GetServerUniqID());
764 else
765 $result = md5($userId.$hash);
766
767 return $result;
768 }
769
770 public static function getDomainHash($hash)
771 {
772 $result = md5($_SERVER['SERVER_NAME'].$hash);
773
774 return $result;
775 }
776
777 public static function clearCache()
778 {
779 $cache = \Bitrix\Main\Data\Cache::createInstance();
780 $cache->cleanDir(self::CACHE_PATH);
781
782 return true;
783 }
784}
$hash
Определения ajax_redirector.php:8
$messageFields
Определения callback_ednaru.php:22
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения app.php:18
static getDomainHash($hash)
Определения app.php:770
const CACHE_PATH
Определения app.php:20
static update(array $app, array $updateFields)
Определения app.php:241
static getListCache($lang=LANGUAGE_ID)
Определения app.php:581
static getUserHash($userId, $hash='register')
Определения app.php:760
static addMessage(array $app, array $messageFields)
Определения app.php:442
static getListForJs($lang=LANGUAGE_ID)
Определения app.php:719
const CACHE_TTL
Определения app.php:19
static addToken(array $params)
Определения app.php:421
static unRegister(array $app)
Определения app.php:191
static filterList(array $list)
Определения app.php:701
static clearCache()
Определения app.php:777
static add($botId, $dialogId)
Определения token.php:27
static isChatId($id)
Определения common.php:58
static getPullExtra()
Определения common.php:127
static getChatId($dialogId, $userId=null)
Определения dialog.php:93
static getInstance($userId=null)
Определения user.php:45
static Add($arFields)
Определения im_message.php:28
</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
$moduleId
$app
Определения proxy.php:8
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
const BX_RESIZE_IMAGE_PROPORTIONAL
Определения constants.php:11
if(!defined('SITE_ID')) $lang
Определения include.php:91
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
Определения contextmenu.php:9
$GLOBALS['____1690880296']
Определения license.php:1
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$fields
Определения yandex_run.php:501