View Full Version : vBulletin integration

02-21-2010, 07:12 PM
I recently changed the way my HELP pages work to use a special forum, and threads from it, for most of the HELP page content. (There are some pages that pull data out of the database for display, so it is the pages that contain only text and images.)

I simply use the following code to grab the text from a thread, BBCode parse it, and display it. The function fetches only the first post in a thread, so other developers can use those threads for comments about the content without affecting the text that is displayed. It makes editing and revisions very simple - much easier than typing raw HTML into the PHP code.

Call it like this:

$help = get_forum_help("New Game");

echo $help['message'];
echo $help['last_edit'];
The function that does the hard work:

/* *** FORUM FUNCTIONS ************************************************* */

$bbcode_parser = & new vB_BbCodeParser($vbulletin, fetch_tag_list(), true);

function get_forum_help($help_thread) {
global $vbulletin, $bbcode_parser;

$help_forum = '1'; // Change to the forum that is used

// Get the text, and last edit date, if any (that's the ORDER BY and LIMIT 1)
$sql =
"SELECT thread.threadid, thread.title, post.pagetext, " .
"COALESCE(editlog.dateline, thread.dateline) AS dateline " .
"FROM thread " .
"INNER JOIN post ON post.postid = thread.firstpostid " .
"LEFT JOIN editlog ON editlog.postid = post.postid " .
"WHERE thread.forumid = $help_forum " .
"AND thread.title = '$help_thread' " .
"ORDER BY editlog.dateline DESC " .
"LIMIT 1";

$help = sql_query_first($sql);

// The title is not used
// $help['title'] = unhtmlspecialchars( $help['title'] );
// $help['title'] = xhtml_clean( $help['title'] );

// Parse the BB Code and change new lines to break
$help['message'] = $bbcode_parser->do_parse($help['pagetext'], true,true,true,true,true);

// Make sure that the message has two new lines at the end
$help['message'] .= "<br /><br />";

$help['date'] = vbdate( $vbulletin->options['dateformat'], $help['dateline'] );
$help['time'] = vbdate( $vbulletin->options['timeformat'], $help['dateline'] );

$help['last_edit'] =
"<br /><br /><p align='right'><font size='-2'><i>" .
"Last Edit ".$help['date']." ".$help['time'] .

return $help;