PDA

View Full Version : Display Post from vB to Homepage outside vB w/ bbCode formatting


AdTheRat
09-13-2008, 07:30 PM
Heya, new to vBulletin (gasp nooo, a newbie! =O)

Basically, I've been trying to simply pull first posts of each thread from say a News forum or announcement into the homepage. The forum is in a separate folder.

Now, I've have manage to pull the data I want and display it on the homepage, but when it come to formatting the post (bbCodes and all) it been proving to be a headache.

Was wondering if anyone have any suggestions as in how I could get the post formatted to how it would be displayed in forum outside? Maybe there is a method of using the vBulletin built-in bbCode parser?

I have searched the forum, but I even suck at googling so, sorry if this is a repeated question.

Thanks
- Addy

Dismounted
09-14-2008, 05:17 AM
// initialise bbcode class
$cwd = getcwd();
chdir('./forum/');
require_once('./global.php');
require_once(DIR . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

// parse message
$message = $parser->parse($yourmessage, $forumid);

// get back
chdir($cwd);
Change directories and variables as appropriate.

AdTheRat
09-14-2008, 01:05 PM
Ok, that's a step in the right directation! Yay!..

Right, I get

Fatal error: Call to a member function query_first_slave() on a non-object in /home/cfpasta/domains/pasta.coldfront.net/public_html/forums/includes/functions.php on line 1310

The codes:
function getHTMLNews($trim=false)
{

$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$bb2html = $parser->parse($bb2html, FORUM_ID_NEWS);
//$bb2html = $parser->do_parse($bb2html);

return $bb2html;

}

This is part of my news class. Called on when news is being displayed in template.

News object populated (plus the global.php include) by

//Function to load up the news for homepage

function loadnews() {

$cwd = getcwd();
chdir('./forums/');
require_once('./global.php');
require_once(DIR . '/includes/class_bbcode.php');

global $perfomance;

$db = new mysql();
$query = 'SELECT t.`threadid`, t.`title`, p.`username`, p.`pagetext`, p.`dateline`, d.`ccount` '
. 'FROM vb_thread t INNER JOIN vb_post p ON t.threadid = p.threadid INNER JOIN '
. '(SELECT count(*) as ccount, threadid FROM vb_post GROUP BY threadid) d ON '
. 'd.threadid = t.threadid WHERE p.parentid = 0 and t.forumid = ' . FORUM_ID_NEWS . ' '
. 'ORDER BY t.dateline desc LIMIT 0,10';

//Grab news
$result = $db->do_query($query, 'direct');
$perfomance->add_milestone('SQL Query done');

//If we have news, loop and create objects for each news
while ($row = mysql_fetch_assoc($result)) {
$news = new news($row['threadid'], $row['title'], $row['pagetext'],
$row['ccount'] - 1, $row['username'], $row['dateline']);
//ccount - 1 (remove a count, as query counts the article as well as other comments.

include('../template/default_news.php');
}
$perfomance->add_milestone('News Object populated/displayed');

// get back
chdir($cwd);
}

FORUM_NEWS_ID is defined by a config.php included much earlier.

(To avoid any confusions, the templates are not part of the forums templates is in fact our own.)

~Added~
Just adding this while I'm thinking about, our host just compiled php with mysqli, is it just a simple edit of config from mysql to mysqli and vB will switch over or a bit more to it? Just thought to ask before doing. Kill two birds with one stone, so they say

AdTheRat
09-18-2008, 05:11 PM
*echo* Hello?

Does anyone have any ideas how to fix

Fatal error: Call to a member function query_first_slave() on a non-object in /home/cfpasta/domains/pasta.coldfront.net/public_html/forums/includes/functions.php on line 1310

My searches suggest something to do with DB connections, so I've tried changing $db to $db2, etc, etc.

Dismounted
09-19-2008, 05:08 AM
Since you are calling the parser inside the function - it does not have access to the required variables inside the local scope.
// I think this is all - I may be wrong
global $vbulletin, $vbphrase, $db;

AdTheRat
09-19-2008, 07:01 AM
*facepalms*

Of course! So obvious now! The news class has no access to the $vbulletin class. Bad me! *slap head*

Ok, Error gone, and lacking news now! Ha! *tries things*

Thanks you Dismounted! ^_^

- Sorted and working! Woooooo!!