1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
im_message_param.php
См. документацию.
1<?
2use Bitrix\Im as IM;
3use Bitrix\Main\UrlPreview as UrlPreview;
4
6{
7 public static function Set($messageId, $params = Array())
8 {
9 $messageId = intval($messageId);
10 if(!(is_array($params) || is_null($params)) || $messageId <= 0)
11 return false;
12
13 if (is_null($params) || count($params) <= 0)
14 {
15 return self::DeleteAll($messageId);
16 }
17
18 $default = self::GetDefault();
19
20 $arToDelete = array();
21 foreach ($params as $key => $val)
22 {
23 if (isset($default[$key]) && $default[$key] == $val)
24 {
25 $arToDelete[$key] = array(
26 "=MESSAGE_ID" => $messageId,
27 "=PARAM_NAME" => $key,
28 );
29 }
30 }
31
32 $arToInsert = array();
33 foreach($params as $k1 => $v1)
34 {
35 $name = mb_substr(trim($k1), 0, 100);
36 if($name <> '')
37 {
38 if(is_object($v1) && $v1 instanceof \Bitrix\Im\Bot\Keyboard)
39 {
40 $v1 = array($v1);
41 }
42 else
43 {
44 if(is_object($v1) && $v1 instanceof \Bitrix\Im\Bot\ContextMenu)
45 {
46 $v1 = array($v1);
47 }
48 else
49 {
50 if(is_object($v1) && $v1 instanceof CIMMessageParamAttach)
51 {
52 $v1 = array($v1);
53 }
54 else
55 {
56 if(is_object($v1) && $v1 instanceof \Bitrix\Main\Type\DateTime)
57 {
58 $v1 = array($v1->getTimestamp());
59 }
60 else
61 {
62 if(is_array($v1) && \Bitrix\Main\Type\Collection::isAssociative($v1))
63 {
64 $v1 = array($v1);
65 }
66 else
67 {
68 if(!is_array($v1))
69 {
70 $v1 = array($v1);
71 }
72 }
73 }
74 }
75 }
76 }
77
78 if(empty($v1))
79 {
80 $arToDelete[$name] = array(
81 "=MESSAGE_ID" => $messageId,
82 "=PARAM_NAME" => $name,
83 );
84 }
85 else
86 {
87 foreach($v1 as $v2)
88 {
89 if(is_array($v2))
90 {
92 if($value <> '' && mb_strlen($value) < 60000)
93 {
94 $key = md5($name.$value);
95 $arToInsert[$key] = array(
96 "MESSAGE_ID" => $messageId,
97 "PARAM_NAME" => $name,
98 "PARAM_VALUE" => isset($v2['ID'])? $v2['ID'] : time(),
99 "PARAM_JSON" => $value,
100 );
101 }
102 }
103 else
104 {
105 if(is_object($v2) && ($v2 instanceof \Bitrix\Im\Bot\Keyboard || $v2 instanceof \Bitrix\Im\Bot\ContextMenu))
106 {
107 $value = $v2->getJson();
108 if($value <> '')
109 {
110 $key = md5($name.$value);
111 $arToInsert[$key] = array(
112 "MESSAGE_ID" => $messageId,
113 "PARAM_NAME" => $name,
114 "PARAM_VALUE" => "",
115 "PARAM_JSON" => $value,
116 );
117 }
118 }
119 else
120 {
121 if(is_object($v2) && $v2 instanceof CIMMessageParamAttach)
122 {
123 $value = $v2->GetJSON();
124 $valueArray = $v2->GetArray();
125 if($value <> '')
126 {
127 $description = $valueArray['DESCRIPTION'];
128 if (mb_strlen($description) > 100)
129 {
130 $description = mb_substr($description, 0, 97) . '...';
131 }
132 $key = md5($name.$value);
133 $arToInsert[$key] = array(
134 "MESSAGE_ID" => $messageId,
135 "PARAM_NAME" => $name,
136 "PARAM_VALUE" => $description,
137 "PARAM_JSON" => $value,
138 );
139 }
140 }
141 else
142 {
143 $value = mb_substr(trim($v2), 0, 100);
144 if($value <> '')
145 {
146 $key = md5($name.$value);
147 $arToInsert[$key] = array(
148 "MESSAGE_ID" => $messageId,
149 "PARAM_NAME" => $name,
150 "PARAM_VALUE" => $value,
151 );
152 }
153 }
154 }
155 }
156 }
157 }
158 }
159 }
160
161 if(!empty($arToInsert))
162 {
163 $messageParameters = IM\Model\MessageParamTable::getList(array(
164 'select' => array('ID', 'PARAM_NAME', 'PARAM_VALUE', 'PARAM_JSON'),
165 'filter' => array(
166 '=MESSAGE_ID' => $messageId,
167 ),
168 ));
169 while($ar = $messageParameters->fetch())
170 {
171 if ($ar['PARAM_JSON'] <> '')
172 {
173 $key = md5($ar["PARAM_NAME"].$ar["PARAM_JSON"]);
174 }
175 else
176 {
177 $key = md5($ar["PARAM_NAME"].$ar["PARAM_VALUE"]);
178 }
179 if(array_key_exists($key, $arToInsert))
180 {
181 unset($arToInsert[$key]);
182 }
183 else if (isset($params[$ar["PARAM_NAME"]]))
184 {
185 IM\Model\MessageParamTable::delete($ar['ID']);
186 }
187 }
188 }
189
190 foreach($arToInsert as $parameterInfo)
191 {
192 if (in_array($parameterInfo["PARAM_NAME"], Array('KEYBOARD', 'MENU', 'ATTACH', 'NAME', 'IMOL_VOTE_TEXT', 'IMOL_VOTE_LIKE', 'IMOL_VOTE_DISLIKE')))
193 {
194 $parameterInfo['PARAM_VALUE'] = \Bitrix\Im\Text::encodeEmoji($parameterInfo['PARAM_VALUE']);
195 }
196
197 if (isset($parameterInfo['PARAM_VALUE']) && mb_strlen($parameterInfo['PARAM_VALUE']) > 100)
198 {
199 $parameterInfo['PARAM_VALUE'] = mb_substr($parameterInfo['PARAM_VALUE'], 0, 97) . '...';
200 }
201
202 IM\Model\MessageParamTable::add($parameterInfo);
203 }
204
205 foreach($arToDelete as $filter)
206 {
207 $messageParameters = IM\Model\MessageParamTable::getList(array(
208 'select' => array('ID'),
209 'filter' => $filter,
210 ));
211 while ($parameterInfo = $messageParameters->fetch())
212 {
213 IM\Model\MessageParamTable::delete($parameterInfo['ID']);
214 }
215 }
216
217 return true;
218 }
219
220 public static function SendPull($messageId, $sendExtraParams = true)
221 {
222 global $DB;
223
224 if (!CModule::IncludeModule('pull'))
225 return false;
226
227 $messageId = intval($messageId);
228
229 $sql = "
230 SELECT
231 C.ID as CHAT_ID,
232 C.PARENT_ID as CHAT_PARENT_ID,
233 C.TYPE as MESSAGE_TYPE,
234 M.AUTHOR_ID,
235 C.ENTITY_TYPE as CHAT_ENTITY_TYPE,
236 C.ENTITY_ID as CHAT_ENTITY_ID,
237 C.LAST_MESSAGE_ID as CHAT_LAST_MESSAGE_ID
238 FROM b_im_message M INNER JOIN b_im_chat C ON M.CHAT_ID = C.ID
239 WHERE M.ID = ".$messageId."
240 ";
241 $messageData = $DB->Query($sql)->Fetch();
242 if (!$messageData)
243 return false;
244
245 $arPullMessage = Array(
246 'id' => (int)$messageId,
247 'type' => $messageData['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE? 'private': 'chat',
248 );
249
250 $relations = CIMMessenger::GetRelationById($messageId);
251
252 if ($messageData['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE)
253 {
254 $arFields['FROM_USER_ID'] = $messageData['AUTHOR_ID'];
255 foreach ($relations as $rel)
256 {
257 if ($rel['USER_ID'] != $messageData['AUTHOR_ID'])
258 $arFields['TO_USER_ID'] = $rel['USER_ID'];
259 }
260
261 $arPullMessage['fromUserId'] = (int)$arFields['FROM_USER_ID'];
262 $arPullMessage['toUserId'] = (int)$arFields['TO_USER_ID'];
263 $arPullMessage['chatId'] = (int)$messageData['CHAT_ID'];
264 }
265 else
266 {
267 $arPullMessage['chatId'] = (int)$messageData['CHAT_ID'];
268 $arPullMessage['senderId'] = (int)$messageData['AUTHOR_ID'];
269
270 if ($messageData['CHAT_ENTITY_TYPE'] == 'LINES')
271 {
272 foreach ($relations as $rel)
273 {
274 if ($rel["EXTERNAL_AUTH_ID"] == 'imconnector')
275 {
276 unset($relations[$rel["USER_ID"]]);
277 }
278 }
279 }
280 }
281
282 $arMessages[$messageId] = Array();
283 $params = CIMMessageParam::Get(Array($messageId), false, $sendExtraParams === true);
284 $arMessages[$messageId]['params'] = $params[$messageId];
285
286 if (is_array($sendExtraParams) && !empty($sendExtraParams))
287 {
288 $arDefault = CIMMessageParam::GetDefault();
289 foreach($sendExtraParams as $key)
290 {
291 if (!isset($arMessages[$messageId]['params'][$key]))
292 {
293 $arMessages[$messageId]['params'][$key] = $arDefault[$key];
294 }
295 }
296 }
297
298 $arMessages = CIMMessageLink::prepareShow($arMessages, $params);
299 $arPullMessage['params'] = CIMMessenger::PrepareParamsForPull($arMessages[$messageId]['params']);
300 $pull = [
301 'module_id' => 'im',
302 'command' => 'messageParamsUpdate',
303 'params' => $arPullMessage,
305 ];
306
307 if ($messageData['MESSAGE_TYPE'] === IM\V2\Chat::IM_TYPE_COMMENT)
308 {
309 CPullWatch::AddToStack('IM_PUBLIC_COMMENT_'.$messageData['CHAT_PARENT_ID'], $pull);
310 }
311 else
312 {
313 \Bitrix\Pull\Event::add(array_keys($relations), $pull);
314 }
315
316 if (CIMMessenger::needToSendPublicPull($messageData['MESSAGE_TYPE']))
317 {
318 CPullWatch::AddToStack('IM_PUBLIC_'.$messageData['CHAT_ID'], $pull);
319 }
320 if ($messageData['MESSAGE_TYPE'] === IM\V2\Chat::IM_TYPE_OPEN_CHANNEL && (int)$messageId === (int)$messageData['CHAT_LAST_MESSAGE_ID'])
321 {
322 IM\V2\Chat\OpenChannelChat::sendSharedPull($pull);
323 }
324
325 return true;
326 }
327
328 public static function DeleteAll($messageId)
329 {
330 $messageId = intval($messageId);
331 if ($messageId <= 0)
332 return false;
333
334 $messageParameters = IM\Model\MessageParamTable::getList(array(
335 'select' => array('ID', 'PARAM_NAME'),
336 'filter' => array(
337 '=MESSAGE_ID' => $messageId,
338 ),
339 ));
340 while ($parameterInfo = $messageParameters->fetch())
341 {
342 IM\Model\MessageParamTable::delete($parameterInfo['ID']);
343 }
344
345 return true;
346 }
347
348 public static function DeleteByParam($paramName, $paramValue)
349 {
350 if ($paramName == '' || $paramValue == '')
351 {
352 return false;
353 }
354
355 $messageParameters = IM\Model\MessageParamTable::getList(array(
356 'select' => array('ID', 'MESSAGE_ID'),
357 'filter' => array(
358 '=PARAM_NAME' => $paramName,
359 '=PARAM_VALUE' => $paramValue,
360 ),
361 ));
362 while ($parameterInfo = $messageParameters->fetch())
363 {
364 IM\Model\MessageParamTable::delete($parameterInfo['ID']);
365 }
366
367 return true;
368 }
369
370 public static function Get($messageId, $paramName = false, $withDefault = false)
371 {
372 $arResult = array();
373 if (is_array($messageId))
374 {
375 if (!empty($messageId))
376 {
377 foreach ($messageId as $key => $value)
378 {
379 $messageId[$key] = intval($value);
380 $arResult[$messageId[$key]] = Array();
381 }
382 }
383 else
384 {
385 return $arResult;
386 }
387 }
388 else
389 {
390 $messageId = intval($messageId);
391 if ($messageId <= 0)
392 {
393 return false;
394 }
395 $arResult[$messageId] = Array();
396 }
397
398 $filter = array(
399 '=MESSAGE_ID' => $messageId,
400 );
401 if ($paramName && $paramName <> '')
402 {
403 $filter['=PARAM_NAME'] = $paramName;
404 }
405 $messageParameters = IM\Model\MessageParamTable::getList(array(
406 'select' => array('ID', 'MESSAGE_ID', 'PARAM_NAME', 'PARAM_VALUE', 'PARAM_JSON'),
407 'filter' => $filter,
408 ));
409 while($ar = $messageParameters->fetch())
410 {
411 if (in_array($ar["PARAM_NAME"], Array('KEYBOARD', 'MENU', 'ATTACH', 'NAME', 'IMOL_VOTE_TEXT', 'IMOL_VOTE_LIKE', 'IMOL_VOTE_DISLIKE', 'IMOL_COMMENT_HEAD')))
412 {
413 $ar['PARAM_VALUE'] = \Bitrix\Im\Text::decodeEmoji($ar['PARAM_VALUE']);
414 }
415
416 if ($ar["PARAM_JSON"] <> '')
417 {
418 try
419 {
420 $value = \Bitrix\Main\Web\Json::decode($ar["PARAM_JSON"]);
421 }
422 catch (\Bitrix\Main\SystemException $e)
423 {
424 }
425 }
426 else
427 {
428 $value = $ar["PARAM_VALUE"];
429 }
430 if (in_array($ar["PARAM_NAME"], Array('KEYBOARD', 'MENU', 'COMPONENT_PARAMS')))
431 {
432 $arResult[$ar["MESSAGE_ID"]][$ar["PARAM_NAME"]] = $value;
433 }
434 else
435 {
436 $arResult[$ar["MESSAGE_ID"]][$ar["PARAM_NAME"]][] = $value;
437 }
438 }
439
440 if (is_array($messageId))
441 {
442 foreach ($messageId as $key)
443 {
444 $arResult[$key] = self::PrepareValues($arResult[$key], $withDefault);
445 }
446 }
447 else
448 {
449 $arResult = self::PrepareValues($arResult[$messageId], $withDefault);
450 }
451
452 if ($paramName)
453 {
454 $arResult = isset($arResult[$paramName])? $arResult[$paramName]: null;
455 }
456
457 return $arResult;
458 }
459
460 public static function GetMessageIdByParam($paramName, $paramValue, $chatId = null)
461 {
462 $arResult = Array();
463 if ($paramName == '' || $paramValue == '')
464 {
465 return $arResult;
466 }
467 $filter = array(
468 '=PARAM_NAME' => $paramName,
469 '=PARAM_VALUE' => $paramValue,
470 );
471 if ($chatId)
472 {
473 $filter['=MESSAGE.CHAT_ID'] = $chatId;
474 }
475
476 $messageParameters = IM\Model\MessageParamTable::getList(array(
477 'select' => array('MESSAGE_ID'),
478 'filter' => $filter,
479 ));
480 while($ar = $messageParameters->fetch())
481 {
482 $arResult[] = $ar["MESSAGE_ID"];
483 }
484
485 return $arResult;
486 }
487
488 public static function PrepareValues($values, $withDefault = false)
489 {
490 $arValues = Array();
491
492 $arDefault = self::GetDefault();
493 foreach($values as $key => $value)
494 {
495 if (in_array($key, Array('IS_ERROR', 'IS_DELIVERED', 'IS_DELETED', 'BETA', 'IS_EDITED', 'CAN_ANSWER', 'IMOL_QUOTE_MSG', 'SENDING', 'URL_ONLY', 'LARGE_FONT', 'CRM_FORM_FILLED')))
496 {
497 $arValues[$key] = in_array($value[0], Array('Y', 'N'))? $value[0]: $arDefault[$key];
498 }
499 else if (in_array($key, Array('KEYBOARD_UID')))
500 {
501 $arValues[$key] = intval($value);
502 }
503 else if (in_array($key, Array('CALL_ID', 'CHAT_ID', 'CHAT_MESSAGE', 'IMOL_VOTE_SID', 'IMOL_VOTE_USER', 'IMOL_VOTE_HEAD', 'SENDING_TS', 'IMOL_SID')))
504 {
505 $arValues[$key] = intval($value[0]);
506 }
507 else if (in_array($key, Array('CHAT_LAST_DATE')))
508 {
509 if (is_object($value) && $value instanceof \Bitrix\Main\Type\DateTime)
510 {
511 $arValues[$key] = $value;
512 }
513 else if (is_object($value[0]) && $value[0] instanceof \Bitrix\Main\Type\DateTime)
514 {
515 $arValues[$key] = $value[0];
516 }
517 else
518 {
520 }
521 }
522 else if ($key == 'DATE_TEXT')
523 {
524 if (is_array($value) && !empty($value))
525 {
526 foreach ($value as $k => $v)
527 {
529 }
530 }
531 else if (!is_array($value))
532 {
534 }
535 else
536 {
537 $arValues[$key] = $arDefault[$key];
538 }
539 }
540 else if ($key == 'CHAT_USER' || $key == 'DATE_TS' || $key == 'FILE_ID' || $key == 'LIKE' || $key == 'FAVORITE' || $key == 'KEYBOARD_ACTION' || $key == 'URL_ID' || $key == 'LINK_ACTIVE' || $key == 'USERS')
541 {
542 if (is_array($value) && !empty($value))
543 {
544 foreach ($value as $k => $v)
545 {
546 $arValues[$key][$k] = intval($v);
547 }
548 }
549 else if (!is_array($value) && intval($value) > 0)
550 {
551 $arValues[$key] = intval($value);
552 }
553 else
554 {
555 $arValues[$key] = $arDefault[$key];
556 }
557 }
558 else if ($key == 'CONNECTOR_MID')
559 {
560 if (is_array($value) && !empty($value))
561 {
562 foreach ($value as $k => $v)
563 {
564 $arValues[$key][$k] = $v;
565 }
566 }
567 else if (!is_array($value) && $value <> '')
568 {
569 $arValues[$key] = $value;
570 }
571 else
572 {
573 $arValues[$key] = $arDefault[$key];
574 }
575 }
576 else if ($key == 'NOTIFY')
577 {
578 if ($value === 'N')
579 {
580 $arValues[$key] = $value;
581 }
582 else if (is_array($value))
583 {
584 if (empty($value) || count($value) === 1 && $value[0] === 'N')
585 {
586 $arValues[$key] = 'N';
587 }
588 else
589 {
590 foreach ($value as $k => $v)
591 {
592 $arValues[$key][$k] = intval($v);
593 }
594 }
595 }
596 else
597 {
598 $arValues[$key] = $arDefault[$key];
599 }
600 }
601 else if ($key == 'ATTACH')
602 {
603 if (isset($value))
604 {
605 $arValues[$key] = CIMMessageParamAttach::PrepareAttach($value);
606 }
607 else
608 {
609 $arValues[$key] = $arDefault[$key];
610 }
611 }
612 else if (
613 $key == 'TYPE' ||
614 $key == 'COMPONENT_ID' ||
615 $key == 'CLASS' ||
616 $key == 'IMOL_VOTE' ||
617 $key == 'IMOL_VOTE_TEXT' ||
618 $key == 'IMOL_VOTE_LIKE' ||
619 $key == 'IMOL_VOTE_DISLIKE' ||
620 $key == 'IMOL_FORM' ||
621 $key == 'IMOL_COMMENT_HEAD' ||
622 $key == 'IMOL_DATE_CLOSE_VOTE' ||
623 $key == 'IMOL_TIME_LIMIT_VOTE' ||
624 $key == 'CRM_FORM_ID' ||
625 $key == 'CRM_FORM_SEC'
626 )
627 {
628 $arValues[$key] = isset($value[0])? $value[0]: '';
629 }
630 else if ($key == 'CONNECTOR_MID')
631 {
632 $arValues[$key] = $value;
633 }
634 else if ($key == 'NAME')
635 {
636 $arValues[$key] = isset($value[0])? htmlspecialcharsbx($value[0]): $arDefault[$key];
637 }
638 else if ($key == 'USER_ID')
639 {
640 $arValues[$key] = isset($value[0])? intval($value[0]): $arDefault[$key];
641 }
642 else if ($key == 'AVATAR')
643 {
644 if (isset($value))
645 {
646 $arValues[$key] = CIMChat::GetAvatarImage($value[0], 200, false);
647 }
648 else
649 {
650 $arValues[$key] = $arDefault[$key];
651 }
652 }
653 else if (isset($arDefault[$key]))
654 {
655 $arValues[$key] = $value;
656 }
657 }
658
659 if ($withDefault)
660 {
661 foreach($arDefault as $key => $value)
662 {
663 if (!isset($arValues[$key]))
664 {
665 $arValues[$key] = $value;
666 }
667 }
668 }
669 else
670 {
671 foreach($arDefault as $key => $value)
672 {
673 if (isset($arValues[$key]) && $arValues[$key] == $value)
674 {
675 unset($arValues[$key]);
676 }
677 }
678 }
679
680 return $arValues;
681 }
682
683 public static function GetDefault()
684 {
685 $arDefault = [
686 'TYPE' => '',
687 'COMPONENT_ID' => '',
688 'COMPONENT_PARAMS' => [],
689 'CODE' => '',
690 'FAVORITE' => [],
691 'LIKE' => [],
692 'FILE_ID' => [],
693 'URL_ID' => [],
694 'URL_ONLY' => 'N',
695 'ATTACH' => [],
696 'LINK_ACTIVE' => [],
697 'LARGE_FONT' => 'N',
698 'NOTIFY' => 'Y',
699 'MENU' => 'N',
700 'KEYBOARD' => 'N',
701 'KEYBOARD_UID' => 0,
702 'CONNECTOR_MID' => [],
703 'IS_ERROR' => 'N',
704 'IS_DELIVERED' => 'Y',
705 'IS_DELETED' => 'N',
706 'IS_EDITED' => 'N',
707 'BETA' => 'N',
708 'SENDING' => 'N',
709 'SENDING_TS' => 0,
710 'CAN_ANSWER' => 'N',
711 'IS_PINNED' => 'N',
712 'CLASS' => '',
713 'CALL_ID' => 0,
714 'FORWARD_ID' => 0,
715 'USER_ID' => '',
716 'NAME' => '',
717 'AVATAR' => '',
718 'CHAT_ID' => 0,
719 'CHAT_MESSAGE' => 0,
720 'CHAT_LAST_DATE' => '',
721 'CHAT_USER' => [],
722 'DATE_TEXT' => [],
723 'DATE_TS' => [],
724 'IMOL_VOTE' => '',
725 'IMOL_VOTE_TEXT' => '',
726 'IMOL_VOTE_LIKE' => '',
727 'IMOL_VOTE_DISLIKE' => '',
728 'IMOL_VOTE_SID' => '',
729 'IMOL_VOTE_USER' => '',
730 'IMOL_VOTE_HEAD' => '',
731 'IMOL_COMMENT_HEAD' => '',
732 'IMOL_QUOTE_MSG' => 'N',
733 'IMOL_SID' => 0,
734 'IMOL_FORM' => '',
735 'IMOL_DATE_CLOSE_VOTE' => '',
736 'IMOL_TIME_LIMIT_VOTE' => '',
737 'USERS' => [],
738 'CRM_FORM_ID' => '',
739 'CRM_FORM_SEC' => '',
740 'CRM_FORM_FILLED' => 'N',
741 'COPILOT_PROMPT_CODE' => null,
742 ];
743
744 return $arDefault;
745 }
746}
747
748
750{
751 const NORMAL = "#aac337";
752 const ATTENTION = "#e8a441";
753 const PROBLEM = "#df532d";
754 const TRANSPARENT = "TRANSPARENT";
755 const CHAT = "CHAT";
756 const FIRST_MESSAGE = 'FIRST_MESSAGE';
757 const SKIP_MESSAGE = 'SKIP_MESSAGE';
758 const TEXT_NODES_NAMES = ['NAME', 'LINK', 'MESSAGE', 'VALUE'];
759
760 private $result = Array();
761
762 function __construct($id = null, $color = null)
763 {
764 $this->result['ID'] = $id? $id: time();
765 $this->result['BLOCKS'] = Array();
766 $this->result['DESCRIPTION'] = '';
767
768 $this->SetColor($color);
769 }
770
771 public function SetDescription($text)
772 {
773 $text = self::removeNewLine($text);
775 $this->result['DESCRIPTION'] = trim($text);
776 }
777
778 public function SetColor($color = null)
779 {
780 if ($color == self::TRANSPARENT)
781 {
782 $this->result['COLOR'] = 'transparent';
783 }
784 else if ($color != self::CHAT)
785 {
786 if (!$color || !preg_match('/^#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b$/D', $color))
787 {
789 }
790 $this->result['COLOR'] = $color;
791 }
792 }
793
794 public function setColorToken($color): void
795 {
796 $this->result['COLOR_TOKEN'] = IM\V2\Message\Color\Color::validateColor($color);
797 }
798
799 public function AddUser($params)
800 {
801 $add = Array();
802 if (!isset($params['NAME']) || trim($params['NAME']) == '')
803 return false;
804
805 $add['NAME'] = self::removeNewLine($params['NAME']);
806 $add['AVATAR_TYPE'] = 'USER';
807
808 if (isset($params['NETWORK_ID']))
809 {
810 $add['NETWORK_ID'] = htmlspecialcharsbx(mb_substr($params['NETWORK_ID'], 0, 1)).intval(mb_substr($params['NETWORK_ID'], 1));
811 }
812 else if (isset($params['USER_ID']) && intval($params['USER_ID']) > 0)
813 {
814 $add['USER_ID'] = intval($params['USER_ID']);
815 }
816 else if (isset($params['CHAT_ID']) && intval($params['CHAT_ID']) > 0)
817 {
818 $add['CHAT_ID'] = intval($params['CHAT_ID']);
819 $add['AVATAR_TYPE'] = 'CHAT';
820 }
821 else if (isset($params['BOT_ID']) && intval($params['BOT_ID']) > 0)
822 {
823 $add['BOT_ID'] = intval($params['BOT_ID']);
824 $add['AVATAR_TYPE'] = 'BOT';
825 }
826 else if (isset($params['LINK']) && preg_match('#^(?:/|https?://)#', $params['LINK']))
827 {
828 $add['LINK'] = $params['LINK'];
829 }
830
831 if (isset($params['AVATAR']) && preg_match('#^(?:/|https?://)#', $params['AVATAR']))
832 {
833 $add['AVATAR'] = $params['AVATAR'];
834 }
835
836 if (isset($params['AVATAR_TYPE']) && in_array($params['AVATAR_TYPE'], Array('CHAT', 'USER', 'BOT')))
837 {
838 $add['AVATAR_TYPE'] = $params['AVATAR_TYPE'];
839 }
840
841 $this->result['BLOCKS'][]['USER'] = Array($add);
842
843 return true;
844 }
845
846 public function AddChat($params)
847 {
848 $params['AVATAR_TYPE'] = 'CHAT';
849 return $this->AddUser($params);
850 }
851
852 public function AddBot($params)
853 {
854 $params['AVATAR_TYPE'] = 'BOT';
855 return $this->AddUser($params);
856 }
857
858 public function AddLink($params)
859 {
860 $result = Array();
861
862 if (isset($params['NETWORK_ID']) && isset($params['NAME']))
863 {
864 $result['NETWORK_ID'] = htmlspecialcharsbx(mb_substr($params['NETWORK_ID'], 0, 1)).intval(mb_substr($params['NETWORK_ID'], 1));
865 }
866 else if (isset($params['USER_ID']) && intval($params['USER_ID']) > 0 && isset($params['NAME']))
867 {
868 $result['USER_ID'] = intval($params['USER_ID']);
869 }
870 else if (isset($params['CHAT_ID']) && intval($params['CHAT_ID']) > 0 && isset($params['NAME']))
871 {
872 $result['CHAT_ID'] = intval($params['CHAT_ID']);
873 }
874 else if (!isset($params['LINK']) || isset($params['LINK']) && !preg_match('#^(?:/|https?://)#', $params['LINK']))
875 {
876 return false;
877 }
878
879 if (isset($params['NAME']))
880 {
881 $result['NAME'] = self::removeNewLine(trim($params['NAME']));
882 }
883 if (isset($params['LINK']))
884 {
885 $result['LINK'] = $params['LINK'];
886 }
887
888 if (isset($params['DESC']))
889 {
890 $result['DESC'] = $params['DESC'];
891 }
892
893 if (isset($params['HTML']))
894 {
895 $result['HTML'] = $params['HTML'];
896 }
897 else if (isset($params['PREVIEW']) && preg_match('#^(?:/|https?://)#', $params['PREVIEW']))
898 {
899 $result['PREVIEW'] = $params['PREVIEW'];
900 if (isset($params['WIDTH']) && intval($params['WIDTH']) > 0)
901 {
902 $result['WIDTH'] = intval($params['WIDTH']);
903 }
904 if (isset($params['HEIGHT']) && intval($params['HEIGHT']) > 0)
905 {
906 $result['HEIGHT'] = intval($params['HEIGHT']);
907 }
908 }
909
910 $this->result['BLOCKS'][]['LINK'] = Array($result);
911
912 return true;
913 }
914
915 public function AddRichLink($params)
916 {
917 $add = Array();
918
919 if (isset($params['NETWORK_ID']) && isset($params['NAME']))
920 {
921 $add['NETWORK_ID'] = htmlspecialcharsbx(mb_substr($params['NETWORK_ID'], 0, 1)).intval(mb_substr($params['NETWORK_ID'], 1));
922 }
923 else if (isset($params['USER_ID']) && intval($params['USER_ID']) > 0 && isset($params['NAME']))
924 {
925 $add['USER_ID'] = intval($params['USER_ID']);
926 }
927 else if (isset($params['CHAT_ID']) && intval($params['CHAT_ID']) > 0 && isset($params['NAME']))
928 {
929 $add['CHAT_ID'] = intval($params['CHAT_ID']);
930 }
931 else if (!isset($params['LINK']) || isset($params['LINK']) && !preg_match('#^(?:/|https?://)#', $params['LINK']))
932 {
933 return false;
934 }
935
936 if (isset($params['NAME']))
937 {
938 $add['NAME'] = self::removeNewLine(trim($params['NAME']));
939 }
940 if (isset($params['LINK']))
941 {
942 $add['LINK'] = $params['LINK'];
943 }
944
945 if (isset($params['DESC']))
946 {
947 $add['DESC'] = self::removeNewLine(trim($params['DESC']));
948 }
949
950 if (isset($params['HTML']))
951 {
952 $add['HTML'] = self::removeNewLine(trim($params['HTML']));
953 }
954
955 if (isset($params['PREVIEW']) && preg_match('#^(?:/|https?://)#', $params['PREVIEW']))
956 {
957 $add['PREVIEW'] = $params['PREVIEW'];
958 $add['PREVIEW_SIZE'] = [
959 'HEIGHT' => $params['PREVIEW_SIZE']['HEIGHT'] ?? 0,
960 'WIDTH' => $params['PREVIEW_SIZE']['WIDTH'] ?? 0,
961 ];
962 }
963 else if (isset($params['EXTRA_IMAGE']) && preg_match('#^(?:/|https?://)#', $params['EXTRA_IMAGE']))
964 {
965 $add['EXTRA_IMAGE'] = $params['EXTRA_IMAGE'];
966 }
967
968 $this->result['BLOCKS'][]['RICH_LINK'] = Array($add);
969
970 return true;
971 }
972
973 public function AddHtml($html)
974 {
975 if (!isset($html))
976 return false;
977
979 $this->result['BLOCKS'][]['HTML'] = trim($html);
980
981 return true;
982 }
983
984 public function AddMessage($message, $asDescription = false)
985 {
986 $message = trim($message);
987 if ($message == '')
988 return false;
989
990 $message = str_replace(['#BR#'], '[BR]', trim($message));
991
992 if ($asDescription)
993 {
994 $this->result['DESCRIPTION'] = $message;
995 }
996 $this->result['BLOCKS'][]['MESSAGE'] = $message;
997
998 return true;
999 }
1000
1001 public function AddGrid($params)
1002 {
1003 $add = Array();
1004
1005 foreach ($params as $grid)
1006 {
1007 $result = Array();
1008
1009 if ($grid['DISPLAY'] != 'LINE')
1010 {
1011 if (
1012 !isset($grid['NAME']) && !isset($grid['VALUE'])
1013 || trim($grid['NAME']) == '' && trim($grid['VALUE']) == ''
1014 )
1015 {
1016 continue;
1017 }
1018 }
1019
1020 if (isset($grid['DISPLAY']) && in_array($grid['DISPLAY'], Array('BLOCK', 'LINE', 'CARD', 'ROW', 'COLUMN', 'TABLE')))
1021 {
1022 if ($grid['DISPLAY'] == 'COLUMN')
1023 {
1024 $grid['DISPLAY'] = 'ROW';
1025 }
1026 if ($grid['DISPLAY'] == 'CARD')
1027 {
1028 $grid['DISPLAY'] = 'LINE';
1029 }
1030 $result['DISPLAY'] = $grid['DISPLAY'];
1031 }
1032 else
1033 {
1034 $result['DISPLAY'] = 'BLOCK';
1035 }
1036
1037 $result['NAME'] = self::removeNewLine(trim($grid['NAME']));
1038
1039 $result['VALUE'] = str_replace(['#BR#'], '[BR]', trim($grid['VALUE']));
1040
1041 if (isset($grid['COLOR']) && preg_match('/^#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b$/D', $grid['COLOR']))
1042 {
1043 $result['COLOR'] = $grid['COLOR'];
1044 }
1045 if (isset($grid['WIDTH']) && intval($grid['WIDTH']) > 0)
1046 {
1047 $result['WIDTH'] = intval($grid['WIDTH']);
1048 }
1049 if (isset($grid['HEIGHT']) && intval($grid['HEIGHT']) > 0)
1050 {
1051 $result['HEIGHT'] = intval($grid['HEIGHT']);
1052 }
1053 if (isset($grid['USER_ID']) && intval($grid['USER_ID']) > 0)
1054 {
1055 $result['USER_ID'] = intval($grid['USER_ID']);
1056 }
1057 if (isset($grid['CHAT_ID']) && intval($grid['CHAT_ID']) > 0)
1058 {
1059 $result['CHAT_ID'] = intval($grid['CHAT_ID']);
1060 }
1061 if (isset($grid['LINK']) && preg_match('#^(?:/|https?://)#', $grid['LINK']))
1062 {
1063 $result['LINK'] = $grid['LINK'];
1064 }
1065
1066 $result['COLOR_TOKEN'] = IM\V2\Message\Color\Color::validateColor($grid['COLOR_TOKEN'] ?? null);
1067
1068 $add[] = $result;
1069 }
1070 if (empty($add))
1071 return false;
1072
1073 $this->result['BLOCKS'][]['GRID'] = $add;
1074
1075 return true;
1076 }
1077
1078 public function AddImages($params)
1079 {
1080 $add = Array();
1081
1082 foreach ($params as $images)
1083 {
1084 $result = Array();
1085
1086 if (!isset($images['LINK']) || isset($images['LINK']) && !preg_match('#^(?:/|https?://)#', $images['LINK']))
1087 continue;
1088
1089 if (isset($images['NAME']) && trim($images['NAME']) <> '')
1090 {
1091 $result['NAME'] = (trim($images['NAME']));
1092 }
1093
1094 $result['LINK'] = $images['LINK'];
1095
1096 if (isset($images['WIDTH']) && intval($images['WIDTH']) > 0)
1097 {
1098 $result['WIDTH'] = intval($images['WIDTH']);
1099 }
1100 if (isset($images['HEIGHT']) && intval($images['HEIGHT']) > 0)
1101 {
1102 $result['HEIGHT'] = intval($images['HEIGHT']);
1103 }
1104
1105 if (isset($images['PREVIEW']) && preg_match('#^(?:/|https?://)#', $images['PREVIEW']))
1106 {
1107 $result['PREVIEW'] = $images['PREVIEW'];
1108 }
1109
1110 $add[] = $result;
1111 }
1112
1113 if (empty($add))
1114 return false;
1115
1116 $this->result['BLOCKS'][]['IMAGE'] = $add;
1117
1118 return true;
1119 }
1120
1121 public function AddFiles($params)
1122 {
1123 $add = Array();
1124
1125 foreach ($params as $files)
1126 {
1127 $result = Array();
1128
1129 if (!isset($files['LINK']) || isset($files['LINK']) && !preg_match('#^(?:/|https?://)#', $files['LINK']))
1130 continue;
1131
1132 $result['LINK'] = $files['LINK'];
1133
1134 if (isset($files['NAME']) && trim($files['NAME']) <> '')
1135 {
1136 $result['NAME'] = self::removeNewLine(trim($files['NAME']));
1137 }
1138
1139 if (isset($files['SIZE']) && intval($files['SIZE']) > 0)
1140 {
1141 $result['SIZE'] = intval($files['SIZE']);
1142 }
1143
1144 $add[] = $result;
1145 }
1146
1147 if (empty($add))
1148 return false;
1149
1150 $this->result['BLOCKS'][]['FILE'] = $add;
1151
1152 return true;
1153 }
1154
1155 public function AddDelimiter($params = Array())
1156 {
1157 $add = Array();
1158
1159 $add['SIZE'] = isset($params['SIZE'])? intval($params['SIZE']): 0;
1160 if ($add['SIZE'] <= 0)
1161 {
1162 $add['SIZE'] = 200;
1163 }
1164
1165 if (isset($params['COLOR']) && preg_match('/^#([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\b$/D', $params['COLOR']))
1166 {
1167 $add['COLOR'] = $params['COLOR'];
1168 }
1169
1170 $this->result['BLOCKS'][]['DELIMITER'] = $add;
1171 }
1172
1173 private static function decodeBbCode($message)
1174 {
1175 return \Bitrix\Im\Text::parse($message, Array('SAFE' => 'N'));
1176 }
1177
1178 private static function removeNewLine($text)
1179 {
1180 $text = preg_replace('/\R/u', ' ', $text);
1181 return $text;
1182 }
1183
1184 public static function GetAttachByJson($array)
1185 {
1186 if (is_string($array))
1187 {
1188 $array = \CUtil::JsObjectToPhp($array, true);
1189 }
1190 if (!is_array($array))
1191 {
1192 return null;
1193 }
1194
1195 $array = IM\Text::convertSymbolsAfterJsonDecode($array);
1196
1198 $attach = null;
1199 $description = '';
1200 $colorToken = null;
1201
1202 if (isset($array['BLOCKS']))
1203 {
1204 $blocks = $array['BLOCKS'];
1205
1206 if (isset($array['COLOR']))
1207 {
1208 $color = $array['COLOR'];
1209 }
1210 if (isset($array['DESCRIPTION']))
1211 {
1212 $description = $array['DESCRIPTION'];
1213 }
1214 if (isset($array['COLOR_TOKEN']))
1215 {
1216 $colorToken = $array['COLOR_TOKEN'];
1217 }
1218 }
1219 else
1220 {
1221 $blocks = $array;
1222 }
1223
1224 $attach = new CIMMessageParamAttach();
1225 $attach->SetColor($color);
1226 $attach->setColorToken($colorToken);
1227 $attach->SetDescription($description);
1228 foreach ($blocks as $data)
1229 {
1230 if (isset($data['USER']))
1231 {
1232 if (is_array($data['USER']) && !\Bitrix\Main\Type\Collection::isAssociative($data['USER']))
1233 {
1234 foreach ($data['USER'] as $dataItem)
1235 {
1236 $attach->AddUser($dataItem);
1237 }
1238 }
1239 else
1240 {
1241 $attach->AddUser($data['USER']);
1242 }
1243 }
1244 else if (isset($data['LINK']))
1245 {
1246 if (is_array($data['LINK']) && !\Bitrix\Main\Type\Collection::isAssociative($data['LINK']))
1247 {
1248 foreach ($data['LINK'] as $dataItem)
1249 {
1250 $attach->AddLink($dataItem);
1251 }
1252 }
1253 else
1254 {
1255 $attach->AddLink($data['LINK']);
1256 }
1257 }
1258 else if (isset($data['RICH_LINK']))
1259 {
1260 if (is_array($data['RICH_LINK']) && !\Bitrix\Main\Type\Collection::isAssociative($data['RICH_LINK']))
1261 {
1262 foreach ($data['RICH_LINK'] as $dataItem)
1263 {
1264 $attach->AddRichLink($dataItem);
1265 }
1266 }
1267 else
1268 {
1269 $attach->AddRichLink($data['RICH_LINK']);
1270 }
1271 }
1272 else if (isset($data['MESSAGE']))
1273 {
1274 if (is_array($data['MESSAGE']) && isset($data['MESSAGE']['TEXT']))
1275 {
1276 $attach->AddMessage($data['MESSAGE']['TEXT'], $data['MESSAGE']['AS_DESCRIPTION'] === 'Y');
1277 }
1278 else
1279 {
1280 $attach->AddMessage($data['MESSAGE']);
1281 }
1282 }
1283 else if (isset($data['GRID']))
1284 {
1285 $attach->AddGrid($data['GRID']);
1286 }
1287 else if (isset($data['IMAGE']))
1288 {
1289 if (is_array($data['IMAGE']) && \Bitrix\Main\Type\Collection::isAssociative($data['IMAGE']))
1290 {
1291 $data['IMAGE'] = Array($data['IMAGE']);
1292 }
1293 $attach->AddImages($data['IMAGE']);
1294 }
1295 else if (isset($data['FILE']))
1296 {
1297 if (is_array($data['FILE']) && \Bitrix\Main\Type\Collection::isAssociative($data['FILE']))
1298 {
1299 $data['FILE'] = Array($data['FILE']);
1300 }
1301 $attach->AddFiles($data['FILE']);
1302 }
1303 else if (isset($data['DELIMITER']))
1304 {
1305 $attach->AddDelimiter($data['DELIMITER']);
1306 }
1307 }
1308
1309 return $attach->IsEmpty()? null: $attach;
1310 }
1311
1312 public static function PrepareAttach($attach)
1313 {
1314 if (!is_array($attach))
1315 {
1316 return $attach;
1317 }
1318
1319 $isCollection = true;
1320 if(\Bitrix\Main\Type\Collection::isAssociative($attach))
1321 {
1322 $isCollection = false;
1323 $attach = array($attach);
1324 }
1325
1326 foreach ($attach as $attachKey => &$attachBody)
1327 {
1328 if (!is_array($attachBody))
1329 {
1330 // wrong ATTACH value like TS
1331 continue;
1332 }
1333 $findFirstMessage = false;
1334 $attachBody['DESCRIPTION'] ??= null;
1335 if ($attachBody['DESCRIPTION'] === self::FIRST_MESSAGE)
1336 {
1337 $attachBody['DESCRIPTION'] = '';
1338 $findFirstMessage = true;
1339 }
1340
1341 if (isset($attachBody['BLOCKS']) && is_array($attachBody['BLOCKS']))
1342 {
1343 foreach ($attachBody['BLOCKS'] as &$block)
1344 {
1345 if (isset($block['HTML']))
1346 {
1347 $block['HTML'] = \Bitrix\Im\Text::convertHtmlToBbCode($block['HTML']);
1348 }
1349 else if (isset($block['MESSAGE']))
1350 {
1351 if ($findFirstMessage)
1352 {
1353 $attachBody['DESCRIPTION'] = $block['MESSAGE'];
1354 $findFirstMessage = false;
1355 }
1356 }
1357 }
1358 }
1359 }
1360
1361 return $isCollection? $attach: $attach[0];
1362 }
1363
1364 public function IsEmpty()
1365 {
1366 return empty($this->result['BLOCKS']);
1367 }
1368
1369 public function IsAllowSize()
1370 {
1371 return $this->GetJSON()? true: false;
1372 }
1373
1374 public function SetId($id)
1375 {
1376 $this->result['ID'] = $id;
1377 return true;
1378 }
1379
1380 public function GetId()
1381 {
1382 return $this->result['ID'];
1383 }
1384
1385 public function GetArray()
1386 {
1387 return $this->result;
1388 }
1389
1390 public function GetJSON()
1391 {
1392 $result = \Bitrix\Im\Common::jsonEncode($this->result);
1393 return mb_strlen($result) < 60000? $result: "";
1394 }
1395
1402 public static function GetTextForIndex($attach) : array
1403 {
1404 if($attach instanceof \CIMMessageParamAttach)
1405 {
1406 $attach = $attach->GetArray();
1407 }
1408 $textNodes = [];
1409 array_walk_recursive($attach, function($item, $key) use(&$textNodes){
1410 if(in_array($key, self::TEXT_NODES_NAMES))
1411 {
1412 $textNodes[] = $item;
1413 }
1414 });
1415
1416 return $textNodes;
1417 }
1418}
1419
1421{
1422 private $result = false;
1423 private $message = "";
1424 private $attach = Array();
1425 private $urlId = Array();
1426 private $staticUrl = Array();
1427
1428 public function prepareInsert($text)
1429 {
1430 $this->message = $text;
1431
1433 foreach ($urls as $url)
1434 {
1435 $this->prepareUrlObjects($url);
1436 break;
1437 }
1438
1439 return $this->result();
1440 }
1441
1442 private function prepareUrlObjects($url)
1443 {
1444 //$linkParam = UrlPreview\UrlPreview::getMetadataAndHtmlByUrl($url, true, false);
1445 $linkParam = (new IM\V2\Entity\Url\UrlItem($url))->getMetadata();
1446 if (empty($linkParam))
1447 {
1448 return false;
1449 }
1450
1451 $attach = self::formatAttach($linkParam);
1452 if (!$attach)
1453 {
1454 return false;
1455 }
1456 $attach->SetDescription(\CIMMessageParamAttach::SKIP_MESSAGE);
1457
1458 $this->attach[$linkParam['ID']] = $attach;
1459 $this->urlId[$linkParam['ID']] = $linkParam['ID'];
1460
1461 if ($linkParam['TYPE'] == UrlPreview\UrlMetadataTable::TYPE_STATIC)
1462 {
1463 $this->staticUrl[] = $url;
1464
1465 if (mb_substr($url, -1) == '/')
1466 {
1467 $this->staticUrl[] = mb_substr($url, 0, -1);
1468 }
1469 }
1470
1471 $this->result = true;
1472
1473 return true;
1474 }
1475
1476 public static function prepareShow($arMessages, $params)
1477 {
1478 $arUrl = Array();
1479 foreach ($params as $messageId => $param)
1480 {
1481 if (isset($param['URL_ID']))
1482 {
1483 foreach ($param['URL_ID'] as $urlId)
1484 {
1485 $urlId = intval($urlId);
1486 if ($urlId > 0)
1487 {
1488 $arUrl[$urlId] = $urlId;
1489 }
1490 }
1491 }
1492 }
1493
1494 if (!empty($arUrl))
1495 {
1496 $arAttachUrl = self::getAttachments($arUrl, true);
1497 if (!empty($arAttachUrl))
1498 {
1499 foreach ($params as $messageId => $param)
1500 {
1501 if (isset($param['URL_ID']))
1502 {
1503 foreach ($param['URL_ID'] as $urlId)
1504 {
1505 if (isset($arAttachUrl[$urlId]))
1506 {
1507 if (isset($arMessages[$messageId]['params']))
1508 {
1509 $arMessages[$messageId]['params']['ATTACH'][] = $arAttachUrl[$urlId];
1510 }
1511 else
1512 {
1513 $arMessages[$messageId]['PARAMS']['ATTACH'][] = $arAttachUrl[$urlId];
1514 }
1515 }
1516 }
1517 }
1518 }
1519 }
1520 }
1521
1522 return $arMessages;
1523 }
1524
1525 public static function getAttachments($id, $typeArray = false)
1526 {
1527 $attachArray = Array();
1528
1529 if (is_array($id))
1530 {
1531 foreach ($id as $key => $value)
1532 {
1533 $id[$key] = intval($value);
1534 }
1535 }
1536 else
1537 {
1538 $id = array(intval($id));
1539 }
1540
1541 if ($params = UrlPreview\UrlPreview::getMetadataAndHtmlByIds($id))
1542 {
1543 foreach ($params as $id => $linkParam)
1544 {
1545 if ($attach = self::formatAttach($linkParam))
1546 {
1547 $attachArray[$id] = $typeArray? $attach->GetArray(): $attach;
1548 }
1549 }
1550 }
1551
1552 return $attachArray;
1553 }
1554
1555 public static function formatAttach($linkParam)
1556 {
1557 $attach = null;
1558 $typeLinkParam = $linkParam['TYPE'] ?? null;
1559 $extraImageLinkParam = $linkParam['EXTRA_IMAGE'] ?? null;
1560
1561 if ($typeLinkParam == UrlPreview\UrlMetadataTable::TYPE_STATIC)
1562 {
1563 if ($linkParam['EXTRA']['PEER_IP_PRIVATE'] && IM\User::getInstance()->isExtranet())
1564 {
1565 return $attach;
1566 }
1567 if (intval($linkParam['IMAGE_ID']) > 0)
1568 {
1569 $image = CFile::ResizeImageGet(
1570 $linkParam['IMAGE_ID'],
1571 array('width' => 450, 'height' => 120),
1573 true,
1574 false,
1575 true
1576 );
1577 $linkParam['IMAGE_ID'] = empty($image['src'])? '': $image['src'];
1578 $linkParam['IMAGE_SIZE']['HEIGHT'] = $image['height'] ?? 0;
1579 $linkParam['IMAGE_SIZE']['WIDTH'] = $image['width'] ?? 0;
1580 }
1581 else if ($linkParam['IMAGE'] <> '')
1582 {
1583 $linkParam['IMAGE_ID'] = $linkParam['IMAGE'];
1584 $linkParam['IMAGE_SIZE']['HEIGHT'] = $linkParam['EXTRA']['IMAGE_INFO']['HEIGHT'] ?? 0;
1585 $linkParam['IMAGE_SIZE']['WIDTH'] = $linkParam['EXTRA']['IMAGE_INFO']['WIDTH'] ?? 0;
1586 }
1587 else if (!empty($linkParam['EXTRA']['IMAGES']))
1588 {
1589 //we take only first extra image
1590 $linkParam['EXTRA_IMAGE'] = $linkParam['EXTRA']['IMAGES'][0];
1591 }
1592 else
1593 {
1594 $linkParam['IMAGE_ID'] = '';
1595 }
1596
1597 $attach = new CIMMessageParamAttach($linkParam['ID'], CIMMessageParamAttach::TRANSPARENT);
1598 $attach->AddRichLink(Array(
1599 "NAME" => $linkParam['TITLE'],
1600 "DESC" => $linkParam['DESCRIPTION'],
1601 "LINK" => $linkParam['URL'],
1602 "PREVIEW" => $linkParam['IMAGE_ID'],
1603 "PREVIEW_SIZE" => $linkParam['IMAGE_SIZE'],
1604 "EXTRA_IMAGE" => $extraImageLinkParam,
1605 ));
1606 }
1607 else if ($linkParam['TYPE'] == UrlPreview\UrlMetadataTable::TYPE_DYNAMIC)
1608 {
1609 $attach = UrlPreview\UrlPreview::getImAttach($linkParam['URL'], true);
1610 if ($attach && $attach instanceof CIMMessageParamAttach)
1611 {
1612 $attach->SetId($linkParam['ID']);
1613 }
1614 }
1615 return $attach;
1616 }
1617
1618 private function isLinkOnly()
1619 {
1621 foreach ($this->staticUrl as $url)
1622 {
1623 $message = str_replace($url, '', $message);
1624 }
1625 $message = trim($message);
1626
1627 return empty($message);
1628 }
1629
1630 public function result()
1631 {
1632 return Array(
1633 'RESULT' => $this->result,
1634 'MESSAGE' => $this->message,
1635 'MESSAGE_IS_LINK' => $this->isLinkOnly(),
1636 'URL_ID' => array_values($this->urlId),
1637 'ATTACH' => array_values($this->attach),
1638 );
1639 }
1640}
1641
1642?>
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
$arResult
Определения generate_coupon.php:16
static getRandomColor()
Определения color.php:193
static getPullExtra()
Определения common.php:127
static jsonEncode($array=[])
Определения common.php:48
static encodeEmoji($text)
Определения text.php:373
static convertHtmlToBbCode($html)
Определения text.php:398
static decodeEmoji($text)
Определения text.php:378
static getUrlsFromText(?string $text)
Определения UrlItem.php:82
static createFromTimestamp($timestamp)
Определения datetime.php:246
static decode($data)
Определения json.php:50
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
AddRichLink($params)
Определения im_message_param.php:915
__construct($id=null, $color=null)
Определения im_message_param.php:762
AddChat($params)
Определения im_message_param.php:846
static GetTextForIndex($attach)
Определения im_message_param.php:1402
setColorToken($color)
Определения im_message_param.php:794
const TRANSPARENT
Определения im_message_param.php:754
const TEXT_NODES_NAMES
Определения im_message_param.php:758
AddHtml($html)
Определения im_message_param.php:973
AddFiles($params)
Определения im_message_param.php:1121
AddMessage($message, $asDescription=false)
Определения im_message_param.php:984
const PROBLEM
Определения im_message_param.php:753
const FIRST_MESSAGE
Определения im_message_param.php:756
AddImages($params)
Определения im_message_param.php:1078
AddBot($params)
Определения im_message_param.php:852
AddLink($params)
Определения im_message_param.php:858
AddGrid($params)
Определения im_message_param.php:1001
const ATTENTION
Определения im_message_param.php:752
AddDelimiter($params=Array())
Определения im_message_param.php:1155
static PrepareAttach($attach)
Определения im_message_param.php:1312
const NORMAL
Определения im_message_param.php:751
const SKIP_MESSAGE
Определения im_message_param.php:757
AddUser($params)
Определения im_message_param.php:799
static GetAttachByJson($array)
Определения im_message_param.php:1184
SetDescription($text)
Определения im_message_param.php:771
SetColor($color=null)
Определения im_message_param.php:778
static DeleteAll($messageId)
Определения im_message_param.php:328
static GetDefault()
Определения im_message_param.php:683
static DeleteByParam($paramName, $paramValue)
Определения im_message_param.php:348
static Get($messageId, $paramName=false, $withDefault=false)
Определения im_message_param.php:370
static SendPull($messageId, $sendExtraParams=true)
Определения im_message_param.php:220
static Set($messageId, $params=Array())
Определения im_message_param.php:7
static GetMessageIdByParam($paramName, $paramValue, $chatId=null)
Определения im_message_param.php:460
static PrepareValues($values, $withDefault=false)
Определения im_message_param.php:488
$arValues
Определения component_props.php:25
$arFields
Определения dblapprove.php:5
$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
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$filter
Определения iblock_catalog_list.php:54
const IM_MESSAGE_PRIVATE
Определения include.php:22
global $DB
Определения cron_frame.php:29
const BX_RESIZE_IMAGE_PROPORTIONAL
Определения constants.php:11
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
$name
Определения menu_edit.php:35
$message
Определения payment.php:8
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$val
Определения options.php:1793
$k
Определения template_pdf.php:567
$url
Определения iframe.php:7