The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
vB5 API help - latest / trending posts list only returns if < 5 days
I created a simple PHP script that loads the vB5 API and generates a simple JSON list of the trending posts. (See sample code below). The problem is that I can't get the scripts to generate anything for more than a couple days. Ideally I'd like to get the trending posts in the last 7 days, last 31 days, etc. But it I go over 3-5 days, nothing is returned. Any suggestions?
Sample code to load the vB5 API, and get the last 20 days of posts: Code:
$vbpath = $_SERVER['DOCUMENT_ROOT']; define('CSRF_PROTECTION', false); require_once($vbpath . '/includes/vb5/autoloader.php'); vB5_Autoloader::register($vbpath); vB5_Frontend_Application::init('config.php'); $api = Api_InterfaceAbstract::instance(); $search_json = '{"channel":["15"],"starter_only":1,"date":{"from":"'7'"},"sort":{"lastcontent":"desc"},"view":"","exclude_type":["vBForum_PrivateMessage"]}'; $threads = vB_Api::instanceInternal('search')->getInitialResults($search_json, 30, 1); $i = 0; $thread_returns = array(); if (!isset($threads['errors']) AND !empty($threads['results'])) { //let's get views too $threads['results'] = vB_Api::instanceInternal('node')->mergeNodeviewsForTopics($threads['results']); foreach ($threads['results'] as $tid => $thread_details) { $i++; $thread_returns['results'][$i] = array( 'title' => $thread_details['content']['title'], 'publishdate' => $thread_details['content']['publishdate'], 'channeltitle' => $thread_details['content']['channeltitle'], 'description' => $thread_details['content']['description'], 'userid' => $thread_details['content']['userid'], 'authorname' => $thread_details['content']['authorname'], 'uniqueid' => $thread_details['content']['nodeid'] ); //Get author profile page if($user_info = vB_User::fetchUserinfo($thread_details['content']['userid'], 0, false, false)) { $thread_returns['results'][$i]['user_bbprofileurl'] = vB5_Route::buildUrl('profile|bburl', array('userid' => $thread_details['content']['userid'], 'username' => $thread_details['content']['authorname'])); } //vB5_Route::buildUrl -- build out the URL to the post $thread_returns['results'][$i]['postlink'] = vB5_Route::buildUrl( $thread_details['routeid'] . '|fullurl', array( 'nodeid' => $thread_details['nodeid'], 'title' => $thread_details['title'] ) ); //vB5_Route::buildUrl -- build out the URL to the channel $thread_returns['results'][$i]['channellink'] = vB5_Route::buildUrl( $thread_details['content']['channelroute'] . '|fullurl' ); //Add in the views and votes $thread_returns['results'][$i]['views'] = $thread_details['content']['views']; $thread_returns['results'][$i]['votes'] = $thread_details['content']['votes']; } } $thread_returns['totalRecords'] = count($thread_returns['results']); $thread_returns['searchJSON'] = $search_json; $thread_returns['days'] = $num_days; if ($thread_returns['totalRecords'] > 0) { header('Content-Type: application/json'); echo json_encode($thread_returns); } else { var_dump($thread_returns); } Any help is greatly appreciated. Cheers, Jeff |
#2
|
||||
|
||||
You could use template for this also... just search for initialResult in templates for examples. There is also a ignore cache as search option . You could try this.
|
#3
|
|||
|
|||
An update -- one of the problems was actually a silent json_encode error in PHP -- once I checked for json errors I saw that error. Wrapping all of the thread details in utf8_encode() fixed that error:
Code:
'title' => utf8_encode($thread_details['content']['title']), Cheers, Jeff |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|