Originally taken up in a
borrowed thread
Basics: I want to write a script that copies the text of threads from my news forum to my front site. I've hand-coded a mostly-working script from scratch, but I have no idea how to parse BBCodes, so any multiline news posts or posts that contain BBCodes show up as a giant mishmash on the front site.
My front site is in / and the forums are in /forums/, so I have to chdir() into forums and back whenever I want to call any vBulletin functionality. Having searched the forums, I've seen code that looks like this:
PHP Code:
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$text = "[color=red]some text with tags[/color]";
$html = $bbcode_parser->parse($text);
(example lifted directly from the other thread)
Problem is, it doesn't work.
The other thread in the vB3 forum solved most of the initial issues I had, so I'll leave them out, but now I'm running into some dependency problems. I'm not all that familiar with the internal workings of vBulletin--for that matter, OOP in general is not my forte--so I don't know what classes/methods/functions are where.
Here's my current code:
PHP Code:
/* Save the old version */
//echo "<p>".$news_threads[$counter]["postbody"]."</p>";
/**/
//attempting to do it with bbcode parser
// global $vbulletin; // declared in index.php
chdir('forums');
//require_once('./global.php');
//require_once('./includes/init.php'); //uncommenting this line changes nothing
require_once('./includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list()); // I don't understand this line at all, just copied it from the forums
// next 2 lines currently commented out, which is how I determined where the problem lies, but they should work
$parsedNews = $bbcode_parser->do_parse($news_threads[$counter]["postbody"]);
echo "<p>$parsedNews</p>";
chdir('..');
//end attempt to do it with bbcode parser
$news_threads[$counter]["postbody"] is a vanilla associative array containing the text of the first post of each thread in the news forum exactly as entered by the user, complete with all BBCodes and whitespace. I didn't use any vBulletin code to pull the data from the db, it's all handcoded, but it works -- it just doesn't display right as HTML because the whitespace is ignored and BBCodes aren't parsed.
With that code in the while loop, I get the following error:
Code:
Fatal error: Call to a member function query_read_slave() on a non-object in /(elided)/forums/includes/class_bbcode.php on line 220
The error (and the body of the post) disappears if I comment out the line instantiating the new vB_BbcodeParser.
If it matters, the basic structure of my frontsite is as follows
frontconfig.php: contains global variables for my code -- nothing relating to vBulletin
index.php: Shell HTML page containing the CSS and basic table structure -- a vanilla site with a sidebar containing links and a main page body containing news posts
sidebar.php: Links, inserted into index.php with an include() statement
main.php: contains some static HTML and my news script.
/forums/global.php is include()d at the top of index.php; since main.php is called only from within index.php, it should always include global.php. There's also a "global vbulletin;" statement in index.php which should likewise be inherited into main.