public function SendUnreadMessages($receiverJId, $domain = "") { $receiverJId = trim($receiverJId); if (strlen($receiverJId) <= 0) { return false; } $receiver = CXMPPUtility::GetUserByJId($receiverJId, $domain); if (!$receiver) { return false; } $factory = CXMPPFactory::GetFactory(); if (IsModuleInstalled("im") && CModule::IncludeModule("im")) { $CIMMessage = new CIMMessage($receiverJId, array('hide_link' => true)); $arMessage = $CIMMessage->GetUnreadMessage(array('SPEED_CHECK' => 'N', 'ORDER' => 'ASC', 'USE_SMILES' => 'N', 'USER_LOAD' => 'N', 'LOAD_DEPARTMENT' => 'N')); if ($arMessage['result']) { foreach ($arMessage['message'] as $id => $arMessage) { $factory->__SendMessage($arMessage["senderId"], $arMessage["recipientId"], $arMessage["id"], IM_MESSAGE_PRIVATE, htmlspecialcharsbx(CTextParser::convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", $arMessage["text"]))), $domain); } } // Notify $CIMNotify = new CIMNotify($receiverJId); $arNotify = $CIMNotify->GetUnreadNotify(array('SPEED_CHECK' => 'N', 'ORDER' => 'ASC')); if ($arNotify['result']) { foreach ($arNotify['original_notify'] as $id => $arNotify) { if (isset($arNotify["NOTIFY_MODULE"]) && isset($arNotify["NOTIFY_EVENT"]) && !CIMSettings::GetNotifyAccess($arNotify["TO_USER_ID"], $arNotify["NOTIFY_MODULE"], $arNotify["NOTIFY_EVENT"], CIMSettings::CLIENT_XMPP)) { continue; } if ($arNotify["MESSAGE_OUT"] == IM_MAIL_SKIP) { $arNotify["MESSAGE_OUT"] = ''; } $factory->__SendMessage($arNotify["FROM_USER_ID"], $arNotify["TO_USER_ID"], $arNotify["ID"], IM_MESSAGE_SYSTEM, htmlspecialcharsbx(CTextParser::convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", strlen($arNotify["MESSAGE_OUT"]) > 0 ? $arNotify["MESSAGE_OUT"] : $arNotify["MESSAGE"]))), $domain); } } } else { $parser = new CSocNetTextParser(); $dbMessages = CSocNetMessages::GetList(array("DATE_CREATE" => "ASC"), array("TO_USER_ID" => $receiver["ID"], "DATE_VIEW" => "", "TO_DELETED" => "N", "IS_LOG_ALL" => "Y"), false, false, array("ID", "FROM_USER_ID", "TO_USER_ID", "MESSAGE", "DATE_VIEW", "MESSAGE_TYPE", "FROM_DELETED", "TO_DELETED", "IS_LOG")); while ($arMessage = $dbMessages->Fetch()) { $factory->__SendMessage($arMessage["IS_LOG"] == "Y" ? -5 : $arMessage["FROM_USER_ID"], $arMessage["TO_USER_ID"], $arMessage["ID"], $arMessage["MESSAGE_TYPE"], htmlspecialcharsbx($parser->convert4mail(str_replace(array("#BR#", "<br />", "<br>", "<br/>"), "\n", $arMessage["MESSAGE"]))), $domain); } } return true; }
public static function SendEventAgent() { global $DB; if (IsModuleInstalled("im")) { return "CSocNetMessages::SendEventAgent();"; } $dbMessage = CSocNetMessages::GetList(array(), array("DATE_VIEW" => "", "TO_DELETED" => "N", "SEND_MAIL" => "N", "!IS_LOG" => "Y"), false, false, array("ID", "FROM_USER_ID", "TO_USER_ID", "TITLE", "MESSAGE", "DATE_CREATE", "FROM_USER_NAME", "FROM_USER_LAST_NAME", "FROM_USER_LOGIN", "TO_USER_NAME", "TO_USER_LAST_NAME", "TO_USER_LOGIN", "TO_USER_EMAIL", "TO_USER_LID", "EMAIL_TEMPLATE", "IS_LOG")); while ($arMessage = $dbMessage->Fetch()) { if (isset($arMessage["EMAIL_TEMPLATE"]) && strlen($arMessage["EMAIL_TEMPLATE"]) > 0) { $mailTemplate = $arMessage["EMAIL_TEMPLATE"]; } else { $mailTemplate = "SONET_NEW_MESSAGE"; } $defSiteID = $arMessage["TO_USER_LID"]; $siteID = CSocNetUserEvents::GetEventSite($arMessage["TO_USER_ID"], $mailTemplate, $defSiteID); if ($siteID == false || StrLen($siteID) <= 0) { $siteID = CSite::GetDefSite(); } if ($siteID == false || StrLen($siteID) <= 0) { continue; } $arFields = array("MESSAGE_ID" => $arMessage["ID"], "USER_ID" => $arMessage["TO_USER_ID"], "USER_NAME" => $arMessage["TO_USER_NAME"], "USER_LAST_NAME" => $arMessage["TO_USER_LAST_NAME"], "SENDER_ID" => $arMessage["FROM_USER_ID"], "SENDER_NAME" => $arMessage["FROM_USER_NAME"], "SENDER_LAST_NAME" => $arMessage["FROM_USER_LAST_NAME"], "EMAIL_TO" => $arMessage["TO_USER_EMAIL"], "TITLE" => $arMessage["TITLE"], "MESSAGE" => CSocNetTextParser::convert4mail($arMessage["MESSAGE"])); $event = new CEvent(); $event->Send($mailTemplate, $siteID, $arFields, "N"); CSocNetMessages::Update($arMessage["ID"], array("SEND_MAIL" => "Y")); } return "CSocNetMessages::SendEventAgent();"; }