Beispiel #1
0
 public function prepareApiDataForPost(array $post, array $thread, array $forum)
 {
     /* @var $forumModel XenForo_Model_Forum */
     $forumModel = $this->getModelFromCache('XenForo_Model_Forum');
     $post = $this->preparePost($post, $thread, $forum);
     $attachments = array();
     if (!empty($post['attachments'])) {
         $attachments = $post['attachments'];
     }
     if (!isset($post['messageHtml'])) {
         $post['messageHtml'] = bdApi_Data_Helper_Message::getHtml($post);
     }
     if (isset($post['message'])) {
         $post['messagePlainText'] = bdApi_Data_Helper_Message::getPlainText($post['message']);
     }
     if (isset($post['signature'])) {
         $post['signaturePlainText'] = bdApi_Data_Helper_Message::getPlainText($post['signature']);
     }
     $publicKeys = array('post_id' => 'post_id', 'thread_id' => 'thread_id', 'user_id' => 'poster_user_id', 'username' => 'poster_username', 'post_date' => 'post_create_date', 'message' => 'post_body', 'messageHtml' => 'post_body_html', 'messagePlainText' => 'post_body_plain_text', 'signature' => 'signature', 'signatureHtml' => 'signature_html', 'signaturePlainText' => 'signature_plain_text', 'likes' => 'post_like_count', 'attach_count' => 'post_attachment_count');
     $data = bdApi_Data_Helper_Core::filter($post, $publicKeys);
     $data['user_is_ignored'] = XenForo_Visitor::getInstance()->isIgnoring($post['user_id']);
     if (isset($post['message_state'])) {
         switch ($post['message_state']) {
             case 'visible':
                 $data['post_is_published'] = true;
                 $data['post_is_deleted'] = false;
                 break;
             case 'moderated':
                 $data['post_is_published'] = false;
                 $data['post_is_deleted'] = false;
                 break;
             case 'deleted':
                 $data['post_is_published'] = false;
                 $data['post_is_deleted'] = true;
                 break;
         }
     }
     if (isset($post['last_edit_date'])) {
         // since XenForo 1.2.0
         if ($post['last_edit_date'] > 0) {
             $data['post_update_date'] = $post['last_edit_date'];
         } else {
             // by default, last_edit_date = 0
             $data['post_update_date'] = $post['post_date'];
         }
     }
     if (isset($post['position'])) {
         $data['post_is_first_post'] = intval($post['position']) === 0;
     }
     if (isset($post['like_date'])) {
         $data['post_is_liked'] = !empty($post['like_date']);
     }
     if (!empty($attachments)) {
         $data['attachments'] = $this->prepareApiDataForAttachments($attachments, $post, $thread, $forum);
     }
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('posts', $post), 'detail' => bdApi_Data_Helper_Core::safeBuildApiLink('posts', $post), 'thread' => bdApi_Data_Helper_Core::safeBuildApiLink('threads', $post), 'poster' => bdApi_Data_Helper_Core::safeBuildApiLink('users', $post), 'likes' => bdApi_Data_Helper_Core::safeBuildApiLink('posts/likes', $post), 'report' => bdApi_Data_Helper_Core::safeBuildApiLink('posts/report', $post), 'attachments' => bdApi_Data_Helper_Core::safeBuildApiLink('posts/attachments', $post), 'poster_avatar' => XenForo_Template_Helper_Core::callHelper('avatar', array($post, 'm', false, true)));
     if (!empty($post['attach_count'])) {
         $data['links']['attachments'] = bdApi_Data_Helper_Core::safeBuildApiLink('posts/attachments', $post);
     }
     $data['permissions'] = array('view' => $this->canViewPost($post, $thread, $forum), 'edit' => $this->canEditPost($post, $thread, $forum), 'delete' => $this->canDeletePost($post, $thread, $forum), 'reply' => $this->_getThreadModel()->canReplyToThread($thread, $forum), 'like' => $this->canLikePost($post, $thread, $forum), 'report' => $this->canReportPost($post, $thread, $forum), 'upload_attachment' => $this->canEditPost($post, $thread, $forum) and $forumModel->canUploadAndManageAttachment($forum));
     return $data;
 }
Beispiel #2
0
 public function prepareApiDataForMessage(array $message, array $conversation)
 {
     $message = $this->prepareMessage($message, $conversation);
     $attachments = array();
     if (!empty($message['attachments'])) {
         $attachments = $message['attachments'];
     }
     if (!isset($message['messageHtml'])) {
         $message['messageHtml'] = bdApi_Data_Helper_Message::getHtml($message);
     }
     if (isset($message['message'])) {
         $message['messagePlainText'] = bdApi_Data_Helper_Message::getPlainText($message['message']);
     }
     if (isset($message['signature'])) {
         $message['signaturePlainText'] = bdApi_Data_Helper_Message::getPlainText($message['signature']);
     }
     $publicKeys = array('message_id' => 'message_id', 'conversation_id' => 'conversation_id', 'user_id' => 'creator_user_id', 'username' => 'creator_username', 'message_date' => 'message_create_date', 'message' => 'message_body', 'messageHtml' => 'message_body_html', 'messagePlainText' => 'message_body_plain_text', 'signature' => 'signature', 'signatureHtml' => 'signature_html', 'signaturePlainText' => 'signature_plain_text', 'attach_count' => 'message_attachment_count');
     $data = bdApi_Data_Helper_Core::filter($message, $publicKeys);
     $data['user_is_ignored'] = XenForo_Visitor::getInstance()->isIgnoring($message['user_id']);
     if (!empty($attachments)) {
         $data['attachments'] = $this->prepareApiDataForAttachments($message, $attachments);
     }
     $data['links'] = array('detail' => bdApi_Data_Helper_Core::safeBuildApiLink('conversation-messages', $message), 'conversation' => bdApi_Data_Helper_Core::safeBuildApiLink('conversations', $conversation), 'creator' => bdApi_Data_Helper_Core::safeBuildApiLink('users', $message), 'creator_avatar' => XenForo_Template_Helper_Core::callHelper('avatar', array($message, 'm', false, true)), 'report' => bdApi_Data_Helper_Core::safeBuildApiLink('conversation-messages/report', $message));
     $data['permissions'] = array('view' => true, 'edit' => $this->canEditMessage($message, $conversation), 'delete' => false, 'reply' => $this->canReplyToConversation($conversation), 'upload_attachment' => $this->canUploadAndManageAttachment($conversation) and $this->canEditMessage($message, $conversation), 'report' => $this->canReportMessage($message, $conversation));
     return $data;
 }