<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Vb4_showthread extends vB_Api { public function call($threadid, $perpage = 0, $pagenumber = 1, $postid = 0) { $thread = vB_Api::instance('node')->getFullContentforNodes(array($threadid)); if(empty($thread)) { return array("response" => array("errormessage" => array("invalidid"))); } vB_Api::instanceInternal('node')->incrementNodeview($threadid); $thread = $thread[0]; $modPerms = vB::getUserContext()->getModeratorPerms($thread); $perpage = vB_Library::instance('vb4_functions')->getUsersPostPerPage($perpage); $posts = array(); $page_nav = vB_Library::instance('vb4_functions')->pageNav(1, $perpage, 1); $search = array("channel" => $threadid); $search['view'] = vB_Api_Search::FILTER_VIEW_CONVERSATION_THREAD; $search['depth'] = 1; $search['include_starter'] = true; $search['sort']['isstarter'] = 'desc'; $search['sort']['created'] = 'asc'; $search['nolimit'] = 1; $searchAPI = vB_Api::instanceInternal('search'); if (!empty($postid)) { $node = vB_Api::instance('node')->getNode($postid, false, false); if (!empty($node['starter']) OR $threadid != $node['starter']) { $starter = vB_Library::instance('node')->getNodeBare($node['starter']); $pagenumber = $searchAPI->getPageNumber( $postid, $starter, $perpage, $search['depth'], $search['sort']['lastcontent'], $search['include_starter'] ); } else { $postid = null; } } $post_search = $searchAPI->getInitialResults($search, $perpage, $pagenumber, true); $position = 0; $foundPosition = false; if (!isset($post_search['errors']) AND !empty($post_search['results'])) { $assertor = vB::getDbAssertor(); $options = vB::getDatastore()->getValue('options'); $userInfo = vB_Api::instance('user')->fetchUserinfo(); $timenow = vB::getRequest()->getTimeNow(); $cutoff = $timenow - ($options['markinglimit'] * 86400); if ($userInfo['userid']) { $threadInfo = vB_Library::instance('node')->getNodeBare($threadid);; $threadread = $assertor->getRow('vBForum:noderead', array( vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $threadid, 'userid' => $userInfo['userid'], )); $threadread = ($threadread) ? $threadread['readtime'] : 0; $forumread = $assertor->getRow('vBForum:noderead', array( vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $threadInfo['parentid'], 'userid' => $userInfo['userid'], )); $forumread = ($forumread) ? $forumread['readtime'] : 0; $threadview = max($threadread, $forumread, $cutoff); } else { $threadview = $cutoff; } $firstpostid = 0; $lastpostid = 0; $firstunread = 0; $poll = array(); foreach ($post_search['results'] AS $key => $node) { if (in_array($node['contenttypeclass'], array('Link', 'Text', 'Gallery', 'Poll', 'Video', 'Event'))) { if ($firstpostid === 0) { $firstpostid = $node['nodeid']; } if ($firstunread === 0 AND $node['publishdate'] > $threadview) { $firstunread = $node; } list($posts[], $temp) = vB_Library::instance('vb4_functions')->parsePost($node); if (empty($poll) AND !empty($temp)) { $poll = $temp; } $lastpostid = $node['nodeid']; if (!$foundPosition AND !empty($postid)) { $position++; if ($postid == $node['nodeid']) { $foundPosition = true; } } } } $page_nav = vB_Library::instance('vb4_functions')->pageNav($post_search['pagenumber'], $perpage, $post_search['totalRecords']); } $userinfo = vB_Api::instance('user')->fetchUserinfo(); if ($userinfo['userid'] > 0) { $subscribed = vB_Api::instance('follow')->isFollowingContent($thread['nodeid']); } else { $subscribed = 0; } $tagList = array(); if (!empty($thread['content']['taglist'])) { $nodeTags = explode(',', $thread['content']['taglist']); foreach ($nodeTags AS $tag) { $tagList[] = array( 'tag' => $tag, ); } } $response = array(); $response['response']['thread'] = vB_Library::instance('vb4_functions')->parseThreadInfo($thread); $response['response']['postbits'] = $posts; $response['response']['tag_list'] = array('tag_list' => $tagList); if (!empty($poll)) { $response['response']['poll'] = $poll; } $response['response']['pagenav'] = $page_nav; $response['response']['pagenumber'] = intval($pagenumber); if ($foundPosition) { $response['response']['position'] = $position; } $response['response']['FIRSTPOSTID'] = intval($firstpostid); $response['response']['LASTPOSTID'] = intval($lastpostid); $response['response']['firstunread'] = ($firstunread === 0) ? '' : vB5_Route::buildUrl($firstunread['routeid'], $firstunread); $response['response']['firstunreadid'] = ($firstunread === 0) ? '' : intval($firstunread['nodeid']); $response['show'] = array( 'inlinemod' => $thread['content']['canmoderate'] ? 1 : 0, 'spamctrls' => $modPerms['candeleteposts'] > 0 ? 1 : 0, 'openclose' => $modPerms['canopenclose'] > 0 ? 1 : 0, 'approvepost' => $modPerms['canmoderateposts'] > 0 ? 1 : 0, 'deleteposts' => $modPerms['candeleteposts'] > 0 ? 1 : 0, 'subscribed' => $subscribed, ); return $response; } } 