MODx & Vbulletin 3.8.x — the last message from the forum

Recently I wrote how to do the merge users and MODx to vbulletin, but what good does that do if the relationship between the forum and the website only users? Want some practical applications of this merger, and to warm up will make the output of the last N messages from the forum on the website.

easy


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

For starters, we need to decide how messages will look on the website — in a table? Typically, this sequential string of records with date and time, author, topic, and section. Still as the variant of the first M characters of the message to be of interest to visitors.
Therefore, we will create a chunk of forum_last_messages and inscribe in it the view for each record:
 
<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> 

In fact that we've identified the div with the class forum_message, then to his css to make beautiful and format the text inside to fit your needs. Next, we insert the link to the forum showing the display thread with the specified last message, name and number of answers in it. Also, if necessary, we can decorate and the last flood on forme.
Next comes the paragraph with the name of the section is made in such a way as not to put the tag
<br />
— in the same css styles, you can format this paragraph with the selector .forum_message p {}. Well, and then insert a placeholder cropped of forum messages. Personally, I don't need it was, but I made it — template engine successfully processes it and replace the empty place.

Now the most interesting and at the same time simple. One request to forum, one method MODx, one loop and a snippet forum_last_messages ready!

 
<?php 
global $modx, $vbulletin; 

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

$count= (empty($count) || ($count<2)) ? 10 : $count; //number of messages to display, default is 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')) { 
//the array elements are named quite clear 
$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']) //the date format 
), 
'[+', 
'+]' 
); 
} 

return $txt; 
?> 

I think the code is outrageously simple and intuitive :)

In the loop-handler series I did cropped the text of the post for the simple reason that the thread table is not stored, the text of the last message, and to obtain er will have to pull more and post table, which will affect performance.

So now using [!forum_last_messages?count=`17`!] on the site we will receive a list of recent topics on the forum!

By the way: a request to the forum selects all OPEN for anonymous topics and none closed. Honestly, it's a glitch, and a fifth wheel, because if there is a merger with the forum and the user is logged in we can easily to know what topic he has access, and how to choose them. But should these movements to make if easier to go to the forum to my account and view subscriptions to your favorite theme?
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

ODBC Firebird, Postgresql, executing queries in Powershell

garage48 for the first time in Kiev!

The Ministry of communications wants to ban phones without GLONASS