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); }
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); }
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); }
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); }
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); }
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; } $search = $this->_getSearchModel()->prepareSearch($search); $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']); if (XenForo_Application::$versionId > 1050000 && !empty($search['searchConstraints']['tag'])) { /** @var bdApi_Extend_Model_Tag $tagModel */ $tagModel = $this->getModelFromCache('XenForo_Model_Tag'); $tags = $tagModel->bdApi_getTagsByIds(explode(' ', $search['searchConstraints']['tag'])); $data['search_tags'] = $tagModel->prepareApiDataForTags($tags); } switch ($search['search_type']) { case self::OPTION_SEARCH_TYPE_USER_TIMELINE: if (!$this->_isFieldExcluded('user') && !empty($search['searchConstraints']['user']) && is_array($search['searchConstraints']['user']) && count($search['searchConstraints']['user']) === 1) { $userId = reset($search['searchConstraints']['user']); /** @var bdApi_XenForo_Model_User $userModel */ $userModel = $this->getModelFromCache('XenForo_Model_User'); $user = $userModel->getUserById($userId, $userModel->getFetchOptionsToPrepareApiData()); $data['user'] = $this->_filterDataSingle($userModel->prepareApiDataForUser($user), array('user')); } break; } 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); }
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); }
public function actionGetIndex() { $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT); if (!empty($userId)) { return $this->responseReroute(__CLASS__, 'single'); } $userModel = $this->_getUserModel(); $pageNavParams = array(); $page = $this->_input->filterSingle('page', XenForo_Input::UINT); $limit = XenForo_Application::get('options')->membersPerPage; $inputLimit = $this->_input->filterSingle('limit', XenForo_Input::UINT); if (!empty($inputLimit)) { $limit = $inputLimit; $pageNavParams['limit'] = $inputLimit; } $conditions = array('user_state' => 'valid', 'is_banned' => 0); $fetchOptions = array('limit' => $limit, 'page' => $page, 'order' => bdApi_XenForo_Model_User::ORDER_USER_ID); $users = $userModel->getUsers($conditions, $userModel->getFetchOptionsToPrepareApiData($fetchOptions)); $total = $userModel->countUsers($conditions); $data = array('users' => $this->_filterDataMany($userModel->prepareApiDataForUsers($users)), 'users_total' => $total); bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'users', array(), $pageNavParams); return $this->responseData('bdApi_ViewApi_User_List', $data); }
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); }
protected function _getNewOrRecentResponse($searchType, array $threadIds) { $visitor = XenForo_Visitor::getInstance(); $threadModel = $this->_getThreadModel(); $results = array(); $threads = $threadModel->getThreadsByIds($threadIds, array('join' => XenForo_Model_Thread::FETCH_FORUM | XenForo_Model_Thread::FETCH_USER, 'permissionCombinationId' => $visitor['permission_combination_id'])); foreach ($threadIds as $threadId) { if (!isset($threads[$threadId])) { continue; } $threadRef =& $threads[$threadId]; $threadRef['permissions'] = XenForo_Permission::unserializePermissions($threadRef['node_permission_cache']); if ($threadModel->canViewThreadAndContainer($threadRef, $threadRef, $null, $threadRef['permissions']) && !$visitor->isIgnoring($threadRef['user_id'])) { $results[] = array('thread_id' => $threadId); } } $data = array('threads' => $results); $dataLimit = $this->_input->filterSingle('data_limit', XenForo_Input::UINT); if ($dataLimit > 0) { $searchResults = array(); foreach ($results as $result) { $searchResults[] = array(XenForo_Model_Search::CONTENT_TYPE => 'thread', XenForo_Model_Search::CONTENT_ID => $result['thread_id']); } /** @var bdApi_Extend_Model_Search $searchModel */ $searchModel = $this->getModelFromCache('XenForo_Model_Search'); $search = $searchModel->insertSearch($searchResults, $searchType, '', array(), 'date', false); $dataResults = array_slice($searchResults, 0, $dataLimit); $dataResults = $searchModel->prepareApiDataForSearchResults($dataResults); $data['data'] = $searchModel->prepareApiContentDataForSearch($dataResults); bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $dataLimit, $search['result_count'], 1, 'search/results', $search, array('limit' => $dataLimit)); } return $this->responseData('bdApi_ViewApi_Thread_NewOrRecent', $data); }
public function actionGetTimeline() { $user = $this->_getUserOrError(); /** @var XenForo_Model_UserProfile $userProfileModel */ $userProfileModel = $this->getModelFromCache('XenForo_Model_UserProfile'); if (!$userProfileModel->canViewProfilePosts($user)) { return $this->responseNoPermission(); } $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; } /** @var bdApi_XenForo_Model_ProfilePost $profilePostModel */ $profilePostModel = $this->getModelFromCache('XenForo_Model_ProfilePost'); $conditions = array('deleted' => false, 'moderated' => false); $fetchOptions = array('perPage' => $limit, 'page' => $page); $profilePosts = $profilePostModel->getProfilePostsForUserId($user['user_id'], $conditions, $profilePostModel->getFetchOptionsToPrepareApiData($fetchOptions)); $total = $profilePostModel->countProfilePostsForUserId($user['user_id'], $conditions); $data = array('profile_posts' => $this->_filterDataMany($profilePostModel->prepareApiDataForProfilePosts($profilePosts, $user)), 'profile_posts_total' => $total); if (!$this->_isFieldExcluded('user')) { $data['user'] = $this->_filterDataSingle($this->_getUserModel()->prepareApiDataForUser($user), array('user')); } bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'users/timeline', $user, $pageNavParams); return $this->responseData('bdApi_ViewApi_User_Timeline', $data); }
public function actionGetFollowed() { $this->_assertRegistrationRequired(); $total = $this->_getThreadWatchModel()->countThreadsWatchedByUser(XenForo_Visitor::getUserId()); if ($this->_input->inRequest('total')) { $data = array('threads_total' => $total); return $this->responseData('bdApi_ViewApi_Thread_Followed_Total', $data); } $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; } $fetchOptions = array('limit' => $limit, 'page' => $page); $threadWatches = $this->_getThreadWatchModel()->getThreadsWatchedByUser(XenForo_Visitor::getUserId(), false, $fetchOptions); $threadsData = array(); $threads = array(); if (!empty($threadWatches)) { $threadIds = array(); foreach ($threadWatches as $threadWatch) { $threadIds[] = $threadWatch['thread_id']; } $fetchOptions = $this->_getThreadModel()->getFetchOptionsToPrepareApiData(); $threads = $this->_getThreadModel()->getThreadsByIds($threadIds, $fetchOptions); $threads = $this->_prepareThreads($threads); } foreach ($threadWatches as $threadWatch) { foreach ($threads as &$threadData) { if ($threadWatch['thread_id'] == $threadData['thread_id']) { $threadData = $this->_getThreadWatchModel()->prepareApiDataForThreadWatches($threadData, $threadWatch); $threadsData[] = $threadData; } } } $data = array('threads' => $this->_filterDataMany($threadsData), 'threads_total' => $total); bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $limit, $total, $page, 'threads/followed', array(), $pageNavParams); return $this->responseData('bdApi_ViewApi_Thread_Followed', $data); }
public function actionPostPosts() { $constraints = array(); $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT); if (!empty($threadId)) { $constraints['thread'] = $threadId; } $search = $this->_doSearch('post', $constraints); $pageResultIds = $this->_getSearchModel()->sliceSearchResultsToPage($search, 1, null); $results = $this->_getSearchModel()->prepareApiDataForSearchResults($pageResultIds); $threadIds = array(); $posts = array(); foreach ($results as $key => $result) { if ($result['content_type'] == 'post') { $posts[$key] = array('post_id' => $result['content_id']); } elseif ($result['content_type'] == 'thread') { $posts[$key] = array('thread_id' => $result['content_id']); $threadIds[intval($result['content_id'])] = $key; } } if (!empty($threadIds)) { /** @var XenForo_Model_Thread $threadModel */ $threadModel = $this->getModelFromCache('XenForo_Model_Thread'); $threads = $threadModel->getThreadsByIds(array_keys($threadIds)); foreach ($threadIds as $threadId => $key) { if (isset($threads[$threadId])) { $threadRef =& $threads[$threadId]; $posts[$key]['post_id'] = $threadRef['first_post_id']; } } ksort($posts); } $data = array('posts' => $posts); $resultsData = $this->_fetchResultsData($results); if (!empty($resultsData)) { $data['data'] = $resultsData['data']; bdApi_Data_Helper_Core::addPageLinks($this->getInput(), $data, $resultsData['limit'], $search['result_count'], $resultsData['page'], 'search/results', $search, $resultsData['pageLinkParams']); } return $this->responseData('bdApi_ViewApi_Search_Posts', $data); }