public function getMessageObject()
 {
     if (!isset($this->message)) {
         $this->message = PrivateMessage::getByID($this->msgID);
     }
     return $this->message;
 }
 public function get($itemsToGet = 0, $offset = 0)
 {
     $r = parent::get($itemsToGet, $offset);
     foreach ($r as $row) {
         $messages[] = UserPrivateMessage::getByID($row['msgID'], $this->mailbox);
     }
     return $messages;
 }
 public function process($mail)
 {
     // now that we're here, we know that we're validated and that this is an email
     // coming from someone proper.
     // We need to know what to do with it, now. We check the "data" column, which stores
     // a serialized PHP object that contains relevant information about what this item needs to respond to, post to, etc...
     $do = $mail->getDataObject();
     if ($do->msgID > 0) {
         $upm = UserPrivateMessage::getByID($do->msgID);
         if (is_object($upm)) {
             $originalTo = UserInfo::getByID($do->toUID);
             $originalFrom = UserInfo::getByID($do->fromUID);
             if (is_object($originalTo) && is_object($originalFrom)) {
                 $body = $mail->getProcessedBody();
                 $originalTo->sendPrivateMessage($originalFrom, $mail->getSubject(), $body, $upm);
             }
         }
     }
 }
Beispiel #4
0
 public function reply($boxID, $msgID)
 {
     $dh = Core::make('helper/date');
     /* @var $dh \Concrete\Core\Localization\Service\Date */
     $msg = UserPrivateMessage::getByID($msgID);
     $uID = $msg->getMessageRelevantUserID();
     $this->validateUser($uID);
     $this->set('backURL', View::url('/account/messages/inbox', 'view_message', $boxID, $msgID));
     $this->set('msgID', $msgID);
     $this->set('box', $boxID);
     $this->set('msg', $msg);
     $this->set('msgSubject', $msg->getFormattedMessageSubject());
     $body = "\n\n\n" . $msg->getMessageDelimiter() . "\n";
     $body .= t("From: %s\nDate Sent: %s\nSubject: %s", $msg->getMessageAuthorName(), $dh->formatDateTime($msg->getMessageDateAdded(), true), $msg->getFormattedMessageSubject());
     $body .= "\n\n" . $msg->getMessageBody();
     $this->set('msgBody', $body);
 }
Beispiel #5
0
 public function getLastMessageObject()
 {
     if ($this->lastMessageID > 0) {
         return PrivateMessage::getByID($this->lastMessageID, $this);
     }
 }
Beispiel #6
0
 /**
  * @param \Concrete\Core\User\PrivateMessage\PrivateMessage $msg
  *
  * @return bool
  */
 public function canReadPrivateMessage($msg)
 {
     return $msg->getMessageUserID() == $this->getUserID();
 }
Beispiel #7
0
 /**
  * @param UserInfo $recipient
  * @param string $subject
  * @param string $text
  * @param \Concrete\Core\User\PrivateMessage\PrivateMessage $inReplyTo
  *
  * @return \Concrete\Core\Error\ErrorList\ErrorList|false|null
  */
 public function sendPrivateMessage($recipient, $subject, $text, $inReplyTo = false)
 {
     if (Limit::isOverLimit($this->getUserID())) {
         return Limit::getErrorObject();
     }
     $antispam = Core::make('helper/validation/antispam');
     $messageText = t('Subject: %s', $subject);
     $messageText .= "\n";
     $messageText .= t('Message: %s', $text);
     $additionalArgs = array('user' => $this);
     if (!$antispam->check($messageText, 'private_message', $additionalArgs)) {
         return false;
     }
     $subject = $subject == '' ? t('(No Subject)') : $subject;
     $db = $this->connection;
     $dt = Core::make('helper/date');
     $msgDateCreated = $dt->getOverridableNow();
     $v = array($this->getUserID(), $msgDateCreated, $subject, $text, $recipient->getUserID());
     $db->Execute('insert into UserPrivateMessages (uAuthorID, msgDateCreated, msgSubject, msgBody, uToID) values (?, ?, ?, ?, ?)', $v);
     $msgID = $db->Insert_ID();
     if ($msgID > 0) {
         // we add the private message to the sent box of the sender, and the inbox of the recipient
         $v = array($msgID, $this->getUserID(), $this->getUserID(), UserPrivateMessageMailbox::MBTYPE_SENT, 0, 1);
         $db->Execute('insert into UserPrivateMessagesTo (msgID, uID, uAuthorID, msgMailboxID, msgIsNew, msgIsUnread) values (?, ?, ?, ?, ?, ?)', $v);
         $v = array($msgID, $recipient->getUserID(), $this->getUserID(), UserPrivateMessageMailbox::MBTYPE_INBOX, 1, 1);
         $db->Execute('insert into UserPrivateMessagesTo (msgID, uID, uAuthorID, msgMailboxID, msgIsNew, msgIsUnread) values (?, ?, ?, ?, ?, ?)', $v);
     }
     // If the message is in reply to another message, we make a note of that here
     if (is_object($inReplyTo)) {
         $db->Execute('update UserPrivateMessagesTo set msgIsReplied = 1 where uID = ? and msgID = ?', array($this->getUserID(), $inReplyTo->getMessageID()));
     }
     // send the email notification
     if ($recipient->getAttribute('profile_private_messages_notification_enabled')) {
         $mh = Core::make('mail');
         $mh->addParameter('msgSubject', $subject);
         $mh->addParameter('msgBody', $text);
         $mh->addParameter('msgAuthor', $this->getUserName());
         $mh->addParameter('msgDateCreated', $msgDateCreated);
         $mh->addParameter('profileURL', $this->getUserPublicProfileUrl());
         $mh->addParameter('profilePreferencesURL', View::url('/account/profile/edit'));
         $mh->to($recipient->getUserEmail());
         $mh->addParameter('siteName', tc('SiteName', \Core::make('site')->getSite()->getSiteName()));
         $mi = MailImporter::getByHandle("private_message");
         if (is_object($mi) && $mi->isMailImporterEnabled()) {
             $mh->load('private_message_response_enabled');
             // we store information ABOUT the message here. The mail handler has to know how to handle this.
             $data = new \stdClass();
             $data->msgID = $msgID;
             $data->toUID = $recipient->getUserID();
             $data->fromUID = $this->getUserID();
             $mh->enableMailResponseProcessing($mi, $data);
         } else {
             $mh->load('private_message');
         }
         $mh->sendMail();
     }
     $msg = PrivateMessage::getByID($msgID);
     $type = $this->application->make('manager/notification/types')->driver('new_private_message');
     $notifier = $type->getNotifier();
     $subscription = $type->getSubscription($msg);
     $notified = $notifier->getUsersToNotify($subscription, $msg);
     $notification = $type->createNotification($msg);
     $notifier->notify($notified, $notification);
 }