Ejemplo n.º 1
0
 /**
  * Method will be invoked after new database record inserted.
  *
  * @param array $newRecord All fields of inserted record.
  *
  * @return void
  */
 public function afterInsertTrigger(array $newRecord)
 {
     $id = intval($newRecord['MESSAGE_ID']);
     if (!\Bitrix\Main\Loader::includeModule('pull')) {
         return;
     }
     $message = \CIMMessenger::GetById($id, array('WITH_FILES' => 'Y'));
     if (!$message) {
         return;
     }
     if ($newRecord['PARAM_NAME'] === 'LIKE' && $newRecord["PARAM_VALUE"]) {
         $like = $message['PARAMS']['LIKE'];
         $result = \Bitrix\IM\ChatTable::getList(array('filter' => array('=ID' => $message['CHAT_ID'])));
         $chat = $result->fetch();
         $relations = \CIMMessenger::GetRelationById($id);
         if (!isset($relations[$newRecord["PARAM_VALUE"]])) {
             return;
         }
         if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $newRecord["PARAM_VALUE"]) {
             $CCTP = new \CTextParser();
             $CCTP->MaxStringLen = 200;
             $CCTP->allow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
             $message['MESSAGE'] = str_replace('<br />', ' ', $CCTP->convertText($message['MESSAGE']));
             $message['MESSAGE'] = preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $message['MESSAGE']);
             $message['MESSAGE'] = preg_replace("/\\[[bui]\\](.*?)\\[\\/[bui]\\]/i", "\$1", $message['MESSAGE']);
             $message['MESSAGE'] = preg_replace("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", "\$2", $message['MESSAGE']);
             $message['MESSAGE'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [" . GetMessage('IM_QUOTE') . "] ", str_replace(array("#BR#"), array(" "), $message['MESSAGE']));
             if (count($message['FILES']) > 0 && strlen($message['MESSAGE']) < 200) {
                 foreach ($message['FILES'] as $file) {
                     $file = " [" . GetMessage('IM_MESSAGE_FILE') . ": " . $file['name'] . "]";
                     if (strlen($message['MESSAGE'] . $file) > 200) {
                         break;
                     }
                     $message['MESSAGE'] .= $file;
                 }
                 $message['MESSAGE'] = trim($message['MESSAGE']);
             }
             $isChat = $chat && strlen($chat['TITLE']) > 0;
             $dot = strlen($message['MESSAGE']) >= 200 ? '...' : '';
             $message['MESSAGE'] = substr($message['MESSAGE'], 0, 199) . $dot;
             $message['MESSAGE'] = strlen($message['MESSAGE']) > 0 ? $message['MESSAGE'] : '-';
             $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $newRecord["PARAM_VALUE"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|" . ($isChat ? 'G' : 'P') . "|" . ($isChat ? $chat['ID'] : $newRecord["PARAM_VALUE"]) . "|" . $id, "NOTIFY_MESSAGE" => GetMessage($isChat ? 'IM_MESSAGE_LIKE' : 'IM_MESSAGE_LIKE_PRIVATE', array('#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE'])));
             \CIMNotify::Add($arMessageFields);
         }
         $arPullMessage = array('id' => $id, 'chatId' => $relations[$newRecord["PARAM_VALUE"]]['CHAT_ID'], 'senderId' => $newRecord["PARAM_VALUE"], 'users' => $like);
         foreach ($relations as $rel) {
             \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Method will be invoked after an database record updated.
  *
  * @param array $oldRecord All fields before update.
  * @param array $newRecord All fields after update.
  *
  * @return void
  */
 public function afterUpdateTrigger(array $oldRecord, array $newRecord)
 {
     if (!\Bitrix\Main\Loader::includeModule('pull')) {
         return;
     }
     $arFields = \CIMMessenger::GetById($newRecord['ID'], array('WITH_FILES' => 'Y'));
     if (!$arFields) {
         return;
     }
     $arFields['DATE_MODIFY'] = time() + \CTimeZone::GetOffset();
     $CCTP = new \CTextParser();
     $CCTP->MaxStringLen = 200;
     $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N");
     $pullMessage = $CCTP->convertText(htmlspecialcharsbx($arFields['MESSAGE']));
     $relations = \CIMChat::GetRelationById($arFields['CHAT_ID']);
     $arPullMessage = array('id' => $arFields['ID'], 'type' => $arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE ? 'private' : 'chat', 'text' => $pullMessage, 'date' => $arFields['DATE_MODIFY']);
     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) {
         $arFields['FROM_USER_ID'] = $arFields['AUTHOR_ID'];
         foreach ($relations as $rel) {
             if ($rel['USER_ID'] != $arFields['AUTHOR_ID']) {
                 $arFields['TO_USER_ID'] = $rel['USER_ID'];
             }
         }
         $arPullMessage['fromUserId'] = $arFields['FROM_USER_ID'];
         $arPullMessage['toUserId'] = $arFields['TO_USER_ID'];
     } else {
         $arPullMessage['chatId'] = $arFields['CHAT_ID'];
         $arPullMessage['senderId'] = $arFields['AUTHOR_ID'];
     }
     \CPullStack::AddByUsers(array_keys($relations), $p = array('module_id' => 'im', 'command' => $arFields['PARAMS']['IS_DELETED'] === 'Y' ? 'messageDelete' : 'messageUpdate', 'params' => $arPullMessage));
     foreach ($relations as $rel) {
         $obCache = new \CPHPCache();
         $obCache->CleanDir('/bx/imc/recent' . \CIMMessenger::GetCachePath($rel['USER_ID']));
     }
     if ($newRecord['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) {
         \CPullWatch::AddToStack('IM_PUBLIC_' . $arFields['CHAT_ID'], array('module_id' => 'im', 'command' => $arFields['PARAMS']['IS_DELETED'] === 'Y' ? 'messageDelete' : 'messageUpdate', 'params' => $arPullMessage));
     }
     foreach (\GetModuleEvents("im", "OnAfterMessagesUpdate", true) as $arEvent) {
         \ExecuteModuleEventEx($arEvent, array(intval($newRecord['ID']), $arFields));
     }
 }