예제 #1
0
 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;
 }
예제 #2
0
 public function ClearCaches()
 {
     $factory = CXMPPFactory::GetFactory();
     $factory->ClearCaches();
 }
예제 #3
0
 private function __ProcessServerMessage($arMessage, $clientDomain = "")
 {
     if (count($arMessage) <= 0) {
         return false;
     }
     if (empty($clientDomain)) {
         $clientDomain = CXMPPServer::GetDomain();
     }
     $factory = CXMPPFactory::GetFactory();
     $processResult = $factory->ProcessServerMessage($arMessage, $clientDomain);
     if (is_array($processResult)) {
         $this->Send($processResult);
     }
 }
예제 #4
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("presence", $arMessage) || !array_key_exists(".", $arMessage["presence"])) {
         return false;
     }
     $type = "available";
     if (array_key_exists("type", $arMessage["presence"]["."])) {
         $type = $arMessage["presence"]["."]["type"];
     }
     if ($type == "error") {
         return false;
     }
     // available (empty) - Signals that the sender is online and available for communication.
     // unavailable - Signals that the sender is no longer available for communication.
     // subscribe - The sender wishes to subscribe to the recipient's presence.
     // subscribed - The sender has allowed the recipient to receive their presence.
     // unsubscribe - The sender is unsubscribing from another entity's presence.
     // unsubscribed - The subscription request has been denied or a previously-granted subscription has been cancelled.
     // probe - A request for an entity's current presence; SHOULD be generated only by a server on behalf of a user.
     // error - An error has occurred regarding processing or delivery of a previously-sent presence stanza.
     if (!in_array($type, array("available", "unavailable", "subscribe", "subscribed", "unsubscribe", "unsubscribed", "probe"))) {
         return CXMPPUtility::GetErrorArray($senderJId, "presence", "modify", "bad-request", "", "", "", $senderClient->GetClientDomain());
     }
     $to = "";
     if (array_key_exists("to", $arMessage["presence"]["."])) {
         $to = $arMessage["presence"]["."]["to"];
     }
     $server = CXMPPServer::GetServer();
     if (strlen($to) <= 0) {
         $server->SendAll($arMessage, $senderClient->GetClientDomain());
     } else {
         $server->Send($to, $arMessage, $senderClient->GetClientDomain());
     }
     if (!in_array($type, array("available"))) {
         return true;
     }
     $userJId = $senderJId;
     $show = "online";
     if (array_key_exists("show", $arMessage["presence"])) {
         $show = $arMessage["presence"]["show"]["#"];
     }
     $status = "";
     if (array_key_exists("status", $arMessage["presence"])) {
         $status = $arMessage["presence"]["status"]["#"];
     }
     $priority = 0;
     if (array_key_exists("priority", $arMessage["presence"])) {
         $priority = intval($arMessage["presence"]["priority"]["#"]);
     }
     $arUser = CXMPPUtility::GetUserByJId($userJId);
     if (!$arUser) {
         return CXMPPUtility::GetErrorArray($senderJId, "presence", "auth", "forbidden", "", "", "", $senderClient->GetClientDomain());
     }
     CUser::SetLastActivityDate($arUser["ID"]);
     CXMPPFactory::SendUnreadMessages($senderJId, $senderClient->GetClientDomain());
     $senderClient->ChangeWorkPresence("Status", $show);
     return true;
 }