/**
  * Returns a mixed conversation list with up to 5 unread conversations.
  * 
  * @return	array<mixed>
  */
 public function getMixedConversationList()
 {
     $unreadConversationList = new UserConversationList(WCF::getUser()->userID);
     $unreadConversationList->getConditionBuilder()->add('conversation_to_user.lastVisitTime < conversation.lastPostTime');
     $unreadConversationList->sqlLimit = 5;
     $unreadConversationList->sqlOrderBy = 'conversation.lastPostTime DESC';
     $unreadConversationList->readObjects();
     $conversations = array();
     $count = 0;
     foreach ($unreadConversationList as $conversation) {
         $conversations[] = $conversation;
         $count++;
     }
     if ($count < 5) {
         $conversationList = new UserConversationList(WCF::getUser()->userID);
         $conversationList->getConditionBuilder()->add('conversation_to_user.lastVisitTime >= conversation.lastPostTime');
         $conversationList->sqlLimit = 5 - $count;
         $conversationList->sqlOrderBy = 'conversation.lastPostTime DESC';
         $conversationList->readObjects();
         foreach ($conversationList as $conversation) {
             $conversations[] = $conversation;
         }
     }
     WCF::getTPL()->assign(array('conversations' => $conversations));
     $totalCount = ConversationHandler::getInstance()->getUnreadConversationCount();
     if ($count < 5 && $count < $totalCount) {
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
     }
     return array('template' => WCF::getTPL()->fetch('conversationListUserPanel'), 'totalCount' => $totalCount);
 }
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (!WCF::getUser()->userID) {
         return;
     }
     // check max pc permission
     if (ConversationHandler::getInstance()->getConversationCount() >= WCF::getSession()->getPermission('user.conversation.maxConversations')) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.conversation.error.mailboxIsFull'));
     }
     if (isset($_REQUEST['userID'])) {
         $userID = intval($_REQUEST['userID']);
         $user = UserProfile::getUserProfile($userID);
         if ($user === null || $user->userID == WCF::getUser()->userID) {
             throw new IllegalLinkException();
         }
         // validate user
         try {
             Conversation::validateParticipant($user);
         } catch (UserInputException $e) {
             throw new NamedUserException(WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.' . $e->getType(), array('errorData' => array('username' => $user->username))));
         }
         $this->participants = $user->username;
     }
     // get max text length
     $this->maxTextLength = WCF::getSession()->getPermission('user.conversation.maxLength');
     // quotes
     MessageQuoteManager::getInstance()->readParameters();
 }
Ejemplo n.º 3
0
 /**
  * add private conversation
  *
  * @param  Object  $oMbqEtPc
  */
 public function addMbqEtPc($oMbqEtPc)
 {
     //ref wcf\form\MessageForm,wcf\form\ConversationAddForm
     $oMbqEtPc->convTitle->setOriValue(StringUtil::trim($oMbqEtPc->convTitle->oriValue));
     $oMbqEtPc->convContent->setOriValue(MessageUtil::stripCrap(StringUtil::trim($oMbqEtPc->convContent->oriValue)));
     $attachmentObjectType = 'com.woltlab.wcf.conversation.message';
     $attachmentObjectID = 0;
     $tmpHash = StringUtil::getRandomID();
     $attachmentParentObjectID = 0;
     // check max pc permission
     if (ConversationHandler::getInstance()->getConversationCount() >= WCF::getSession()->getPermission('user.conversation.maxConversations')) {
         MbqError::alert('', 'Sorry.You can not create more conversations.', '', MBQ_ERR_APP);
     }
     //settings
     $preParse = $enableSmilies = $enableBBCodes = $showSignature = $enableHtml = 0;
     $preParse = 1;
     if (WCF::getSession()->getPermission('user.message.canUseSmilies')) {
         $enableSmilies = 1;
     }
     //if (WCF::getSession()->getPermission('user.message.canUseHtml')) $enableHtml = 1;
     if (WCF::getSession()->getPermission('user.message.canUseBBCodes')) {
         $enableBBCodes = 1;
     }
     $showSignature = 1;
     // get max text length
     $maxTextLength = WCF::getSession()->getPermission('user.conversation.maxLength');
     //begin validate
     try {
         $participantIDs = Conversation::validateParticipants(implode(",", $oMbqEtPc->userNames->oriValue));
     } catch (UserInputException $e) {
         MbqError::alert('', $e->getMessage(), '', MBQ_ERR_APP);
     } catch (Exception $e) {
         MbqError::alert('', $e->getMessage(), '', MBQ_ERR_APP);
     }
     if (empty($participantIDs)) {
         MbqError::alert('', 'Need valid participant user ids.', '', MBQ_ERR_APP);
     }
     // check number of participants
     if (count($participantIDs) > WCF::getSession()->getPermission('user.conversation.maxParticipants')) {
         MbqError::alert('', 'Too many participants.', '', MBQ_ERR_APP);
     }
     $allowedBBCodesPermission = 'user.message.allowedBBCodes';
     //validateSubject
     if (empty($oMbqEtPc->convTitle->oriValue)) {
         MbqError::alert('', "Need conversation title.", '', MBQ_ERR_APP);
     }
     if (StringUtil::length($oMbqEtPc->convTitle->oriValue) > 255) {
         MbqError::alert('', "Conversation title is too long.", '', MBQ_ERR_APP);
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($oMbqEtPc->convTitle->oriValue);
         if ($result) {
             MbqError::alert('', "Found censored words in conversation title.", '', MBQ_ERR_APP);
         }
     }
     //validateText
     if (empty($oMbqEtPc->convContent->oriValue)) {
         MbqError::alert('', "Need conversation content.", '', MBQ_ERR_APP);
     }
     // check text length
     if ($maxTextLength != 0 && StringUtil::length($oMbqEtPc->convContent->oriValue) > $maxTextLength) {
         MbqError::alert('', "Conversation content is too long.", '', MBQ_ERR_APP);
     }
     if ($enableBBCodes && $allowedBBCodesPermission) {
         $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($oMbqEtPc->convContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission))));
         if (!empty($disallowedBBCodes)) {
             MbqError::alert('', "Conversation content included disallowed bbcodes.", '', MBQ_ERR_APP);
         }
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($oMbqEtPc->convContent->oriValue);
         if ($result) {
             MbqError::alert('', "Found censored words in conversation content.", '', MBQ_ERR_APP);
         }
     }
     //language
     $languageID = NULL;
     //attachment
     if (MODULE_ATTACHMENT && $attachmentObjectType) {
         $attachmentHandler = new AttachmentHandler($attachmentObjectType, $attachmentObjectID, $tmpHash, $attachmentParentObjectID);
     }
     //save
     if ($preParse) {
         // BBCodes are enabled
         if ($enableBBCodes) {
             if ($allowedBBCodesPermission) {
                 $oMbqEtPc->convContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPc->convContent->oriValue, ArrayUtil::trim(explode(',', WCF::getSession()->getPermission($allowedBBCodesPermission)))));
             } else {
                 $oMbqEtPc->convContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPc->convContent->oriValue));
             }
         } else {
             $oMbqEtPc->convContent->setOriValue(PreParser::getInstance()->parse($oMbqEtPc->convContent->oriValue, array()));
         }
     }
     // save conversation
     $data = array('subject' => $oMbqEtPc->convTitle->oriValue, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID, 'username' => WCF::getUser()->username, 'isDraft' => 0, 'participantCanInvite' => 0);
     $conversationData = array('data' => $data, 'attachmentHandler' => $attachmentHandler, 'messageData' => array('message' => $oMbqEtPc->convContent->oriValue, 'enableBBCodes' => $enableBBCodes, 'enableHtml' => $enableHtml, 'enableSmilies' => $enableSmilies, 'showSignature' => $showSignature));
     $conversationData['participants'] = $participantIDs;
     $conversationData['invisibleParticipants'] = array();
     $objectAction = new ConversationAction(array(), 'create', $conversationData);
     $resultValues = $objectAction->executeAction();
     if ($resultValues['returnValues']->conversationID) {
         $convId = $resultValues['returnValues']->conversationID;
         $messageId = $resultValues['returnValues']->messageID;
         $oMbqRdEtPc = MbqMain::$oClk->newObj('MbqRdEtPc');
         $oMbqEtPc = $oMbqRdEtPc->initOMbqEtPc($convId, array('case' => 'byConvId'));
     } else {
         MbqError::alert('', "Can not create topic.", '', MBQ_ERR_APP);
     }
     return $oMbqEtPc;
 }
 /**
  * Validates the given participant.
  * 
  * @param	\wcf\data\user\UserProfile	$user
  * @param	string				$field
  */
 public static function validateParticipant(UserProfile $user, $field = 'participants')
 {
     // check participant's settings and permissions
     if (!$user->getPermission('user.conversation.canUseConversation')) {
         throw new UserInputException($field, 'canNotUseConversation');
     }
     if (!WCF::getSession()->getPermission('user.profile.cannotBeIgnored')) {
         // check if user wants to receive any conversations
         if ($user->canSendConversation == 2) {
             throw new UserInputException($field, 'doesNotAcceptConversation');
         }
         // check if user only wants to receive conversations by
         // users they are following and if the active user is followed
         // by the relevant user
         if ($user->canSendConversation == 1 && !$user->isFollowing(WCF::getUser()->userID)) {
             throw new UserInputException($field, 'doesNotAcceptConversation');
         }
         // active user is ignored by participant
         if ($user->isIgnoredUser(WCF::getUser()->userID)) {
             throw new UserInputException($field, 'ignoresYou');
         }
         // check participant's mailbox quota
         if (ConversationHandler::getInstance()->getConversationCount($user->userID) >= $user->getPermission('user.conversation.maxConversations')) {
             throw new UserInputException($field, 'mailboxIsFull');
         }
     }
 }