Пример #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 ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage) || !array_key_exists("vcard", $arMessage["iq"]) || $arMessage["iq"]["vcard"]["."]["xmlns"] != "vcard-temp") {
         return false;
     }
     $type = "";
     if (array_key_exists("type", $arMessage["iq"]["."])) {
         $type = $arMessage["iq"]["."]["type"];
     }
     if ($type == "get") {
         $to = $arMessage["iq"]["."]["to"];
         $arUser = CXMPPUtility::GetUserByJId($to);
         if ($arUser) {
             $photoType = "";
             $photo = "";
             if (intval($arUser["PERSONAL_PHOTO"]) > 0) {
                 $imageFile = CFile::GetFileArray($arUser["PERSONAL_PHOTO"]);
                 if ($imageFile !== false) {
                     $arFileTmp = CFile::ResizeImageGet($imageFile, array("width" => 300, "height" => 300), BX_RESIZE_IMAGE_PROPORTIONAL, false);
                     if (is_array($arFileTmp)) {
                         $arFileTmp = CFile::MakeFileArray($arFileTmp["src"]);
                     }
                     $photoType = $imageFile["CONTENT_TYPE"];
                     if (File_Exists($arFileTmp["tmp_name"])) {
                         $photo = File_Get_Contents($arFileTmp["tmp_name"]);
                         $photo = Base64_Encode($photo);
                     }
                 }
             }
             if (empty($photo)) {
                 $photoType = "image/gif";
                 if (File_Exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/images/socialnetwork/nopic_user_150.gif")) {
                     $photo = File_Get_Contents($_SERVER["DOCUMENT_ROOT"] . "/bitrix/images/socialnetwork/nopic_user_150.gif");
                     $photo = Base64_Encode($photo);
                 }
             }
             $arResult = array("iq" => array("." => array("type" => "result", "from" => $to, "to" => $senderJId, "id" => $arMessage['iq']['.']['id']), "vCard" => array("." => array("xmlns" => "vcard-temp", "prodid" => '-//HandGen//NONSGML vGen v1.0//EN', "version" => '2.0'), "FN" => array("#" => CUser::FormatName($this->nameTemplate, $arUser)), "N" => array("FAMILY" => array("#" => $arUser["LAST_NAME"]), "GIVEN" => array("#" => $arUser["NAME"]), "MIDDLE" => array("#" => $arUser["SECOND_NAME"])), "NICKNAME" => array("#" => CUser::FormatName($this->nameTemplate, $arUser)), "BDAY" => array("#" => ConvertDateTime($arUser["PERSONAL_BIRTHDAY"], "YYYY-MM-DD", SITE_ID)), "ORG" => array("ORGNAME" => array("#" => $arUser["WORK_COMPANY"]), "ORGUNIT" => array("#" => $arUser["WORK_DEPARTMENT"])), "TITLE" => array("#" => $arUser["WORK_POSITION"]), "EMAIL" => array("INTERNET" => array("#" => ""), "PREF" => array("#" => ""), "USERID" => array("#" => $arUser["EMAIL"])), "JABBERID" => array("#" => $to), "PHOTO" => array("TYPE" => array("#" => $photoType), "BINVAL" => array("#" => $photo)))));
             if (strlen($arUser["WORK_FAX"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("WORK" => array("#" => ""), "FAX" => array("#" => ""), "NUMBER" => array("#" => $arUser["WORK_FAX"]));
             }
             if (strlen($arUser["PERSONAL_MOBILE"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("HOME" => array("#" => ""), "CELL" => array("#" => ""), "NUMBER" => array("#" => $arUser["PERSONAL_MOBILE"]));
             }
             if (strlen($arUser["WORK_PHONE"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("WORK" => array("#" => ""), "VOICE" => array("#" => ""), "NUMBER" => array("#" => $arUser["WORK_PHONE"]));
             }
             if (strlen($arUser["PERSONAL_PHONE"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("HOME" => array("#" => ""), "VOICE" => array("#" => ""), "NUMBER" => array("#" => $arUser["PERSONAL_PHONE"]));
             }
             if (strlen($arUser["PERSONAL_FAX"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("HOME" => array("#" => ""), "FAX" => array("#" => ""), "NUMBER" => array("#" => $arUser["PERSONAL_FAX"]));
             }
             if (strlen($arUser["WORK_STREET"]) > 0 || strlen($arUser["WORK_CITY"]) > 0 || strlen($arUser["WORK_COUNTRY"]) > 0) {
                 $arResult["iq"]["vCard"]["ADR"][] = array("WORK" => array("#" => ""), "EXTADD" => array("#" => ""), "STREET" => array("#" => $arUser["WORK_STREET"]), "LOCALITY" => array("#" => $arUser["WORK_CITY"]), "REGION" => array("#" => $arUser["WORK_STATE"]), "PCODE" => array("#" => $arUser["WORK_ZIP"]), "CTRY" => array("#" => GetCountryByID($arUser["WORK_COUNTRY"])));
             }
             if (strlen($arUser["PERSONAL_STREET"]) > 0 || strlen($arUser["PERSONAL_CITY"]) > 0 || strlen($arUser["PERSONAL_COUNTRY"]) > 0) {
                 $arResult["iq"]["vCard"]["ADR"][] = array("HOME" => array("#" => ""), "EXTADD" => array("#" => ""), "STREET" => array("#" => $arUser["PERSONAL_STREET"]), "LOCALITY" => array("#" => $arUser["PERSONAL_CITY"]), "REGION" => array("#" => $arUser["PERSONAL_STATE"]), "PCODE" => array("#" => $arUser["PERSONAL_ZIP"]), "CTRY" => array("#" => GetCountryByID($arUser["PERSONAL_COUNTRY"])));
             }
             if ($senderJId != $to) {
                 $arResult["iq"]["."]["from"] = $to;
             }
             //print_r($arResult);echo "\n*****************************************\n";
         } else {
             $arResult = array("iq" => array("." => array("type" => "error", "to" => $senderJId, "id" => $arMessage['iq']['.']['id']), "vCard" => array("." => array("xmlns" => "vcard-temp")), "error" => array("." => array("type" => "cancel"), "item-not-found" => array("." => array("xmlns" => "urn:ietf:params:xml:ns:xmpp-stanzas")))));
             if ($senderJId != $to) {
                 $arResult["iq"]["."]["from"] = $to;
             }
         }
     } elseif ($type == "set") {
         $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id'])));
     }
     return $arResult;
 }
Пример #3
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("message", $arMessage) || !array_key_exists(".", $arMessage["message"])) {
         return false;
     }
     $type = "normal";
     if (array_key_exists("type", $arMessage["message"]["."])) {
         $type = $arMessage["message"]["."]["type"];
     }
     if ($type == "error") {
         return false;
     }
     $mid = "";
     if (array_key_exists("id", $arMessage["message"]["."])) {
         $mid = $arMessage["message"]["."]["id"];
     }
     if (!in_array($type, array("chat", "groupchat", "headline", "normal"))) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "modify", "bad-request", "", $mid, "", $senderClient->GetClientDomain());
     }
     $recipientJId = "";
     if (array_key_exists("to", $arMessage["message"]["."])) {
         $recipientJId = $arMessage["message"]["."]["to"];
     }
     if (strlen($recipientJId) <= 0) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "modify", "bad-request", "", $mid, "", $senderClient->GetClientDomain());
     }
     $body = "";
     if (array_key_exists("body", $arMessage["message"])) {
         $body = $arMessage["message"]["body"]["#"];
     }
     if (strlen($body) <= 0) {
         return true;
     }
     //$body = CXMPPReceiveMessage::htmlspecialcharsback($body);
     //$body = html_entity_decode($body);
     $body = html_entity_decode($body, ENT_COMPAT, SITE_CHARSET);
     $body = str_replace("&apos;", "'", $body);
     $arSender = CXMPPUtility::GetUserByJId($senderJId);
     if (!$arSender) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "auth", "forbidden", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     $arRecipient = CXMPPUtility::GetUserByJId($recipientJId);
     if (!$arRecipient) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "cancel", "item-not-found", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     if (!CSocNetUserPerms::CanPerformOperation($arSender["ID"], $arRecipient["ID"], "message", false)) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "auth", "forbidden", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     if (IsModuleInstalled("im") && CModule::IncludeModule("im")) {
         $arMessageFields = array("FROM_USER_ID" => $arSender["ID"], "TO_USER_ID" => $arRecipient["ID"], "MESSAGE" => $body);
         CIMMessage::Add($arMessageFields);
     } else {
         $arMessageFields = array("=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_PRIVATE, "FROM_USER_ID" => $arSender["ID"], "TO_USER_ID" => $arRecipient["ID"], "MESSAGE" => $body);
         CSocNetMessages::Add($arMessageFields);
     }
     return true;
 }
Пример #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;
 }