Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2020, 05:32 PM
Beergeeksf Beergeeksf is offline
 
Join Date: Jan 2018
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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);
}
If I change the $search_json code above 5 days, nothing is returned, no error is create, just blank output.

Any help is greatly appreciated.

Cheers,
Jeff
Reply With Quote
  #2  
Old 06-27-2020, 04:24 PM
delicjous's Avatar
delicjous delicjous is offline
 
Join Date: Nov 2014
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 06-29-2020, 05:26 PM
Beergeeksf Beergeeksf is offline
 
Join Date: Jan 2018
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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']),
Still seeing inconsistent results, but at least I get results every time now.

Cheers,
Jeff
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:49 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03735 seconds
  • Memory Usage 2,179KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete