Announcement

Collapse
No announcement yet.

Display latest topics on non-vb pages

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ChristianAlfredsson
    replied
    Is it possible to collect more information?

    I have the script and want to get latest post text and date?

    Leave a comment:


  • ChristianAlfredsson
    replied
    I have two forums with latest vBulletin. API is activated on both sites, but I have missed anything in configuration for it to work?


    www.ciklid.org - Not working
    https://www.ciklid.org/forum/api/test.php


    www.zoopet.com - Working
    https://www.zoopet.com/forum/api/test.php

    PHP Code:
    <?

    $vbpath = '..';
    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 = '{ "last":{"from":"100"}, "view":"topic","starter_only":"1", "sort":{"lastcontent":"desc"}, "channel":["18"] }';

    $threads = vB_Api::instanceInternal('search')->getInitialResults($search_json, 30, 1);

    $i = 0;
    $thread_returns = array();

    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']
    );
    $thread_returns['results'][$i]['postlink'] = vB5_Route::buildUrl(
    $thread_details['routeid'] . '|fullurl',
    array(
    'nodeid' => $thread_details['nodeid'],
    'title' => $thread_details['title']
    )
    );
    }
    $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);
    }

    ?>

    Leave a comment:


  • NumNum
    replied
    Thats pretty sharp! Nice site too!

    Leave a comment:


  • ChristianAlfredsson
    replied
    Here is an image of the first page on https://www.zoopet.com

    Amazing code from you

    Leave a comment:


  • ChristianAlfredsson
    replied
    Great. It is now working for me too. Can't thank you enough!

    Leave a comment:


  • ChristianAlfredsson
    replied
    Thank you! Of course. I will change it and report back!

    Leave a comment:


  • beergeek
    replied
    That's just a warning -- and I guess it's not bulletproof code. But nothing is returned -- meaning nothing matched your search parameters / json ($search_json)

    Leave a comment:


  • ChristianAlfredsson
    replied
    Tried it and get this error and no JSON

    Link: https://www.zoopet.com/forum/api/json.php

    PHP Code:
    PHP Warning:  count(): Parameter must be an array or an object that implements Countable in /home/zoopet/forum/api/json.php on line 4 
    This is the line in the code

    PHP Code:
    $thread_returns['totalRecords'] = count($thread_returns['results']); 

    Leave a comment:


  • beergeek
    replied
    Here's how I ended up doing this -- I was (*shockingly*) able to get the API to work. I created a simple file that initialized the API and as @glenrocksvb suggested, uses the search json parameters to pull posts. I greatly simplified the returning JSON because it caused problems occasionally (failing in the json_encode step for some reason).

    Code:
    if (isset($_GET['days'])) {
      $num_days = (int)$_GET['days'];
    } else {
      $num_days = 1;
    }
    
    if (isset($_GET['wanted'])) {
      $channel_id = 23;
    } else {
      $channel_id = 21;
    }
    
    // Path to the vBulletin 5 folder. 
    // '.' indicates current directory where the .htaccess file resides.
    $vbpath = '..';
    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":["'.$channel_id.'"],"starter_only":1,"date":{"from":"'.$num_days.'"},"sort":{"lastcontent":"desc"},"view":"","exclude_type":["vBForum_PrivateMessage"]}';
    
    $threads = vB_Api::instanceInternal('search')->getInitialResults($search_json, 30, 1);      
    
    $i = 0;
    $thread_returns = array();
    
    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']
      );
      $thread_returns['results'][$i]['postlink'] = vB5_Route::buildUrl(
        $thread_details['routeid'] . '|fullurl',
        array(
          'nodeid' => $thread_details['nodeid'],
          'title' => $thread_details['title']
        )
      );
    }
    $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);
    }
    Put this on my VB5 forum, under a new directory at the root -- then called that from a script on my WP site to parse the JSON and make a list of links. You can, of course, modify the array elements returned to fit what you need.

    Cheers,
    Jeff

    Leave a comment:


  • ChristianAlfredsson
    replied
    Is it possibel to get your class DB also?

    Leave a comment:


  • kolifan
    replied
    We use this code on our website. It brings headings of messages of a forum to the homepage

    PHP Code:
    <?php

    class ForumParser
    {
        private 
    $forumIds = [15263];
        private 
    $ctChannel 23;
        private 
    $ctText 22;
        private 
    $prefix 'https://oursite/forum/';
        private 
    $prefixPage 'https://oursite/forum/channel/';
        private 
    $count 5;

        public function 
    get()
        {
            
    $this->loadChannels($this->forumIds);
            
    $this->loadThreads();
            
    $this->loadPosts();
            
    $this->sortPosts();
            
    $this->loadUsers();
            
    $result = [];
            foreach (
    $this->posts as $post) {
                
    $p $this->fillPost($post);
                if (
    $p !== null) {
                    
    $result[] = $p;
                }
            }
            return 
    $result;
        }

        private function 
    loadChannels($ids)
        {
            
    $pattern '
                SELECT
                    `nodeid`,`parentid`,`title`,`urlident`
                FROM
                    `vbc_node`
                WHERE
                    `nodeid` IN ('
    .implode(','$ids).')
            '
    ;
            foreach (
    DB::query2base1($patternnullDB::fAssoc) as $row) {
                
    $this->channels[$row['nodeid']] = [
                    
    'title' => $row['title'],
                    
    'url' => $this->prefixPage.$row['urlident'],
                ];
            }
        }

        private function 
    loadChildren($ids$level 5)
        {
            if (
    $level <= 0) {
                return;
            }
            
    $pattern '
                SELECT
                    `nodeid`,`parentid`,`title`,`urlident`
                FROM
                    `vbc_node`
                WHERE
                    `parentid` IN ('
    .implode(','$ids).')
                    AND `contenttypeid`='
    .$this->ctChannel.'
                    AND `showpublished`
            '
    ;
            
    $idsN = [];
            foreach (
    DB::query2base1($patternnullDB::fAssoc) as $row) {
                
    $id $row['nodeid'];
                
    $prefix = isset($this->channels[$row['parentid']]) ? $this->channels[$row['parentid']]['url'].'/' $this->prefixPage;
                
    $this->channels[$id] = [
                    
    'title' => $row['title'],
                    
    'url' => $prefix.$row['urlident'],
                ];
                
    $idsN[] = $id;
            }
            if (!empty(
    $idsN)) {
                
    $this->loadChildren($idsN$level 1);
            }
        }

        private function 
    loadThreads()
        {
            
    $pattern '
                SELECT
                    *
                FROM
                    `vbc_node`
                WHERE
                    `parentid` IN ('
    .implode(','array_keys($this->channels)).')
                    AND `contenttypeid`='
    .$this->ctText.'
                    AND `showpublished`
                ORDER BY
                    `lastcontent` DESC
                LIMIT '
    .$this->count.'
            '
    ;
            foreach (
    DB::query2base1($patternnullDB::fAssoc) as $row) {
                
    $this->threads[$row['nodeid']] = $row;
                
    $this->posts[] = $row;
                if (
    $row['totalcount'] > 0) {
                    
    $this->threadsP[] = $row['nodeid'];
                }
            }
        }

        private function 
    loadPosts()
        {
            if (empty(
    $this->threadsP)) {
                return;
            }
            
    $pattern '
                SELECT
                    *
                FROM
                    `vbc_node`
                WHERE
                    `parentid` IN ('
    .implode(','$this->threadsP).')
                    AND `contenttypeid`='
    .$this->ctText.'
                    AND `showpublished`
                ORDER BY
                    `lastcontent` DESC
                LIMIT '
    .$this->count.'
            '
    ;
            foreach (
    DB::query2base1($patternnullDB::fAssoc) as $row) {
                
    $this->posts[] = $row;
            }
        }

        private function 
    sortPosts()
        {
            
    usort($this->posts, function ($a$b) {
                if (
    $a['publishdate'] > $b['publishdate']) {
                    return -
    1;
                }
                return 
    1;
            });
            
    $this->posts array_slice($this->posts0$this->count);
        }

        private function 
    loadUsers()
        {
            
    $ids = [];
            foreach (
    $this->posts as $post) {
                
    $ids[$post['userid']] = true;
            }
            if (empty(
    $ids)) {
                return;
            }
            
    $pattern '
                SELECT
                    `u`.*,`u`.`userid`,`u`.`username`,`a`.`filename`
                FROM
                    `vbc_user` AS `u`
                LEFT JOIN
                    `vbc_customavatar` AS `a`
                    ON `a`.`userid`=`u`.`userid`
                WHERE
                    `u`.`userid` IN ('
    .implode(','array_keys($ids)).')';
            foreach (
    DB::query2base1($patternnullDB::fAssoc) as $row) {
                if (
    $row['filename']) {
                    
    $row['avatar_src'] = $this->prefix.'core/customavatars/'.$row['filename'];
                } else {
                    
    $row['avatar_src'] = $this->prefix.'core/images/default/default_avatar_large.png';
                }
                
    $this->users[$row['userid']] = $row;
            }
        }

        private function 
    fillPost($post)
        {
            
    $id $post['nodeid'];
            if (isset(
    $this->threads[$id])) {
                
    $thread $post;
                
    $suffix '';
            } elseif (isset(
    $this->threads[$post['parentid']])) {
                
    $thread $this->threads[$post['parentid']];
                
    $suffix '?p='.$post['nodeid'].'#post'.$post['nodeid'];
            } else {
                return 
    null;
            }
            if (isset(
    $this->channels[$thread['parentid']])) {
                
    $forum $this->channels[$thread['parentid']];
            } else {
                return 
    null;
            }
            if (isset(
    $this->users[$post['userid']])) {
                
    $user $this->users[$post['userid']];
            } else {
                return 
    null;
            }
            return [
                
    'thread_title' => $thread['title'],
                
    'thread_url' => $forum['url'].'/'.$thread['nodeid'].'-'.$thread['urlident'].$suffix,
                
    'forum_title' => $forum['title'],
                
    'forum_url' => $forum['url'],
                
    'date' => date('Y-m-d H:i:s'$post['publishdate']),
                
    'ts' => $post['publishdate'],
                
    'user_name' => $user['username'],
                
    'user_url' => $this->prefix.'member/'.$user['userid'].'-'.mb_strtolower($user['username'], 'UTF-8'),
                
    'avatar_src' => $user['avatar_src'],
            ];
        }

        private 
    $channels = [];

        private 
    $threads = [];

        private 
    $threadsP = [];

        private 
    $posts = [];

        private 
    $users = [];
    }

    Leave a comment:


  • ChristianAlfredsson
    replied
    Is there a guide how to use vbulletin for beginners? With examples?

    Leave a comment:


  • ChristianAlfredsson
    replied
    Sorry but still lost

    Leave a comment:


  • glennrocksvb
    replied
    Check for sample usage of getInitialResults() function at /core/vb/api/follow.php inside the getFollowingUserActivities() function. Inside that function, there is a call to getInitialResults() function.

    Leave a comment:


  • ChristianAlfredsson
    replied
    I have tried but don't understand. Can you explain more?

    Leave a comment:

Working...
X