예제 #1
0
 /**
  * Get last answer or comment.
  * 
  * @param bool $onlyVisible default true
  * @return CMA_Answer|CMA_Comment
  */
 public function getLastComment($onlyVisible = true)
 {
     global $wpdb;
     //         if( empty($format) )
     //         {
     //             $format = get_option('date_format') . ' ' . get_option('time_format');
     //         }
     $records = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments}\n        \tWHERE comment_post_ID = %d AND comment_approved = 1\n        \tORDER BY comment_ID DESC", $this->getId()));
     foreach ($records as $record) {
         if ($record->comment_type == CMA_Answer::COMMENT_TYPE) {
             if ($answer = new CMA_Answer($record)) {
                 if (!$onlyVisible or $answer->isVisible()) {
                     return $answer;
                 }
             }
         } else {
             if ($comment = new CMA_Comment($record)) {
                 if (!$onlyVisible or $comment->isVisible()) {
                     return $comment;
                 }
             }
         }
     }
     //         $lastAnswer = $this->getLastAnswer();
     //         if( $lastAnswer )
     //         {
     //             $dateString = $lastAnswer->getDate();
     //         }
     //         else
     //         {
     //             $dateString = $this->post->post_modified;
     //         }
     //         return date_i18n($format, strtotime($dateString));
 }
 protected static function processUnmarkSpam()
 {
     if (!empty($_GET['nonce']) and wp_verify_nonce($_GET['nonce'], self::ADMIN_UNMARK_SPAM)) {
         // Answer
         if (!empty($_GET['answer_id'])) {
             if ($answer = CMA_Answer::getById($_GET['answer_id'])) {
                 if ($answer->canUnmarkSpam()) {
                     $answer->markAsSpam(0);
                 } else {
                     die('Cannot unmark spam.');
                 }
             } else {
                 die('Unknown answer.');
             }
         }
         // Comment
         if (!empty($_GET['comment_id'])) {
             if ($comment = CMA_Comment::getById($_GET['comment_id'])) {
                 if ($comment->canUnmarkSpam()) {
                     $comment->markAsSpam(0);
                 } else {
                     die('Cannot unmark spam.');
                 }
             } else {
                 die('Unknown comment.');
             }
         }
         if (!empty($_GET['backlink'])) {
             wp_safe_redirect(base64_decode(urldecode($_GET['backlink'])));
             exit;
         }
     } else {
         die('Invalid nonce.');
     }
 }
 protected static function displayComments($threadId, $answerId)
 {
     if (empty(self::$commentsCache[$threadId])) {
         self::$commentsCache[$threadId] = CMA_Comment::getCommentsByThread($threadId);
     }
     if (!empty(self::$commentsCache[$threadId][$answerId])) {
         $comments = self::$commentsCache[$threadId][$answerId];
     } else {
         $comments = array();
     }
     echo self::_loadView('answer/comments/comments-block', compact('comments', 'threadId', 'answerId'));
 }
 public static function processAnwserStatusChange($answerId, $status)
 {
     /*
      * Get the comment, author, thread
      */
     $answer = get_comment($answerId);
     /*
      * Comment not found
      */
     if (!$answer) {
         return;
     }
     // Comment is not a CMA answer nor comment
     if ($answer->comment_type != CMA_Answer::COMMENT_TYPE and $answer->comment_type != CMA_Comment::COMMENT_TYPE) {
         return;
     }
     $thread = CMA_Thread::getInstance($answer->comment_post_ID);
     /*
      * Fix in case $thread isn't found
      */
     if (is_object($thread)) {
         $thread->updateThreadMetadata(array('answerId' => $answerId));
         if ($status == 'approve') {
             // Send notifications
             $thread->setUpdated();
             if ($answer->comment_type == CMA_Answer::COMMENT_TYPE) {
                 $thread->notifyAboutNewAnswer($answerId);
             } else {
                 if ($comment = CMA_Comment::getById($answerId)) {
                     $comment->sendNotifications();
                 }
             }
         } else {
             $thread->clearCache();
         }
     }
 }