示例#1
0
 /**
  * Function will send the compose message ;
  *
  * @param          : $sMessageSubject     (string) - message's subject ;
  * @param          : $sMessageBody        (string) - message's body ;
  * @param          : $vRecipientID        (variant)- message's recipient ID or NickName;
  * @param          : $aComposeSettings    (array)  - contain all needed settings for compose message ;
  * 					[ send_copy	] (bolean)     - allow to send message to phisical recipient's email ;
  * 					[ notification ] (boolean) - allow to send notification to the recipient's email ;
  * 					[ send_copy_to_me ] (boolean) - allow to send message to phisical sender's email ;
  * @return         : signaling information with Html ;
  */
 function sendMessage($sMessageSubject, $sMessageBody, $vRecipientID, &$aComposeSettings, $isSimulateSending = false)
 {
     $sMessageSubject = process_db_input($sMessageSubject, BX_TAGS_STRIP);
     $sMessageSubjectCopy = $GLOBALS['MySQL']->unescape($sMessageSubject);
     $sMessageBody = process_db_input($sMessageBody, BX_TAGS_VALIDATE);
     $sCopyMessage = $GLOBALS['MySQL']->unescape($sMessageBody);
     if (!$isSimulateSending && (!$sMessageSubject || !$sMessageBody)) {
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_FAILED;
         return MsgBox(_t('_please_fill_next_fields_first'));
     }
     // init some needed variables ;
     $sReturnMessage = null;
     $sComposeUrl = BX_DOL_URL_ROOT . 'mail.php?mode=compose';
     // try to define member's ID ;
     $iRecipientID = (int) getId($vRecipientID);
     if (!$iRecipientID) {
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_UNKNOWN_RECIPIENT;
         return MsgBox(_t('_Profile not found'));
     }
     $aRecipientInfo = getProfileInfo($iRecipientID);
     $oEmailTemplate = new BxDolEmailTemplates();
     $bAllowToSend = true;
     $this->iSendMessageStatusCode = BX_MAILBOX_SEND_FAILED;
     // ** check permission for recipient member ;
     // Check if member is blocked ;
     $sQuery = "\n                     SELECT\n                          `ID`, `Profile`\n                     FROM\n                          `sys_block_list`\n                     WHERE\n                          `Profile` = {$this->aMailBoxSettings['member_id']}\n                               AND\n                          `ID` = '{$iRecipientID}'\n                ";
     if (!isAdmin($this->aMailBoxSettings['member_id']) && db_arr($sQuery)) {
         $sReturnMessage = MsgBox(_t('_FAILED_TO_SEND_MESSAGE_BLOCK'));
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_BLOCKED;
         $bAllowToSend = false;
     }
     // antispam check ;
     $sQuery = "\n                         SELECT\n                              `ID`\n                         FROM\n                              `sys_messages`\n                         WHERE\n                              `Sender` = {$this->aMailBoxSettings['member_id']}\n                                   AND\n                              date_add(`Date`, INTERVAL {$this->iWaitMinutes} MINUTE) > Now()\n                    ";
     if (db_arr($sQuery)) {
         $sReturnMessage = MsgBox(_t('_You have to wait for PERIOD minutes before you can write another message!', $this->iWaitMinutes, $sComposeUrl));
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_WAIT;
         $bAllowToSend = false;
     }
     // additional antispam check ;
     if (bx_is_spam($sCopyMessage)) {
         $sReturnMessage = MsgBox(sprintf(_t("_sys_spam_detected"), BX_DOL_URL_ROOT . 'contact.php'));
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_FAILED;
         $bAllowToSend = false;
     }
     // check if member not active ;
     if ($aRecipientInfo['Status'] != 'Active') {
         $sReturnMessage = MsgBox(_t('_FAILED_TO_SEND_MESSAGE_NOT_ACTIVE', $sComposeUrl));
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_RECIPIENT_NOT_ACTIVE;
         $bAllowToSend = false;
     }
     // chek membership level;
     if (!$this->isSendMessageAlowed($this->aMailBoxSettings['member_id'], $isSimulateSending ? false : true)) {
         $sReturnMessage = MsgBox(_t('_FAILED_TO_SEND_MESSAGE_MEMBERSHIP_DISALLOW'));
         $this->iSendMessageStatusCode = BX_MAILBOX_SEND_FAILED_MEMBERSHIP_DISALLOW;
         $bAllowToSend = false;
     }
     // ** allow to send message ;
     if (!$isSimulateSending && $bAllowToSend) {
         $sQuery = "\n                        INSERT INTO\n                            `sys_messages`\n                        SET\n                            `Sender`       = {$this->aMailBoxSettings['member_id']},\n                            `Recipient`    = {$iRecipientID},\n                            `Subject`      =  '{$sMessageSubject}',\n                            `Text`         =  '{$sMessageBody}',\n                            `Date`         = NOW(),\n                            `New`          = '1',\n                            `Type`         = 'letter'\n                    ";
         if (db_res($sQuery)) {
             $sReturnMessage = MsgBox(_t('_MESSAGE_SENT', $sComposeUrl, getProfileLink($iRecipientID), $aRecipientInfo['NickName']));
             $this->iSendMessageStatusCode = BX_MAILBOX_SEND_SUCCESS;
             //--- create system event
             bx_import('BxDolAlerts');
             $aAlertData = array('msg_id' => db_last_id(), 'subject' => $sMessageSubjectCopy, 'body' => $sCopyMessage, 'send_copy' => $aComposeSettings['send_copy'], 'notification' => $aComposeSettings['notification'], 'send_copy_to_me' => $aComposeSettings['send_copy_to_me']);
             $oZ = new BxDolAlerts('profile', 'send_mail_internal', $this->aMailBoxSettings['member_id'], $iRecipientID, $aAlertData);
             $oZ->alert();
             // ** check the additional parameters ;
             // send message to phisical recipient's email ;
             if ($aComposeSettings['send_copy']) {
                 $aTemplate = $oEmailTemplate->getTemplate('t_Message', $iRecipientID);
                 $aPlus = array();
                 $aPlus['MessageText'] = replace_full_uris($sCopyMessage);
                 $aPlus['ProfileReference'] = getNickName($this->aMailBoxSettings['member_id']);
                 $aPlus['ProfileUrl'] = getProfileLink($this->aMailBoxSettings['member_id']);
                 sendMail($aRecipientInfo['Email'], $sMessageSubjectCopy, $aTemplate['Body'], $iRecipientID, $aPlus);
             }
             // send notification to the recipient's email ;
             if ($aComposeSettings['notification']) {
                 $aTemplate = $oEmailTemplate->getTemplate('t_Compose', $iRecipientID);
                 $aPlus['ProfileReference'] = getNickName($this->aMailBoxSettings['member_id']);
                 $aPlus['ProfileUrl'] = getProfileLink($this->aMailBoxSettings['member_id']);
                 sendMail($aRecipientInfo['Email'], $aTemplate['Subject'], $aTemplate['Body'], $iRecipientID, $aPlus);
             }
             // allow to send message to phisical sender's email;
             if ($aComposeSettings['send_copy_to_me']) {
                 $aSenderInfo = getProfileInfo($this->aMailBoxSettings['member_id']);
                 $aTemplate = $oEmailTemplate->getTemplate('t_MessageCopy', $this->aMailBoxSettings['member_id']);
                 $aPlus['your subject here'] = $sMessageSubjectCopy;
                 $aPlus['your message here'] = replace_full_uris($sCopyMessage);
                 sendMail($aSenderInfo['Email'], $aTemplate['Subject'], $aTemplate['Body'], $this->aMailBoxSettings['member_id'], $aPlus);
             }
         } else {
             $sReturnMessage = MsgBox(_t('_FAILED_TO_SEND_MESSAGE'));
             $this->iSendMessageStatusCode = BX_MAILBOX_SEND_FAILED;
         }
     }
     return $sReturnMessage;
 }
/**
 * Send message
 */
function MemberSendMessage($member, $recipient, $must_use_credits = false)
{
    global $site;
    $en_dest_choice = getParam("enable_msg_dest_choice");
    $max_message_size = getParam("max_inbox_message_size");
    $max_messages = getParam("max_inbox_messages");
    // Check if recipient is active
    if ('Active' != $recipient['Status']) {
        return 10;
    }
    // Check if member is blocked
    if (db_arr("SELECT `ID`, `Profile` FROM `BlockList` WHERE `Profile` = {$member['ID']} AND `ID` = '{$recipient['ID']}';")) {
        return 5;
    }
    // If must use credits then check for enough amount
    if ($must_use_credits && getProfileCredits($member['ID']) < (double) $msg_credits) {
        return 21;
    }
    // antispam ))
    if (db_arr("SELECT `ID` FROM `Messages` WHERE `Sender` = {$member[ID]} AND date_add(`Date`, INTERVAL 1 MINUTE) > Now()")) {
        return 3;
    }
    // Get sender info
    $sender = getProfileInfo($member['ID']);
    $aPlus = array();
    $aPlus['ProfileReference'] = $sender ? '<a href="' . getProfileLink($member['ID']) . '">' . $sender['NickName'] . '</a> (' . getProfileLink($member['ID']) . ') ' : '<b>' . _t("_Visitor") . '</b>';
    // Don't send notification if message is sending to email
    if ($_POST['notify'] && !($_POST['sendto'] == "email" || $_POST['sendto'] == "both")) {
        $message_text = getParam("t_Compose");
        $subject = getParam('t_Compose_subject');
        $aPlus['senderNickName'] = $sender ? $sender['NickName'] : _t("_Visitor");
        $notify_res = sendMail($recipient['Email'], $subject, $message_text, $recipient['ID'], $aPlus);
        if (!$notify_res) {
            echo "<div class=\"err\">" . _t("_Notification send failed") . "</div><br />\n";
        }
    }
    // Send message to email
    if ($en_dest_choice && ($_POST['sendto'] == "email" || $_POST['sendto'] == "both")) {
        $message_text = getParam("t_Message");
        $subject = process_pass_data($_POST['mes_subject']);
        $aPlus['MessageText'] = strmaxtextlen(clear_xss(replace_full_uris(process_pass_data($_POST['text']))), $max_message_size);
        $result = sendMail($recipient['Email'], $subject, $message_text, $recipient['ID'], $aPlus);
    }
    // Send message to communicator
    if ($_POST['sendto'] == "lovemail" || $_POST['sendto'] == "both") {
        // Restrict with total messages count
        $messages_count = db_arr("SELECT COUNT(*) AS `mess_count` FROM `Messages` WHERE `Recipient` = '{$recipient['ID']}'");
        $messages_count = $messages_count['mess_count'];
        if ($messages_count - 1 > $max_messages) {
            $del_res = db_res("SELECT `ID` FROM `Messages` WHERE `Recipient` = '{$recipient['ID']}' ORDER BY `Date` ASC LIMIT " . ($messages_count - $max_messages + 1));
            while ($del_arr = mysql_fetch_array($del_res)) {
                db_res("DELETE FROM `Messages` WHERE `ID` = {$del_arr['ID']}");
            }
        }
        // Insert message into database
        $message_text = strmaxtextlen(addslashes(clear_xss(process_pass_data($_POST['text']))), $max_message_size);
        $message_subject = strmaxwordlen(process_db_input($_POST['mes_subject']), 30);
        $result = db_res("INSERT INTO `Messages` ( `Date`, `Sender`, `Recipient`, `Text`, `Subject`, `New` ) VALUES ( NOW(), {$member['ID']}, {$recipient['ID']}, '{$message_text}', '{$message_subject}', '1' )");
    }
    // If sending successful then mark as performed action
    if ($result) {
        checkAction($member['ID'], ACTION_ID_SEND_MESSAGE, true);
        if ($must_use_credits) {
            decProfileCredits($member['ID'], $msg_credits);
        }
    } else {
        return 1;
    }
    return 0;
}