21 public static function register(array $fields)
23 $moduleId = $fields[
'MODULE_ID'];
24 if (strlen($moduleId) <= 0)
32 $jscommand = isset($fields[
'JS'])? $fields[
'JS']:
'';
34 if (isset($fields[
'IFRAME']))
36 $check = parse_url($fields[
'IFRAME']);
37 if (!isset($check[
'scheme']) && !isset($check[
'host']))
39 if (strpos($fields[
'IFRAME'],
'/desktop_app/iframe/') !== 0)
44 else if (!in_array($check[
'scheme'], Array(
'http',
'https')) || empty($check[
'host']))
48 $iframe = $fields[
'IFRAME'].(isset($check[
'query'])?
'&':
'?');
49 $iframeWidth = isset($fields[
'IFRAME_WIDTH']) && intval($fields[
'IFRAME_WIDTH']) > 250? intval($fields[
'IFRAME_WIDTH']): $iframeWidth;
50 $iframeHeight = isset($fields[
'IFRAME_HEIGHT']) && intval($fields[
'IFRAME_HEIGHT']) > 50? intval($fields[
'IFRAME_HEIGHT']): $iframeHeight;
58 $icon = $fields[
'ICON_CODE'];
64 $iconFileId = intval($fields[
'ICON_FILE_ID']);
66 $hash = isset($fields[
'HASH'])? substr($fields[
'HASH'], 0, 32):
'register';
67 $context = isset($fields[
'CONTEXT'])? $fields[
'CONTEXT']:
'ALL';
68 $hidden = isset($fields[
'HIDDEN']) && $fields[
'HIDDEN'] ==
'Y'?
'Y':
'N';
69 $botId = isset($fields[
'BOT_ID'])? intval($fields[
'BOT_ID']): 0;
75 $extranetSupport = isset($fields[
'EXTRANET_SUPPORT']) && $fields[
'EXTRANET_SUPPORT'] ==
'Y'?
'Y':
'N';
78 $class = isset($fields[
'CLASS'])? $fields[
'CLASS']:
'';
79 $methodLangGet = isset($fields[
'METHOD_LANG_GET'])? $fields[
'METHOD_LANG_GET']:
'';
82 $appId = isset($fields[
'APP_ID'])? $fields[
'APP_ID']:
'';
83 $langSet = isset($fields[
'LANG'])? $fields[
'LANG']: Array();
85 if ($moduleId ==
'rest')
94 if (empty($class) || empty($methodLangGet))
101 foreach ($icons as $cmd)
105 if ($botId == $cmd[
'BOT_ID'] && $icon == $cmd[
'ICON_CODE'])
112 if ($appId == $cmd[
'APP_ID'] && $icon == $cmd[
'ICON_CODE'])
117 else if ($moduleId == $cmd[
'MODULE_ID'] && $icon == $cmd[
'ICON_CODE'])
123 $result = \Bitrix\Im\Model\TextareaIconTable::add(Array(
126 'MODULE_ID' => $moduleId,
127 'ICON_CODE' => $icon,
128 'ICON_FILE_ID' => $iconFileId,
129 'CONTEXT' => ToLower($context),
132 'IFRAME_WIDTH' => $iframeWidth,
133 'IFRAME_HEIGHT' => $iframeHeight,
135 'EXTRANET_SUPPORT' => $extranetSupport,
137 'METHOD_LANG_GET' => $methodLangGet,
141 if (!$result->isSuccess())
144 $cache = \Bitrix\Main\Data\Cache::createInstance();
145 $cache->cleanDir(self::CACHE_PATH);
147 $iconId = $result->getId();
149 if ($moduleId ==
'rest')
151 foreach ($langSet as $lang)
153 if (!isset($lang[
'LANGUAGE_ID']) || empty($lang[
'LANGUAGE_ID']))
156 if (!isset($lang[
'TITLE']) && empty($lang[
'TITLE']))
161 \Bitrix\Im\Model\TextareaIconLangTable::add(array(
162 'ICON_ID' => $iconId,
163 'LANGUAGE_ID' => strtolower($lang[
'LANGUAGE_ID']),
164 'TITLE' => $lang[
'TITLE'],
165 'DESCRIPTION' => $lang[
'DESCRIPTION'],
166 'COPYRIGHT' => $lang[
'COPYRIGHT']
180 $iconId = intval($icon[
'ICON_ID']);
181 $moduleId = isset($icon[
'MODULE_ID'])? $icon[
'MODULE_ID']:
'';
182 $appId = isset($icon[
'APP_ID'])? $icon[
'APP_ID']:
'';
184 if (intval($iconId) <= 0)
187 if (!isset($icon[
'FORCE']) || $icon[
'FORCE'] ==
'N')
190 if (!isset($icons[$iconId]))
193 if (strlen($moduleId) > 0 && $icons[$iconId][
'MODULE_ID'] != $moduleId)
196 if (strlen($appId) > 0 && $icons[$iconId][
'APP_ID'] != $appId)
200 \Bitrix\Im\Model\TextareaIconTable::delete($iconId);
202 $orm = \Bitrix\Im\Model\TextareaIconLangTable::getList(Array(
203 'filter' => Array(
'=ICON_ID' => $iconId)
205 while ($row = $orm->fetch())
207 \Bitrix\Im\Model\TextareaIconLangTable::delete($row[
'ID']);
210 $cache = \Bitrix\Main\Data\Cache::createInstance();
211 $cache->cleanDir(self::CACHE_PATH);
213 if (\
Bitrix\Main\Loader::includeModule(
'pull'))
215 \CPullStack::AddShared(Array(
217 'command' =>
'deleteTextareaIcon',
227 public static function update(array $icon, array $updateFields)
229 $iconId = intval($icon[
'ICON_ID']);
230 $userId = intval($icon[
'USER_ID']);
231 $moduleId = isset($icon[
'MODULE_ID'])? $icon[
'MODULE_ID']:
'';
232 $appId = isset($icon[
'APP_ID'])? $icon[
'APP_ID']:
'';
234 if (intval($iconId) <= 0)
238 if (!isset($commands[$iconId]))
241 if (strlen($moduleId) > 0 && $commands[$iconId][
'MODULE_ID'] != $moduleId)
244 if (strlen($appId) > 0 && $commands[$iconId][
'APP_ID'] != $appId)
247 if (isset($updateFields[
'LANG']) && $commands[$iconId][
'MODULE_ID'] ==
'rest')
249 $orm = \Bitrix\Im\Model\TextareaIconLangTable::getList(Array(
250 'filter' => Array(
'=ICON_ID' => $iconId)
252 while ($row = $orm->fetch())
254 \Bitrix\Im\Model\TextareaIconLangTable::delete($row[
'ID']);
256 foreach ($updateFields[
'LANG'] as $lang)
258 if (!isset($lang[
'LANGUAGE_ID']) || empty($lang[
'LANGUAGE_ID']))
261 if (!isset($lang[
'TITLE']) && empty($lang[
'TITLE']))
266 \Bitrix\Im\Model\TextareaIconLangTable::add(array(
267 'ICON_ID' => $iconId,
268 'LANGUAGE_ID' => strtolower($lang[
'LANGUAGE_ID']),
269 'TITLE' => $lang[
'TITLE'],
270 'DESCRIPTION' => $lang[
'DESCRIPTION'],
271 'COPYRIGHT' => $lang[
'COPYRIGHT']
281 if (isset($updateFields[
'CONTEXT']) && !empty($updateFields[
'CONTEXT']))
283 $update[
'CONTEXT'] = ToLower($updateFields[
'CONTEXT']);
285 if (isset($updateFields[
'HASH']) && !empty($updateFields[
'HASH']))
287 $update[
'HASH'] = $updateFields[
'HASH'];
289 if (isset($updateFields[
'HIDDEN']))
291 $update[
'HIDDEN'] = $updateFields[
'HIDDEN'] ==
'Y'?
'Y':
'N';
293 if (isset($updateFields[
'IFRAME']) && !empty($updateFields[
'IFRAME']))
295 $check = parse_url($updateFields[
'IFRAME']);
296 if (!isset($check[
'scheme']) && !isset($check[
'host']))
298 if (strpos($updateFields[
'IFRAME'],
'/desktop_app/iframe/') !== 0)
303 else if (!in_array($check[
'scheme'], Array(
'http',
'https')) || empty($check[
'host']))
307 $update[
'IFRAME'] = $updateFields[
'IFRAME'].(isset($check[
'query'])?
'&':
'?');
309 else if (isset($updateFields[
'JS']) && !empty($updateFields[
'JS']))
311 $update[
'JS'] = $updateFields[
'JS'];
313 if (isset($updateFields[
'IFRAME_WIDTH']))
315 $update[
'IFRAME_WIDTH'] = intval($updateFields[
'IFRAME_WIDTH']) > 250? intval($updateFields[
'IFRAME_WIDTH']): 350;
317 if (isset($updateFields[
'IFRAME_HEIGHT']))
319 $update[
'IFRAME_HEIGHT'] = intval($updateFields[
'IFRAME_HEIGHT']) > 50? intval($updateFields[
'IFRAME_HEIGHT']): 150;
321 if (isset($updateFields[
'ICON_FILE_ID']))
323 $update[
'ICON_FILE_ID'] = intval($updateFields[
'ICON_FILE_ID']);
325 if (isset($updateFields[
'CLASS']) && !empty($updateFields[
'CLASS']))
327 $update[
'CLASS'] = $updateFields[
'CLASS'];
329 if (isset($updateFields[
'METHOD_LANG_GET']))
331 $update[
'METHOD_LANG_GET'] = $updateFields[
'METHOD_LANG_GET'];
333 if (isset($updateFields[
'EXTRANET_SUPPORT']))
335 $update[
'EXTRANET_SUPPORT'] = $updateFields[
'EXTRANET_SUPPORT'] ==
'Y'?
'Y':
'N';
340 \Bitrix\Im\Model\TextareaIconTable::update($iconId, $update);
342 $cache = \Bitrix\Main\Data\Cache::createInstance();
343 $cache->cleanDir(self::CACHE_PATH);
346 if (\
Bitrix\Main\Loader::includeModule(
'pull'))
348 if ($update[
'HASH'] || $update[
'CONTEXT'] || $update[
'IFRAME'] || $update[
'JS'] || $update[
'IFRAME_WIDTH'] || $update[
'IFRAME_HEIGHT'])
350 \CPullStack::AddShared(Array(
352 'command' =>
'updateTextareaIcon',
356 'hash' => $update[
'HASH'],
357 'context' => $update[
'CONTEXT'],
358 'js' => $update[
'JS'],
359 'iframe' => $update[
'IFRAME'],
360 'iframeWidth' => $update[
'IFRAME_WIDTH'],
361 'iframeHeight' => $update[
'IFRAME_HEIGHT'],
367 \CPullStack::AddShared(Array(
369 'command' =>
'deleteTextareaIcon',
384 $botId = intval($params[
'BOT_ID']);
385 $userId = intval($params[
'USER_ID']);
387 Bot\Token::add($botId, $params[
'DIALOG_ID']);
388 Bot\Token::add($userId, $params[
'DIALOG_ID']);
390 if (!self::isChat($params[
'DIALOG_ID']))
392 Bot\Token::add($botId, $params[
'USER_ID']);
398 public static function addMessage(array $access, array $messageFields)
400 $iconId = intval($access[
'ICON_ID']);
401 $moduleId = isset($access[
'MODULE_ID'])? $access[
'MODULE_ID']:
'';
402 $appId = isset($access[
'APP_ID'])? $access[
'APP_ID']:
'';
408 if (!isset($icons[$iconId]))
411 if (strlen($moduleId) > 0 && $icons[$iconId][
'MODULE_ID'] != $moduleId)
414 if (strlen($appId) > 0 && $icons[$iconId][
'APP_ID'] != $appId)
417 $botId = intval($icons[$iconId][
'BOT_ID']);
419 if (self::isChat($messageFields[
'DIALOG_ID']))
421 $relations = \CIMChat::GetRelationById(substr($messageFields[
'DIALOG_ID'], 4));
425 $userId = intval($messageFields[
'DIALOG_ID']);
426 if (!$userId || $botId == $userId)
430 $relations = \CIMChat::GetPrivateRelation($botId, $userId);
433 if ($botId && !
Bot\Token::isActive($botId, $messageFields[
'DIALOG_ID']))
438 $messageFields[
'ATTACH'] = $messageFields[
'ATTACH']? $messageFields[
'ATTACH']:
null;
439 $messageFields[
'KEYBOARD'] = $messageFields[
'KEYBOARD']? $messageFields[
'KEYBOARD']:
null;
441 $fromUserId = isset($messageFields[
'FROM_USER_ID'])? $messageFields[
'FROM_USER_ID']: $botId;
443 if (self::isChat($messageFields[
'DIALOG_ID']))
445 $chatId = intval(substr($messageFields[
'DIALOG_ID'], 4));
449 if (isset($relations[$fromUserId]) && $messageFields[
'SYSTEM'] !=
'Y')
452 "FROM_USER_ID" => $fromUserId,
453 "TO_CHAT_ID" => $chatId,
454 "ATTACH" => $messageFields[
'ATTACH'],
455 "KEYBOARD" => $messageFields[
'KEYBOARD'],
457 if (isset($messageFields[
'MESSAGE']))
459 $ar[
'MESSAGE'] = $messageFields[
'MESSAGE'];
465 "FROM_USER_ID" => isset($relations[$fromUserId])? $fromUserId: 0,
466 "TO_CHAT_ID" => $chatId,
467 "ATTACH" => $messageFields[
'ATTACH'],
468 "KEYBOARD" => $messageFields[
'KEYBOARD'],
471 if (isset($messageFields[
'MESSAGE']))
473 $ar[
'MESSAGE'] = $messageFields[
'MESSAGE'];
476 $ar[
'MESSAGE'] =
"[B]".$icons[$iconId][
'TITLE'].
"[/B]\n".$ar[
'MESSAGE'];
479 if (isset($messageFields[
'URL_PREVIEW']) && $messageFields[
'URL_PREVIEW'] ==
'N')
481 $ar[
'URL_PREVIEW'] =
'N';
484 $ar[
'SKIP_USER_CHECK'] =
'Y';
485 $ar[
'SKIP_COMMAND'] =
'Y';
487 $id = \CIMChat::AddMessage($ar);
491 $userId = intval($messageFields[
'DIALOG_ID']);
492 \CModule::IncludeModule(
'imbot');
494 if (isset($relations[$fromUserId]) && $messageFields[
'SYSTEM'] !=
'Y')
497 "FROM_USER_ID" => $fromUserId,
498 "TO_USER_ID" => $userId,
499 "ATTACH" => $messageFields[
'ATTACH'],
500 "KEYBOARD" => $messageFields[
'KEYBOARD'],
502 if (isset($messageFields[
'MESSAGE']))
504 $ar[
'MESSAGE'] = $messageFields[
'MESSAGE'];
510 "FROM_USER_ID" => isset($relations[$fromUserId])? $fromUserId: 0,
511 "TO_USER_ID" => $userId,
512 "ATTACH" => $messageFields[
'ATTACH'],
513 "KEYBOARD" => $messageFields[
'KEYBOARD'],
516 if (isset($messageFields[
'MESSAGE']))
518 $ar[
'MESSAGE'] = $messageFields[
'MESSAGE'];
521 $ar[
'MESSAGE'] =
"[B]".$icons[$iconId][
'TITLE'].
"[/B]\n".$ar[
'MESSAGE'];
524 if (isset($messageFields[
'URL_PREVIEW']) && $messageFields[
'URL_PREVIEW'] ==
'N')
526 $ar[
'URL_PREVIEW'] =
'N';
529 $ar[
'SKIP_COMMAND'] =
'Y';
530 $id = \CIMMessage::Add($ar);
549 $cache = \Bitrix\Main\Data\Cache::createInstance();
550 if($cache->initCache(self::CACHE_TTL,
'list_v2_'.$lang, self::CACHE_PATH))
552 $result = $cache->getVars();
556 $loadRestLang =
false;
558 $orm = \Bitrix\Im\Model\TextareaIconTable::getList();
559 while ($row = $orm->fetch())
561 $row[
'ICON_ID'] = $row[
'ID'];
563 if ($row[
'ICON_FILE_ID'])
565 $image = \CFile::ResizeImageGet(
566 $row[
'ICON_FILE_ID'],
567 array(
'width' => 108,
'height' => 66),
568 BX_RESIZE_IMAGE_PROPORTIONAL,
573 $row[
'ICON_URL'] = empty($image[
'src'])?
'': $image[
'src'];
577 $row[
'ICON_URL'] =
'';
580 if (!empty($row[
'CLASS']) && !empty($row[
'METHOD_LANG_GET']))
582 if (\
Bitrix\Main\Loader::includeModule($row[
'MODULE_ID']) && class_exists($row[
"CLASS"]) && method_exists($row[
"CLASS"], $row[
"METHOD_LANG_GET"]))
584 $localize = call_user_func_array(array($row[
"CLASS"], $row[
"METHOD_LANG_GET"]), Array($row[
'ICON_CODE'], $lang));
587 $row[
'TITLE'] = $localize[
'TITLE'];
588 $row[
'DESCRIPTION'] = $localize[
'DESCRIPTION'];
589 $row[
'COPYRIGHT'] = $localize[
'COPYRIGHT'];
593 $row[
'METHOD_LANG_GET'] =
'';
598 $row[
'METHOD_LANG_GET'] =
'';
604 $row[
'DESCRIPTION'] =
'';
605 $row[
'COPYRIGHT'] =
'';
607 if ($row[
'MODULE_ID'] ==
'rest')
609 $loadRestLang =
true;
612 $result[$row[
'ICON_ID']] = $row;
618 $orm = \Bitrix\Im\Model\TextareaIconLangTable::getList();
619 while ($row = $orm->fetch())
621 if (!isset($result[$row[
'ICON_ID']]))
624 $langSet[$row[
'ICON_ID']][$row[
'LANGUAGE_ID']][
'TITLE'] = $row[
'TITLE'];
625 $langSet[$row[
'ICON_ID']][$row[
'LANGUAGE_ID']][
'DESCRIPTION'] = $row[
'DESCRIPTION'];
626 $langSet[$row[
'ICON_ID']][$row[
'LANGUAGE_ID']][
'COPYRIGHT'] = $row[
'COPYRIGHT'];
629 $langAlter = \Bitrix\Im\Bot::getDefaultLanguage();
630 foreach ($result as $iconId => $commandData)
632 if (isset($langSet[$iconId][$lang]))
634 $result[$iconId][
'TITLE'] = $langSet[$iconId][$lang][
'TITLE'];
635 $result[$iconId][
'DESCRIPTION'] = $langSet[$iconId][$lang][
'DESCRIPTION'];
636 $result[$iconId][
'COPYRIGHT'] = $langSet[$iconId][$lang][
'COPYRIGHT'];
638 else if (isset($langSet[$iconId][$langAlter]))
640 $result[$iconId][
'TITLE'] = $langSet[$iconId][$langAlter][
'TITLE'];
641 $result[$iconId][
'DESCRIPTION'] = $langSet[$iconId][$langAlter][
'DESCRIPTION'];
642 $result[$iconId][
'COPYRIGHT'] = $langSet[$iconId][$langAlter][
'COPYRIGHT'];
644 else if (isset($langSet[$iconId]))
646 $langSetCommand = array_values($langSet[$iconId]);
647 $result[$iconId][
'TITLE'] = $langSetCommand[0][
'TITLE'];
648 $result[$iconId][
'DESCRIPTION'] = $langSetCommand[0][
'DESCRIPTION'];
649 $result[$iconId][
'COPYRIGHT'] = $langSetCommand[0][
'COPYRIGHT'];
653 foreach ($result as $key => $value)
655 if (empty($value[
'TITLE']))
657 $row[
'METHOD_LANG_GET'] =
'';
662 $cache->startDataCache();
663 $cache->endDataCache($result);