/** * @param UserInfo $recipient * @param string $subject * @param string $text * @param \Concrete\Core\User\PrivateMessage\PrivateMessage $inReplyTo * * @return \Concrete\Core\Error\Error|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', Config::get('concrete.site')); $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(); } }
/** * Gets the value of the attribute for the user */ public function getAttribute($ak, $displayMode = false) { return parent::getAttribute($ak, $displayMode); }