コード例 #1
0
 /**
  * Adds a response.
  * 
  * @return	array
  */
 public function addResponse()
 {
     if (!empty($this->validationErrors)) {
         if (!empty($this->parameters['data']['username'])) {
             WCF::getSession()->register('username', $this->parameters['data']['username']);
         }
         WCF::getTPL()->assign('errorType', $this->validationErrors);
         $guestDialog = $this->getGuestDialog();
         return array('useCaptcha' => $guestDialog['useCaptcha'], 'guestDialog' => $guestDialog['template']);
     }
     // create response
     $this->createdResponse = CommentResponseEditor::create(array('commentID' => $this->comment->commentID, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID ?: null, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->parameters['data']['username'], 'message' => $this->parameters['data']['message']));
     // update response data
     $responseIDs = $this->comment->getResponseIDs();
     if (count($responseIDs) < 5) {
         $responseIDs[] = $this->createdResponse->responseID;
     }
     $responses = $this->comment->responses + 1;
     // update comment
     $commentEditor = new CommentEditor($this->comment);
     $commentEditor->update(array('responseIDs' => serialize($responseIDs), 'responses' => $responses));
     // update counter
     $this->commentProcessor->updateCounter($this->parameters['data']['objectID'], 1);
     // fire activity event
     $objectType = ObjectTypeCache::getInstance()->getObjectType($this->comment->objectTypeID);
     if ($this->createdResponse->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent')) {
         UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType . '.response.recentActivityEvent', $this->createdResponse->responseID);
     }
     // fire notification event
     if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.notification')) {
         $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType . '.notification');
         $userID = $notificationObjectType->getOwnerID($this->comment->commentID);
         $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse);
         if ($this->comment->userID != WCF::getUser()->userID) {
             UserNotificationHandler::getInstance()->fireEvent('commentResponse', $objectType->objectType . '.response.notification', $notificationObject, array($this->comment->userID), array('commentID' => $this->comment->commentID, 'objectID' => $this->comment->objectID, 'objectUserID' => $userID, 'userID' => $this->comment->userID));
         }
         // notify the container owner
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.notification')) {
             if ($userID != $this->comment->userID && $userID != WCF::getUser()->userID) {
                 UserNotificationHandler::getInstance()->fireEvent('commentResponseOwner', $objectType->objectType . '.response.notification', $notificationObject, array($userID), array('commentID' => $this->comment->commentID, 'objectID' => $this->comment->objectID, 'objectUserID' => $userID, 'userID' => $this->comment->userID));
             }
         }
     }
     if (!$this->createdResponse->userID) {
         // save user name is session
         WCF::getSession()->register('username', $this->createdResponse->username);
         // save last comment time for flood control
         WCF::getSession()->register('lastCommentTime', $this->createdResponse->time);
         // reset captcha for future requests
         if ($this->captchaObjectType) {
             $this->captchaObjectType->getProcessor()->reset();
         }
     }
     return array('commentID' => $this->comment->commentID, 'template' => $this->renderResponse($this->createdResponse), 'responses' => $responses);
 }
コード例 #2
0
 /**
  * Edits a comment or response.
  * 
  * @return	array
  */
 public function edit()
 {
     $returnValues = array('action' => 'saved');
     if ($this->response === null) {
         $editor = new CommentEditor($this->comment);
         $editor->update(array('message' => $this->parameters['data']['message']));
         $comment = new Comment($this->comment->commentID);
         $returnValues['commentID'] = $this->comment->commentID;
         $returnValues['message'] = $comment->getFormattedMessage();
     } else {
         $editor = new CommentResponseEditor($this->response);
         $editor->update(array('message' => $this->parameters['data']['message']));
         $response = new CommentResponse($this->response->responseID);
         $returnValues['responseID'] = $this->response->responseID;
         $returnValues['message'] = $response->getFormattedMessage();
     }
     return $returnValues;
 }