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