Esempio n. 1
0
 public function prepareParams()
 {
     if (!empty($this->_params['_user']['user_id'])) {
         bdApi_ViewApi_Helper_Subscription::prepareDiscoveryParams($this->_params, $this->_response, bdApi_Model_Subscription::TYPE_USER, $this->_params['_user']['user_id'], bdApi_Data_Helper_Core::safeBuildApiLink('users', $this->_params['_user'], array('oauth_token' => '')), isset($this->_params['_user']['bdapi_user']) ? $this->_params['_user']['bdapi_user'] : '');
     }
     parent::prepareParams();
 }
Esempio n. 2
0
 public static function prepareDiscoveryParams(array &$params, Zend_Controller_Response_Http $response, $topicType, $topicId, $selfLink, $subscriptionOption)
 {
     if (!bdApi_Option::getSubscription($topicType)) {
         // subscription for this topic type has been disabled
         return false;
     }
     // subscription discovery
     $hubLink = bdApi_Data_Helper_Core::safeBuildApiLink('subscriptions', null, array('hub.topic' => bdApi_Model_Subscription::getTopic($topicType, $topicId), 'oauth_token' => ''));
     $response->setHeader('Link', sprintf('<%s>; rel=hub', $hubLink));
     $response->setHeader('Link', sprintf('<%s>; rel=self', $selfLink));
     // subscription info
     if (!empty($subscriptionOption)) {
         $subscriptionOption = @unserialize($subscriptionOption);
         if (!empty($subscriptionOption['subscriptions'])) {
             /* @var $session bdApi_Session */
             $session = XenForo_Application::getSession();
             $clientId = $session->getOAuthClientId();
             foreach ($subscriptionOption['subscriptions'] as $subscription) {
                 if ($subscription['client_id'] == $clientId) {
                     $params['subscription_callback'] = $subscription['callback'];
                 }
             }
         }
     }
     return true;
 }
Esempio n. 3
0
 public function actionGetIndex()
 {
     $messageId = $this->_input->filterSingle('message_id', XenForo_Input::UINT);
     if (!empty($messageId)) {
         return $this->responseReroute(__CLASS__, 'single');
     }
     $conversationId = $this->_input->filterSingle('conversation_id', XenForo_Input::UINT);
     if (empty($conversationId)) {
         return $this->responseError(new XenForo_Phrase('bdapi_slash_conversation_messages_requires_conversation_id'), 400);
     }
     $conversation = $this->_getConversationOrError($conversationId);
     $pageNavParams = array('conversation_id' => $conversation['conversation_id']);
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $limit = XenForo_Application::get('options')->messagesPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     $fetchOptions = array('limit' => $limit, 'page' => $page);
     $messages = $this->_getConversationModel()->getConversationMessages($conversation['conversation_id'], $this->_getConversationModel()->getFetchOptionsToPrepareApiDataForMessages($fetchOptions));
     if (!$this->_isFieldExcluded('attachments')) {
         $messages = $this->_getConversationModel()->getAndMergeAttachmentsIntoConversationMessages($messages);
     }
     $total = $conversation['reply_count'] + 1;
     $data = array('messages' => $this->_filterDataMany($this->_getConversationModel()->prepareApiDataForMessages($messages, $conversation)), 'messages_total' => $total);
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'conversation-messages', array(), $pageNavParams);
     return $this->responseData('bdApi_ViewApi_ConversationMessage_List', $data);
 }
Esempio n. 4
0
 public static function doJob($method, $uri, array $params)
 {
     if (XenForo_Application::isRegistered('_bdApi_disableBatch') && XenForo_Application::get('_bdApi_disableBatch')) {
         return array('_job_result' => 'error', '_job_error' => 'Batch running has been disabled.');
     }
     $fc = self::getFc();
     $request = new bdApi_Zend_Controller_Request_Http(bdApi_Data_Helper_Core::safeConvertApiUriToAbsoluteUri($uri, true));
     $request->setMethod($method);
     foreach ($params as $key => $value) {
         $request->setParam($key, $value);
     }
     $fc->setRequest($request);
     // routing
     $routeMatch = $fc->getDependencies()->route($request);
     if (!$routeMatch or !$routeMatch->getControllerName()) {
         list($controllerName, $action) = $fc->getDependencies()->getNotFoundErrorRoute();
         $routeMatch->setControllerName($controllerName);
         $routeMatch->setAction($action);
     }
     $response = $fc->dispatch($routeMatch);
     if ($response instanceof XenForo_ControllerResponse_Error) {
         return array('_job_result' => 'error', '_job_error' => $response->errorText);
     } elseif ($response instanceof XenForo_ControllerResponse_Exception) {
         return array('_job_result' => 'error', '_job_error' => $response->getMessage());
     } elseif ($response instanceof XenForo_ControllerResponse_Message) {
         return array('_job_result' => 'message', '_job_message' => $response->message);
     } elseif ($response instanceof XenForo_ControllerResponse_View) {
         return array('_job_result' => 'ok', '_job_response' => $response);
     }
     throw new XenForo_Exception('Unexpected $response occurred.');
 }
Esempio n. 5
0
 public function actionGetIndex()
 {
     $conversationId = $this->_input->filterSingle('conversation_id', XenForo_Input::UINT);
     if (!empty($conversationId)) {
         return $this->responseReroute(__CLASS__, 'single');
     }
     $visitor = XenForo_Visitor::getInstance();
     $pageNavParams = array();
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $limit = XenForo_Application::get('options')->discussionsPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     $conditions = array();
     $fetchOptions = array('limit' => $limit, 'page' => $page, 'join' => 0);
     // TODO: ordering
     if (!$this->_isFieldExcluded('first_message')) {
         $fetchOptions['join'] += XenForo_Model_Conversation::FETCH_FIRST_MESSAGE;
     }
     $getRecipients = !$this->_isFieldExcluded('recipients');
     $conversations = $this->_getConversationModel()->getConversationsForUser($visitor['user_id'], $conditions, $this->_getConversationModel()->getFetchOptionsToPrepareApiData($fetchOptions));
     $total = $this->_getConversationModel()->countConversationsForUser($visitor['user_id'], $conditions);
     $data = array('conversations' => $this->_filterDataMany($this->_getConversationModel()->prepareApiDataForConversations($conversations, $getRecipients)), 'conversations_total' => $total);
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'conversations', array(), $pageNavParams);
     return $this->responseData('bdApi_ViewApi_Conversation_List', $data);
 }
Esempio n. 6
0
 public function prepareParams()
 {
     if (!empty($this->_params['_thread']['thread_id'])) {
         bdApi_ViewApi_Helper_Subscription::prepareDiscoveryParams($this->_params, $this->_response, bdApi_Model_Subscription::TYPE_THREAD_POST, $this->_params['_thread']['thread_id'], bdApi_Data_Helper_Core::safeBuildApiLink('posts', null, array('thread_id' => $this->_params['_thread']['thread_id'], 'oauth_token' => '')), isset($this->_params['_thread']['bdapi_thread_post']) ? $this->_params['_thread']['bdapi_thread_post'] : '');
     }
     parent::prepareParams();
 }
Esempio n. 7
0
 public function prepareApiDataForCategory(array $category)
 {
     $publicKeys = array('node_id' => 'category_id', 'title' => 'category_title', 'description' => 'category_description');
     $data = bdApi_Data_Helper_Core::filter($category, $publicKeys);
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('categories', $category), 'detail' => bdApi_Data_Helper_Core::safeBuildApiLink('categories', $category), 'sub-categories' => bdApi_Data_Helper_Core::safeBuildApiLink('categories', array(), array('parent_category_id' => $category['node_id'])), 'sub-forums' => bdApi_Data_Helper_Core::safeBuildApiLink('forums', array(), array('parent_category_id' => $category['node_id'])));
     $data['permissions'] = array('view' => $this->canViewCategory($category), 'edit' => XenForo_Visitor::getInstance()->hasAdminPermission('node'), 'delete' => XenForo_Visitor::getInstance()->hasAdminPermission('node'));
     return $data;
 }
Esempio n. 8
0
 public function prepareApiDataForPage(array $page)
 {
     $publicKeys = array('node_id' => 'page_id', 'title' => 'page_title', 'description' => 'page_description', 'view_count' => 'page_view_count');
     $data = bdApi_Data_Helper_Core::filter($page, $publicKeys);
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('pages', $page), 'detail' => bdApi_Data_Helper_Core::safeBuildApiLink('pages', $page), 'sub-pages' => bdApi_Data_Helper_Core::safeBuildApiLink('pages', array(), array('parent_page_id' => $page['node_id'])));
     $data['permissions'] = array('view' => $this->canViewPage($page), 'edit' => XenForo_Visitor::getInstance()->hasAdminPermission('node'), 'delete' => XenForo_Visitor::getInstance()->hasAdminPermission('node'));
     return $data;
 }
Esempio n. 9
0
 protected function _getModules()
 {
     $modules = array('forum' => 2015121802, 'oauth2' => 2015121501, 'subscription' => 2014092301);
     $option = bdApi_Data_Helper_Core::safeGetSession()->getOAuthClientOption('allow_search_indexing');
     if (!empty($option)) {
         $modules['search/indexing'] = 2015091601;
     }
     return $modules;
 }
Esempio n. 10
0
 public function actionGetIndex()
 {
     $postId = $this->_input->filterSingle('post_id', XenForo_Input::UINT);
     if (!empty($postId)) {
         return $this->responseReroute(__CLASS__, 'single');
     }
     $postIds = $this->_input->filterSingle('post_ids', XenForo_Input::STRING);
     if (!empty($postIds)) {
         return $this->responseReroute(__CLASS__, 'multiple');
     }
     $pageOfPostId = $this->_input->filterSingle('page_of_post_id', XenForo_Input::UINT);
     $pageOfPost = null;
     if (!empty($pageOfPostId)) {
         list($pageOfPost, $thread, $forum) = $this->_getForumThreadPostHelper()->assertPostValidAndViewable($pageOfPostId, array(), $this->_getThreadModel()->getFetchOptionsToPrepareApiData(), $this->_getForumModel()->getFetchOptionsToPrepareApiData());
         $threadId = $thread['thread_id'];
     } else {
         $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
         if (empty($threadId)) {
             return $this->responseError(new XenForo_Phrase('bdapi_slash_posts_requires_thread_id'), 400);
         }
         list($thread, $forum) = $this->_getForumThreadPostHelper()->assertThreadValidAndViewable($threadId, $this->_getThreadModel()->getFetchOptionsToPrepareApiData(), $this->_getForumModel()->getFetchOptionsToPrepareApiData());
     }
     if ($this->_getThreadModel()->isRedirect($thread)) {
         return $this->responseError(new XenForo_Phrase('requested_thread_not_found'), 404);
     }
     $pageNavParams = array('thread_id' => $thread['thread_id']);
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $limit = XenForo_Application::get('options')->messagesPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     if (!empty($pageOfPost)) {
         $page = floor($pageOfPost['position'] / $limit) + 1;
     }
     $fetchOptions = array('deleted' => false, 'moderated' => false, 'limit' => $limit, 'page' => $page);
     $order = $this->_input->filterSingle('order', XenForo_Input::STRING, array('default' => 'natural'));
     switch ($order) {
         case 'natural_reverse':
             // load the class to make our constant accessible
             $this->_getPostModel();
             $fetchOptions[bdApi_XenForo_Model_Post::FETCH_OPTIONS_POSTS_IN_THREAD_ORDER_REVERSE] = true;
             $pageNavParams['order'] = $order;
             break;
     }
     $posts = $this->_getPostModel()->getPostsInThread($threadId, $this->_getPostModel()->getFetchOptionsToPrepareApiData($fetchOptions));
     $postsData = $this->_preparePosts($posts, $thread, $forum);
     $total = $thread['reply_count'] + 1;
     $data = array('posts' => $this->_filterDataMany($postsData), 'posts_total' => $total, '_thread' => $thread);
     if (!$this->_isFieldExcluded('thread')) {
         $data['thread'] = $this->_filterDataSingle($this->_getThreadModel()->prepareApiDataForThread($thread, $forum, array()), array('thread'));
     }
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'posts', array(), $pageNavParams);
     return $this->responseData('bdApi_ViewApi_Post_List', $data);
 }
Esempio n. 11
0
 public function prepareApiDataForComment(array $comment, array $profilePost, array $user)
 {
     $comment = $this->prepareProfilePostComment($comment, $profilePost, $user);
     $publicKeys = array('profile_post_comment_id' => 'comment_id', 'profile_post_id' => 'profile_post_id', 'user_id' => 'comment_user_id', 'username' => 'comment_username', 'comment_date' => 'comment_create_date', 'message' => 'comment_body');
     $data = bdApi_Data_Helper_Core::filter($comment, $publicKeys);
     $data['timeline_user_id'] = $profilePost['profile_user_id'];
     $data['links'] = array('detail' => bdApi_Data_Helper_Core::safeBuildApiLink('profile-posts/comments', $profilePost, array('comment_id' => $comment['profile_post_comment_id'])), 'profile_post' => bdApi_Data_Helper_Core::safeBuildApiLink('profile-posts', $profilePost), 'timeline' => bdApi_Data_Helper_Core::safeBuildApiLink('users/timeline', $user), 'timeline_user' => bdApi_Data_Helper_Core::safeBuildApiLink('users', $user), 'poster' => bdApi_Data_Helper_Core::safeBuildApiLink('users', $comment), 'poster_avatar' => XenForo_Template_Helper_Core::callHelper('avatar', array($comment, 'm', false, true)));
     $data['permissions'] = array('view' => $this->canViewProfilePost($profilePost, $user), 'delete' => $this->canDeleteProfilePostComment($comment, $profilePost, $user));
     return $data;
 }
Esempio n. 12
0
 public function prepareParams()
 {
     // render notification html
     $notifications =& $this->_params['notifications'];
     $templates = bdApi_ViewApi_Helper_Alert::getTemplates($this, $this->_params['_alerts'], $this->_params['_alertHandlers']);
     foreach ($notifications as $key => &$notification) {
         $notification['notification_html'] = $templates[$notification['notification_id']]['template'];
     }
     bdApi_ViewApi_Helper_Subscription::prepareDiscoveryParams($this->_params, $this->_response, bdApi_Model_Subscription::TYPE_NOTIFICATION, XenForo_Visitor::getUserId(), bdApi_Data_Helper_Core::safeBuildApiLink('notifications', null, array('oauth_token' => '')), XenForo_Visitor::getInstance()->get('bdapi_user_notification'));
     parent::prepareParams();
 }
Esempio n. 13
0
 public function prepareApiDataForLinkForum(array $linkForum)
 {
     $publicKeys = array('node_id' => 'link_id', 'title' => 'link_title', 'description' => 'link_description');
     $data = bdApi_Data_Helper_Core::filter($linkForum, $publicKeys);
     if (!empty($linkForum['link_url'])) {
         $linkUrl = $linkForum['link_url'];
     } else {
         $linkUrl = XenForo_Link::buildPublicLink('link-forums', $linkForum);
     }
     $data['links']['target'] = $linkUrl;
     $data['permissions'] = array('view' => $this->canViewLinkForum($linkForum), 'edit' => XenForo_Visitor::getInstance()->hasAdminPermission('node'), 'delete' => XenForo_Visitor::getInstance()->hasAdminPermission('node'));
     return $data;
 }
Esempio n. 14
0
 public function setVisitorLanguage($languageId)
 {
     if ($this->get('user_id') > 0) {
         // because XenForo ignore session language id if user is logged in
         // we have to override its value here
         // NOTE: the load_class for XenForo_Visitor requires 1.2.0+
         $session = bdApi_Data_Helper_Core::safeGetSession();
         $requestLanguageId = $session->get('languageId');
         if ($requestLanguageId > 0) {
             $languageId = $requestLanguageId;
         }
     }
     return parent::setVisitorLanguage($languageId);
 }
Esempio n. 15
0
 public function actionGetSdk()
 {
     $prefix = $this->_input->filterSingle('prefix', XenForo_Input::STRING);
     $prefix = preg_replace('/[^a-zA-Z0-9]/', '', $prefix);
     $sdkPath = XenForo_Autoloader::getInstance()->getRootDir() . '/../js/bdApi/full/sdk.js';
     $sdk = file_get_contents($sdkPath);
     $sdk = str_replace('{prefix}', $prefix, $sdk);
     $sdk = str_replace('{data_uri}', XenForo_Link::buildPublicLink('canonical:misc/api-data'), $sdk);
     $sdk = str_replace('{request_uri}', bdApi_Data_Helper_Core::safeBuildApiLink('index'), $sdk);
     header('Content-Type: application/x-javascript; charset=utf-8');
     header('Cache-Control: public, max-age=31536000');
     header(sprintf('Last-Modified: %s', gmstrftime("%a, %d %b %Y %T %Z", filemtime($sdkPath))));
     die($sdk);
 }
Esempio n. 16
0
 public function prepareApiDataForPoll(array $poll, $canVote)
 {
     $poll = $this->preparePoll($poll, $canVote);
     $publicKeys = array('poll_id' => 'poll_id', 'question' => 'poll_question', 'voter_count' => 'poll_vote_count', 'max_votes' => 'poll_max_votes', 'open' => 'poll_is_open', 'hasVoted' => 'poll_is_voted');
     $data = bdApi_Data_Helper_Core::filter($poll, $publicKeys);
     $data['responses'] = array();
     foreach ($poll['responses'] as $responseId => $response) {
         $responseData = array('response_id' => $responseId, 'response_answer' => $response['response']);
         if (!empty($data['poll_is_voted'])) {
             $responseData['response_is_voted'] = $response['hasVoted'];
         }
         $data['responses'][] = $responseData;
     }
     $data['permissions'] = array('vote' => $poll['canVote'], 'result' => $poll['canViewResults']);
     return $data;
 }
Esempio n. 17
0
 public function prepareApiDataForForum(array $forum)
 {
     if (!empty($forum['node_permission_cache'])) {
         XenForo_Visitor::getInstance()->setNodePermissions($forum['node_id'], $forum['node_permission_cache']);
     }
     $publicKeys = array('node_id' => 'forum_id', 'title' => 'forum_title', 'description' => 'forum_description', 'discussion_count' => 'forum_thread_count', 'message_count' => 'forum_post_count');
     $data = bdApi_Data_Helper_Core::filter($forum, $publicKeys);
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('forums', $forum), 'detail' => bdApi_Data_Helper_Core::safeBuildApiLink('forums', $forum), 'sub-categories' => bdApi_Data_Helper_Core::safeBuildApiLink('categories', array(), array('parent_forum_id' => $forum['node_id'])), 'sub-forums' => bdApi_Data_Helper_Core::safeBuildApiLink('forums', array(), array('parent_forum_id' => $forum['node_id'])), 'threads' => bdApi_Data_Helper_Core::safeBuildApiLink('threads', array(), array('forum_id' => $forum['node_id'])));
     $data['permissions'] = array('view' => $this->canViewForum($forum), 'edit' => XenForo_Visitor::getInstance()->hasAdminPermission('node'), 'delete' => XenForo_Visitor::getInstance()->hasAdminPermission('node'), 'create_thread' => $this->canPostThreadInForum($forum), 'upload_attachment' => $this->canUploadAndManageAttachment($forum));
     if (XenForo_Application::$versionId >= 1020000) {
         $data['forum_is_followed'] = !empty($forum['forum_is_watched']);
         $data['links']['followers'] = bdApi_Data_Helper_Core::safeBuildApiLink('forums/followers', $forum);
         $data['permissions']['follow'] = $this->canWatchForum($forum);
     }
     return $data;
 }
Esempio n. 18
0
 public function prepareApiDataForField(array $field, $fieldValue = null)
 {
     $field = $this->prepareUserField($field, true, $fieldValue);
     $data = array();
     $publicKeys = array('title' => 'title', 'description' => 'description', 'display_group' => 'display_group');
     if (!empty($field['isChoice'])) {
         $publicKeys['fieldChoices'] = 'choices';
         $data['is_multi_choice'] = !empty($field['isMultiChoice']);
     }
     $data += bdApi_Data_Helper_Core::filter($field, $publicKeys);
     $data['is_required'] = !empty($field['required']);
     if (!empty($data['choices'])) {
         $choices = array();
         foreach ($data['choices'] as $key => $value) {
             $choices[] = array('key' => strval($key), 'value' => strval($value));
         }
         $data['choices'] = $choices;
     }
     if ($fieldValue !== null) {
         if (!empty($data['choices'])) {
             // choices
             if (is_array($field['field_value'])) {
                 // array
                 $fieldValueIds = array_keys($field['field_value']);
             } else {
                 // single
                 $fieldValueIds = array($field['field_value']);
             }
             $data['values'] = array();
             foreach ($fieldValueIds as $fieldValueId) {
                 $choiceValue = null;
                 foreach ($data['choices'] as $choice) {
                     if ($choice['key'] == $fieldValueId) {
                         $choiceValue = $choice['value'];
                     }
                 }
                 if ($choiceValue !== null) {
                     $data['values'][] = array('key' => strval($fieldValueId), 'value' => $choiceValue);
                 }
             }
         } else {
             // text
             $data['value'] = $field['field_value'];
         }
     }
     return $data;
 }
Esempio n. 19
0
 public function prepareApiDataForThread(array $thread, array $forum, array $firstPost)
 {
     /* @var $postModel bdApi_XenForo_Model_Post */
     $postModel = $this->_getPostModel();
     $thread = $this->prepareThread($thread, $forum);
     $publicKeys = array('thread_id' => 'thread_id', 'node_id' => 'forum_id', 'title' => 'thread_title', 'view_count' => 'thread_view_count', 'user_id' => 'creator_user_id', 'username' => 'creator_username', 'post_date' => 'thread_create_date', 'last_post_date' => 'thread_update_date');
     $data = bdApi_Data_Helper_Core::filter($thread, $publicKeys);
     if (isset($thread['reply_count'])) {
         $data['thread_post_count'] = $thread['reply_count'] + 1;
     }
     if (isset($thread['sticky']) and isset($thread['discussion_state'])) {
         switch ($thread['discussion_state']) {
             case 'visible':
                 $data['thread_is_published'] = true;
                 $data['thread_is_deleted'] = false;
                 $data['thread_is_sticky'] = empty($thread['sticky']) ? false : true;
                 break;
             case 'moderated':
                 $data['thread_is_published'] = false;
                 $data['thread_is_deleted'] = false;
                 $data['thread_is_sticky'] = false;
                 break;
             case 'deleted':
                 $data['thread_is_published'] = false;
                 $data['thread_is_deleted'] = true;
                 $data['thread_is_sticky'] = false;
                 break;
         }
     }
     $data['thread_is_followed'] = !empty($thread['thread_is_watched']);
     if (!empty($firstPost)) {
         $data['first_post'] = $postModel->prepareApiDataForPost($firstPost, $thread, $forum);
     }
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('threads', $thread), 'detail' => bdApi_Data_Helper_Core::safeBuildApiLink('threads', $thread), 'followers' => bdApi_Data_Helper_Core::safeBuildApiLink('threads/followers', $thread), 'forum' => bdApi_Data_Helper_Core::safeBuildApiLink('forums', $thread), 'posts' => bdApi_Data_Helper_Core::safeBuildApiLink('posts', array(), array('thread_id' => $thread['thread_id'])), 'first_poster' => bdApi_Data_Helper_Core::safeBuildApiLink('users', $thread), 'first_post' => bdApi_Data_Helper_Core::safeBuildApiLink('posts', array('post_id' => $thread['first_post_id'])));
     if ($thread['last_post_user_id'] != $thread['user_id']) {
         $data['links']['last_poster'] = bdApi_Data_Helper_Core::safeBuildApiLink('users', array('user_id' => $thread['last_post_user_id'], 'username' => $thread['last_post_username']));
     }
     if ($thread['last_post_id'] != $thread['first_post_id']) {
         $data['links']['last_post'] = bdApi_Data_Helper_Core::safeBuildApiLink('posts', array('post_id' => $thread['last_post_id']));
     }
     $data['permissions'] = array('view' => $this->canViewThread($thread, $forum), 'edit' => $this->canEditThread($thread, $forum), 'delete' => $this->canDeleteThread($thread, $forum), 'follow' => $this->canWatchThread($thread, $forum), 'post' => $this->canReplyToThread($thread, $forum), 'upload_attachment' => $this->_getForumModel()->canUploadAndManageAttachment($forum));
     return $data;
 }
Esempio n. 20
0
 protected function _arrangeElements(array &$elements, array &$nodesGrouped, $parentNodeId, array &$options = array())
 {
     foreach ($nodesGrouped as $_parentNodeId => $nodes) {
         if ($parentNodeId != $_parentNodeId) {
             continue;
         }
         foreach ($nodes as $node) {
             $element = false;
             switch ($node['node_type_id']) {
                 case 'Category':
                     $element = $this->_getCategoryModel()->prepareApiDataForCategory($node);
                     break;
                 case 'Forum':
                     if (!empty($options['forums'][$node['node_id']])) {
                         $element = $this->_getForumModel()->prepareApiDataForForum($options['forums'][$node['node_id']]);
                     }
                     break;
                 case 'LinkForum':
                     $element = $this->_getLinkForumModel()->prepareApiDataForLinkForum($node);
                     break;
                 case 'Page':
                     $element = $this->_getPageModel()->prepareApiDataForPage($node);
                     break;
             }
             if (!empty($element)) {
                 $element['navigation_type'] = strtolower($node['node_type_id']);
                 $element['navigation_id'] = $node['node_id'];
                 $element['navigation_parent_id'] = $node['parent_node_id'];
                 $element['has_sub_elements'] = !empty($nodesGrouped[$node['node_id']]);
                 if ($element['has_sub_elements']) {
                     if (empty($element['links'])) {
                         $element['links'] = array();
                     }
                     $element['links']['sub-elements'] = bdApi_Data_Helper_Core::safeBuildApiLink('navigation', '', array('parent' => $element['navigation_id']));
                 }
                 $elements[] = $element;
                 if ($element['has_sub_elements'] && !is_int($options['expectedParentNodeId'])) {
                     $this->_arrangeElements($elements, $nodesGrouped, intval($node['node_id']), $options);
                 }
             }
         }
     }
 }
Esempio n. 21
0
 public function actionGetIndex()
 {
     $this->_assertRegistrationRequired();
     $alertModel = $this->_getAlertModel();
     $visitor = XenForo_Visitor::getInstance();
     $pageNavParams = array();
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $limit = XenForo_Application::get('options')->alertsPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     $alertResults = $alertModel->getAlertsForUser($visitor['user_id'], XenForo_Model_Alert::FETCH_MODE_RECENT, array('page' => $page, 'limit' => $limit));
     $alerts =& $alertResults['alerts'];
     $total = $alertModel->countAlertsForUser($visitor['user_id']);
     $data = array('notifications' => $this->_filterDataMany($this->_getAlertModel()->prepareApiDataForAlerts($alerts)), 'notifications_total' => $total, 'links' => array('read' => bdApi_Data_Helper_Core::safeBuildApiLink('notifications/read')), '_alerts' => $alerts, '_alertHandlers' => $alertResults['alertHandlers']);
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'notifications', array(), $pageNavParams);
     return $this->responseData('bdApi_ViewApi_Notification_List', $data);
 }
Esempio n. 22
0
 public function actionGetIndex()
 {
     $messageId = $this->_input->filterSingle('message_id', XenForo_Input::UINT);
     if (!empty($messageId)) {
         return $this->responseReroute(__CLASS__, 'single');
     }
     $conversationId = $this->_input->filterSingle('conversation_id', XenForo_Input::UINT);
     if (empty($conversationId)) {
         return $this->responseError(new XenForo_Phrase('bdapi_slash_conversation_messages_requires_conversation_id'), 400);
     }
     $conversation = $this->_getConversationOrError($conversationId);
     $pageNavParams = array('conversation_id' => $conversation['conversation_id']);
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $limit = XenForo_Application::get('options')->messagesPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     $fetchOptions = array('limit' => $limit, 'page' => $page);
     $order = $this->_input->filterSingle('order', XenForo_Input::STRING, array('default' => 'natural'));
     switch ($order) {
         case 'natural_reverse':
             // load the class to make our constant accessible
             $this->_getConversationModel();
             $fetchOptions[bdApi_XenForo_Model_Conversation::FETCH_OPTIONS_MESSAGES_ORDER_REVERSE] = true;
             $pageNavParams['order'] = $order;
             break;
     }
     $messages = $this->_getConversationModel()->getConversationMessages($conversation['conversation_id'], $this->_getConversationModel()->getFetchOptionsToPrepareApiDataForMessages($fetchOptions));
     if (!$this->_isFieldExcluded('attachments')) {
         $messages = $this->_getConversationModel()->getAndMergeAttachmentsIntoConversationMessages($messages);
     }
     $total = $conversation['reply_count'] + 1;
     $data = array('messages' => $this->_filterDataMany($this->_getConversationModel()->prepareApiDataForMessages($messages, $conversation)), 'messages_total' => $total);
     if (!$this->_isFieldExcluded('conversation')) {
         $data['conversation'] = $this->_filterDataSingle($this->_getConversationModel()->prepareApiDataForConversation($conversation), array('conversation'));
     }
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'conversation-messages', array(), $pageNavParams);
     return $this->responseData('bdApi_ViewApi_ConversationMessage_List', $data);
 }
Esempio n. 23
0
 public function actionGetResults()
 {
     $searchId = $this->_input->filterSingle('search_id', XenForo_Input::UINT);
     $search = $this->_getSearchModel()->getSearchById($searchId);
     if (empty($search) || $search['user_id'] != XenForo_Visitor::getUserId()) {
         return $this->responseError(new XenForo_Phrase('requested_search_not_found'), 404);
     }
     $pageNavParams = array();
     $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
     $limit = XenForo_Application::get('options')->searchResultsPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if ($inputLimit > 0) {
         $limit = min($limit, $inputLimit);
         $pageNavParams['limit'] = $limit;
     }
     $pageResultIds = $this->_getSearchModel()->sliceSearchResultsToPage($search, $page, $limit);
     $results = $this->_getSearchModel()->prepareApiDataForSearchResults($pageResultIds);
     $contentData = $this->_getSearchModel()->prepareApiContentDataForSearch($results);
     $data = array('_search' => $search, 'data' => $this->_filterDataMany(array_values($contentData)), 'data_total' => $search['result_count']);
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $search['result_count'], $page, 'search/results', $search, $pageNavParams);
     return $this->responseData('bdApi_ViewApi_Search_Results', $data);
 }
Esempio n. 24
0
 /**
  * Builds and adds the navigation for api data
  *
  * @param XenForo_Input $input
  * @param array $data
  * @param int $perPage
  * @param int $totalItems
  * @param int $page
  * @param string $linkType
  * @param mixed $linkData
  * @param array $linkParams
  * @param array $options
  */
 public static function addPageLinks(XenForo_Input $input, array &$data, $perPage, $totalItems, $page, $linkType, $linkData = null, array $linkParams = array(), array $options = array())
 {
     if (empty($perPage)) {
         return;
     }
     $pageNav = array();
     $inputData = $input->filter(array('fields_include' => XenForo_Input::STRING, 'fields_exclude' => XenForo_Input::STRING));
     if (!empty($inputData['fields_include'])) {
         $linkParams['fields_include'] = $inputData['fields_include'];
     } elseif (!empty($inputData['fields_exclude'])) {
         $linkParams['fields_exclude'] = $inputData['fields_exclude'];
     }
     if (empty($page)) {
         $page = 1;
     }
     $pageNav['pages'] = ceil($totalItems / $perPage);
     if ($pageNav['pages'] <= 1) {
         // do not do anything if there is only 1 page (or no pages)
         return;
     }
     $pageNav['page'] = $page;
     if ($page > 1) {
         // a previous link should only be added if we are not at page 1
         $pageNav['prev'] = bdApi_Data_Helper_Core::safeBuildApiLink($linkType, $linkData, array_merge($linkParams, array('page' => $page - 1)));
     }
     if ($page < $pageNav['pages']) {
         // a next link should only be added if we are not at the last page
         $pageNav['next'] = bdApi_Data_Helper_Core::safeBuildApiLink($linkType, $linkData, array_merge($linkParams, array('page' => $page + 1)));
     }
     // add the page navigation into `links`
     // the data may have existing links or not
     // we simply don't care
     if (empty($data['links'])) {
         $data['links'] = array();
     }
     $data['links'] = array_merge($data['links'], $pageNav);
 }
Esempio n. 25
0
 protected static function _addDefaultParams(array &$params = array())
 {
     bdApi_Data_Helper_Core::addDefaultResponse($params);
 }
Esempio n. 26
0
File: User.php Progetto: sushj/bdApi
 public function actionPostGroups()
 {
     $link = bdApi_Data_Helper_Core::safeBuildApiLink('users', array('user_id' => $this->_input->filterSingle('user_id', XenForo_Input::UINT)));
     $this->_setDeprecatedHeaders('PUT', $link);
     return $this->responseReroute('bdApi_ControllerApi_User', 'put-index');
 }
Esempio n. 27
0
 public function prepareApiDataForThread(array $thread, array $forum, array $firstPost)
 {
     $thread = $this->prepareThread($thread, $forum);
     $publicKeys = array('thread_id' => 'thread_id', 'node_id' => 'forum_id', 'title' => 'thread_title', 'view_count' => 'thread_view_count', 'user_id' => 'creator_user_id', 'username' => 'creator_username', 'post_date' => 'thread_create_date', 'last_post_date' => 'thread_update_date');
     $data = bdApi_Data_Helper_Core::filter($thread, $publicKeys);
     $data['user_is_ignored'] = XenForo_Visitor::getInstance()->isIgnoring($thread['user_id']);
     if (isset($thread['reply_count'])) {
         $data['thread_post_count'] = $thread['reply_count'] + 1;
     }
     if (isset($thread['sticky']) and isset($thread['discussion_state'])) {
         switch ($thread['discussion_state']) {
             case 'visible':
                 $data['thread_is_published'] = true;
                 $data['thread_is_deleted'] = false;
                 $data['thread_is_sticky'] = empty($thread['sticky']) ? false : true;
                 break;
             case 'moderated':
                 $data['thread_is_published'] = false;
                 $data['thread_is_deleted'] = false;
                 $data['thread_is_sticky'] = false;
                 break;
             case 'deleted':
                 $data['thread_is_published'] = false;
                 $data['thread_is_deleted'] = true;
                 $data['thread_is_sticky'] = false;
                 break;
         }
     }
     $data['thread_is_followed'] = !empty($thread['thread_is_watched']);
     if (!empty($firstPost)) {
         /* @var $postModel bdApi_Extend_Model_Post */
         $postModel = $this->_getPostModel();
         $data['first_post'] = $postModel->prepareApiDataForPost($firstPost, $thread, $forum);
     }
     if ($thread['discussion_type'] === 'poll' && isset($this->_bdApi_polls[$thread['thread_id']])) {
         $poll = $this->_bdApi_polls[$thread['thread_id']];
         /** @var bdApi_Extend_Model_Poll $pollModel */
         $pollModel = $this->getModelFromCache('XenForo_Model_Poll');
         $data['poll'] = $pollModel->prepareApiDataForPoll($poll, $this->canVoteOnPoll($poll, $thread, $forum));
         $data['poll']['links']['vote'] = bdApi_Data_Helper_Core::safeBuildApiLink('threads/poll/votes', $thread);
         $data['poll']['links']['results'] = bdApi_Data_Helper_Core::safeBuildApiLink('threads/poll/results', $thread);
     }
     if (XenForo_Application::$versionId > 1050000 && isset($thread['tags'])) {
         $tags = @unserialize($thread['tags']);
         if (is_array($tags)) {
             /** @var bdApi_Extend_Model_Tag $tagModel */
             $tagModel = $this->getModelFromCache('XenForo_Model_Tag');
             $data['thread_tags'] = $tagModel->prepareApiDataForTags($tags);
         }
     }
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('threads', $thread), 'detail' => bdApi_Data_Helper_Core::safeBuildApiLink('threads', $thread), 'followers' => bdApi_Data_Helper_Core::safeBuildApiLink('threads/followers', $thread), 'forum' => bdApi_Data_Helper_Core::safeBuildApiLink('forums', $thread), 'posts' => bdApi_Data_Helper_Core::safeBuildApiLink('posts', array(), array('thread_id' => $thread['thread_id'])), 'first_poster' => bdApi_Data_Helper_Core::safeBuildApiLink('users', $thread), 'first_post' => bdApi_Data_Helper_Core::safeBuildApiLink('posts', array('post_id' => $thread['first_post_id'])));
     if ($thread['last_post_user_id'] != $thread['user_id']) {
         $data['links']['last_poster'] = bdApi_Data_Helper_Core::safeBuildApiLink('users', array('user_id' => $thread['last_post_user_id'], 'username' => $thread['last_post_username']));
     }
     if ($thread['last_post_id'] != $thread['first_post_id']) {
         $data['links']['last_post'] = bdApi_Data_Helper_Core::safeBuildApiLink('posts', array('post_id' => $thread['last_post_id']));
     }
     $data['permissions'] = array('view' => $this->canViewThread($thread, $forum), 'delete' => $this->canDeleteThread($thread, $forum), 'follow' => $this->canWatchThread($thread, $forum), 'post' => $this->canReplyToThread($thread, $forum), 'upload_attachment' => $this->_getForumModel()->canUploadAndManageAttachment($forum));
     if (!empty($firstPost)) {
         $data['permissions']['edit'] = $this->_getPostModel()->canEditPost($firstPost, $thread, $forum);
         if (!empty($data['permissions']['edit'])) {
             $data['permissions']['edit_title'] = $this->canEditThread($thread, $forum);
             if (XenForo_Application::$versionId > 1050000) {
                 $data['permissions']['edit_tags'] = $this->canEditTags($thread, $forum);
             }
         }
     }
     return $data;
 }
Esempio n. 28
0
 public function actionGetComments()
 {
     $pageOfCommentId = $this->_input->filterSingle('page_of_comment_id', XenForo_Input::UINT);
     $pageOfComment = null;
     $commentId = $this->_input->filterSingle('comment_id', XenForo_Input::UINT);
     $beforeDate = $this->_input->filterSingle('before', XenForo_Input::UINT);
     if (!empty($pageOfCommentId)) {
         list($pageOfComment, $profilePost, $user) = $this->_getUserProfileHelper()->assertProfilePostCommentValidAndViewable($pageOfCommentId, $this->_getProfilePostModel()->getCommentFetchOptionsToPrepareApiData(), $this->_getProfilePostModel()->getFetchOptionsToPrepareApiData(), $this->_getUserModel()->getFetchOptionsToPrepareApiData());
         $profilePostId = $profilePost['profile_post_id'];
     } else {
         $profilePostId = $this->_input->filterSingle('profile_post_id', XenForo_Input::UINT);
         if (empty($profilePostId)) {
             return $this->responseNoPermission();
         }
         list($profilePost, $user) = $this->_getUserProfileHelper()->assertProfilePostValidAndViewable($profilePostId, $this->_getProfilePostModel()->getFetchOptionsToPrepareApiData(), $this->_getUserModel()->getFetchOptionsToPrepareApiData());
         // special case for single comment
         if (!empty($commentId)) {
             list($comment, , ) = $this->_getUserProfileHelper()->assertProfilePostCommentValidAndViewable($commentId, $this->_getProfilePostModel()->getCommentFetchOptionsToPrepareApiData());
             if ($comment['profile_post_id'] != $profilePost['profile_post_id']) {
                 return $this->responseNoPermission();
             }
             $data = array('comment' => $this->_filterDataSingle($this->_getProfilePostModel()->prepareApiDataForComment($comment, $profilePost, $user)));
             return $this->responseData('bdApi_ViewApi_ProfilePost_Comments_Single', $data);
         }
     }
     $pageNavParams = array();
     $limit = XenForo_Application::get('options')->messagesPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     if (!empty($pageOfComment)) {
         $beforeDate = $pageOfComment['comment_date'] + 1;
     }
     $fetchOptions = array('limit' => $limit);
     $comments = $this->_getProfilePostModel()->getProfilePostCommentsByProfilePost($profilePostId, $beforeDate, $this->_getProfilePostModel()->getCommentFetchOptionsToPrepareApiData($fetchOptions));
     $oldestComment = reset($comments);
     $latestComment = end($comments);
     $total = $profilePost['comment_count'];
     $data = array('comments' => $this->_filterDataMany($this->_getProfilePostModel()->prepareApiDataForComments($comments, $profilePost, $user)), 'comments_total' => $total, '_profilePost' => $profilePost, '_user' => $user);
     if (!$this->_isFieldExcluded('profile_post')) {
         $data['profile_post'] = $this->_filterDataSingle($this->_getProfilePostModel()->prepareApiDataForProfilePost($profilePost, $user), array('profile_post'));
     }
     if (!$this->_isFieldExcluded('timeline_user')) {
         $data['timeline_user'] = $this->_filterDataSingle($this->_getUserModel()->prepareApiDataForUser($user), array('timeline_user'));
     }
     $inputData = $this->_input->filter(array('fields_include' => XenForo_Input::STRING, 'fields_exclude' => XenForo_Input::STRING));
     if (!empty($inputData['fields_include'])) {
         $pageNavParams['fields_include'] = $inputData['fields_include'];
     } elseif (!empty($inputData['fields_exclude'])) {
         $pageNavParams['fields_exclude'] = $inputData['fields_exclude'];
     }
     if ($oldestComment['comment_date'] != $profilePost['first_comment_date']) {
         $data['links']['prev'] = bdApi_Data_Helper_Core::safeBuildApiLink('profile-posts/comments', $profilePost, array_merge($pageNavParams, array('before' => $oldestComment['comment_date'])));
     }
     if ($latestComment['comment_date'] != $profilePost['last_comment_date']) {
         $data['links']['latest'] = bdApi_Data_Helper_Core::safeBuildApiLink('profile-posts/comments', $profilePost, $pageNavParams);
     }
     return $this->responseData('bdApi_ViewApi_ProfilePost_Comments', $data);
 }
Esempio n. 29
0
 public function actionGetComments()
 {
     $profilePostId = $this->_input->filterSingle('profile_post_id', XenForo_Input::UINT);
     $commentId = $this->_input->filterSingle('comment_id', XenForo_Input::UINT);
     if (!empty($commentId)) {
         list($comment, $profilePost, $user) = $this->_getUserProfileHelper()->assertProfilePostCommentValidAndViewable($commentId, $this->_getProfilePostModel()->getCommentFetchOptionsToPrepareApiData());
         if ($profilePost['profile_post_id'] != $profilePostId) {
             return $this->responseNoPermission();
         }
         $data = array('comment' => $this->_filterDataSingle($this->_getProfilePostModel()->prepareApiDataForComment($comment, $profilePost, $user)));
         return $this->responseData('bdApi_ViewApi_ProfilePost_Comments_Single', $data);
     }
     list($profilePost, $user) = $this->_getUserProfileHelper()->assertProfilePostValidAndViewable($profilePostId);
     $pageNavParams = array();
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $limit = XenForo_Application::get('options')->messagesPerPage;
     $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
     if (!empty($inputLimit)) {
         $limit = $inputLimit;
         $pageNavParams['limit'] = $inputLimit;
     }
     $fetchOptions = array('perPage' => $limit, 'page' => $page);
     $comments = $this->_getProfilePostModel()->getProfilePostCommentsByProfilePost($profilePostId, 0, $this->_getProfilePostModel()->getCommentFetchOptionsToPrepareApiData($fetchOptions));
     $total = $profilePost['comment_count'];
     $data = array('comments' => $this->_filterDataMany($this->_getProfilePostModel()->prepareApiDataForComments($comments, $profilePost, $user)), 'comments_total' => $total);
     bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'profile-posts/comments', $profilePost, $pageNavParams);
     return $this->responseData('bdApi_ViewApi_ProfilePost_Comments', $data);
 }
Esempio n. 30
0
 public function prepareApiDataForAttachment(array $attachment, array $post, array $thread, array $forum, $tempHash = '')
 {
     /* @var $attachmentModel XenForo_Model_Attachment */
     $attachmentModel = $this->getModelFromCache('XenForo_Model_Attachment');
     $attachment = $attachmentModel->prepareAttachment($attachment);
     $publicKeys = array('attachment_id' => 'attachment_id', 'content_id' => 'post_id', 'view_count' => 'attachment_download_count', 'filename' => 'filename');
     $data = bdApi_Data_Helper_Core::filter($attachment, $publicKeys);
     $paths = XenForo_Application::get('requestPaths');
     $paths['fullBasePath'] = XenForo_Application::getOptions()->get('boardUrl') . '/';
     $data['links'] = array('permalink' => XenForo_Link::buildPublicLink('attachments', $attachment));
     if (!empty($attachment['thumbnailUrl'])) {
         $data['links']['thumbnail'] = XenForo_Link::convertUriToAbsoluteUri($attachment['thumbnailUrl'], true, $paths);
     }
     if (!empty($post['post_id'])) {
         $data['links'] += array('data' => bdApi_Data_Helper_Core::safeBuildApiLink('posts/attachments', $post, array('attachment_id' => $attachment['attachment_id'])), 'post' => bdApi_Data_Helper_Core::safeBuildApiLink('posts', $post));
     }
     $data['permissions'] = array('view' => !empty($tempHash) ? $attachmentModel->canViewAttachment($attachment, $tempHash) : $this->canViewAttachmentOnPost($post, $thread, $forum), 'delete' => !empty($tempHash) ? $attachmentModel->canDeleteAttachment($attachment, $tempHash) : $this->canEditPost($post, $thread, $forum));
     if (isset($post['messageHtml'])) {
         $data['attachment_is_inserted'] = empty($post['attachments'][$attachment['attachment_id']]);
     }
     return $data;
 }