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

    Display latest topics on non-vb pages

    Do you have a sql-question that selects latest X posts in all open topics.

    Want to do a nice Joomla and Wordpress plugin to display latest.

    #2
    I recommend just using the Node API similar to what you did for login to fetch the latest posts instead of doing a direct SQL query to the database.

    Comment


      #3
      Can you give me a hint how?

      Comment


        #4
        Correction on what I said. You should use the Search API not the Node API.

        Call the get getInitialResults Search API method and pass a Search JSON data (same JSON you would use to display Latest Topics in Search Module). You could also specify the number of result items per page to return and page number.

        Comment


          #5
          I have tried but don't understand. Can you explain more?

          Comment


            #6
            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.

            Comment


              #7
              Sorry but still lost

              Comment


                #8
                Is there a guide how to use vbulletin for beginners? With examples?

                Comment


                  #9
                  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 = [];
                  }

                  Comment


                    #10
                    Is it possibel to get your class DB also?

                    Comment

                    Working...
                    X