📜 ⬆️ ⬇️

MODx & Vbulletin 3.8.x - latest forum posts

I recently wrote how to merge vbulletin and MODx users, but what is the use of this if the connection between the forum and the site is only in users? I would like some practical application of this merger, and for a warm-up we will conclude the last N messages from the forum on the site.

Easy peasy


Just want to say that this can be implemented at any time, and this article does not depend on the previous one.

First, we need to decide how the messages will look on the site - in the form of a table? As a rule, these are consecutive lines of records with the date and time, author, topic and section. Even as an option, the first M characters of the message to completely interest visitors.
Therefore, we will create a chunk of forum_last_messages and enter the form for each of the entries in it:
 <div id="post_[+postid+]" class="forum_message"> <a href="[+forumlink+]/showthread.php?p=[+postid+]">[+threadtitle+] ([+replycount+])</a>  <span id="user">[+lastposter+]  [+postdate+]</span> <p>/[+forum+]</p> [+shortmessage+] </div> 

Actually, we denoted that div with the class forum_message, so that later in css styles to make it beautiful and format the text inside to fit your needs. Next, we insert a link to the forum indicating the display of the thread with the given last message, its name and the number of answers in it. Also, if necessary, we can decorate the last flooder on the furme.
Next comes the paragraph with the section name - done in such a way as not to put a tag
 <br /> 
- in the same css styles, you can format this particular paragraph using the .forum_message p {} selector. Well, then insert the placeholder trimmed forum message. Personally, I did not need it, but I did it - the template engine will successfully process it and replace it with an empty space.

Now the most interesting and at the same time simple. One request to the forum, one MODx method, one cycle and a snippet forum_last_messages is ready!
')
 <? php
 global $ modx, $ vbulletin;

 $ forumlink = 'http: // URLTOYOUFORUM';
 $ forum_base = (empty ($ vbulletin-> config ['Database'] ['dbname']))?  'FORUMBASE': $ vbulletin-> config ['Database'] ['dbname'];
 // here it is necessary to clarify: most likely the base of the forum and the site is different, therefore we need to know the name of the forum base 
 $ forum_prefix = (empty ($ vbulletin-> config ['Database'] ['tableprefix']))?  'vb_': $ vbulletin-> config ['Database'] ['tableprefix'];

 $ count = (empty ($ count) || ($ count <2))?  10: $ count;  // number of messages for output, default 10


 $ sql = 'SELECT t.title as topic, t.lastpostid, t.lastpost, t.lastposter, t.forumid, t.replycount, t.dateline, f.title as forum
 FROM `'. $ Forum_base.'` ``. $ Forum_prefix.'thread` t, `'. $ Forum_base.'`` `. $ Forum_prefix.'forum` f
 WHERE t.`visible` = 1
 AND t.`open` = 1
 AND f.forumid = t.forumid
 AND t.forumid NOT 
 IN (
     SELECT forumid
     FROM `'. $ Forum_base.'`.``. $ Forum_prefix.'forumpermission`
 )
 ORDER BY t.lastpost DESC 
 LIMIT '. $ Count.'; ';
 $ res = $ modx-> db-> query ($ sql);

 $ txt = ";

 while ($ f_res = $ modx-> db-> getRow ($ res, 'assoc')) {
 // elements of the array are called quite understandable to themselves
 $ txt. = $ modx-> parseChunk ('forum_last_messages', 
     array (
         'forumlink' => $ forumlink,
         'postid' => $ f_res ['lastpostid'],                       
         'threadtitle' => $ f_res ['topic'],                         
         'replycount' => $ f_res ['replycount'],
         'lastposter' => $ f_res ['lastposter'],
         'forum' => $ f_res ['forum'],
         'postdate' => date ("H: i", $ f_res ['lastpost']) // date format
         ),
     '[+',
     '+]'
     );
 }

 return $ txt;
 ?>

I think the code is ugly simple and clear :)

I didn’t make the cut text of the post in the series handler loop for the simple reason that the thread does not store the text of the last message, and in order to get it, it will also be necessary to pull the post table, which will affect performance.

So, now using [! Forum_last_messages? Count = `17`!] On the site we get a list of the latest fresh topics on the forum!

By the way: The request to the forum is chosen by all OPEN for Anonymus topics and not a single closed one. Honestly, this is a flaw, and the fifth wheel, because if there is a merger with the forum and the user is logged in, we can easily find out which topics he has access to, and which not, and select them. But is it necessary to make such gestures, if it's easier to go to the forum to your personal account and see the subscriptions to your favorite topics?

Source: https://habr.com/ru/post/93943/


All Articles