View Full Version : bb-codes on external page
burn4cid
11-23-2009, 10:44 AM
Hi,
Im making a site with a vbulletin forum attached, but topics for a specified forum are displayed on the site as news.
But i need a way to convert the BB-codes from the database.
Is there some sort of code of script i can use or can i attach a script forum vbulletin it self
Greetings burn
Something like this?
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$text = "some text with tags";
$html = $bbcode_parser->parse($text);
burn4cid
11-23-2009, 03:08 PM
i have this:
<?php
define('CWD', '/home/egconline/domains/xxx/public_html/forum');
include(CWD . '/global.php');
require_once(CWD . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_text = $parser->do_parse(viewrules(2322));
echo($parsed_text);
?>
viewrules(2322) = the function that gets the post text form the db
but then i recieve this error:
Fatal error: Call to a member function query_read_slave() on a non-object in /usr/home/egconline/domains/xxx/public_html/forum/includes/class_bbcode.php on line 208
Hmm...I tried this:
<?php
require_once('./global.php');
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$text = "some text with tags";
$html = $bbcode_parser->parse($text);
echo $html;
?>
In a .php file in the forum directory, but it only works when I'm logged in and the cookies have already been set.
Maybe someone else can tell us what's going on...
(stuff deleted because none of it made sense...)
burn4cid
11-23-2009, 04:08 PM
im not working in the same folder, and its not supposed to be logged in.
Im working form a other subdomain.
<?php
chdir('/home/egconline/domains/egc-online.com/public_html/forum');
include ('./global.php');
require_once (DIR . '/includes/class_bbcode.php');
chdir('/home/egconline/domains/egc-online.com/public_html/v2');
function maintext()
{
$bbcode_parser = &new vB_BbCodeParser($vbulletin, fetch_tag_list());
$text = viewrules(2322);
$html = $bbcode_parser->do_parse($text);
echo $html;
}
include ("template.php");
?>
gives the same problem
FWIW, my problem with not being logged in is fixed by calling "print_ouput" instead of "echo". I put my test program in another directory and added the chdir:
<?php
chdir('/home/???/forum');
require_once('./global.php');
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$text = "some text with tags";
$html = $bbcode_parser->parse($text);
print_output($html);
?>
Still works OK.
Maybe you just need a "global $vbulletin;" in your maintext()? (but you didn't have it in a function before, so maybe not...)
--------------- Added 1259002914 at 1259002914 ---------------
Something else that maybe should be mentioned (for future reference if not for burn4cid) - there are other php BBCode parsing functions available out there, if you don't need to specifically use the vBulletin codes.
burn4cid
11-23-2009, 08:06 PM
OMG you r right $vbulletin needs to be added global :D
ty
Citizen Bleys
04-15-2010, 08:29 AM
Hate to bump an old thread, but I'm in exactly the same boat. I want to pull posts from my vBulletin to my frontsite; the self-authored PHP script I'm using is in / and my vBulletin is in /forums/
I've already written all of the code necessary to display forum posts from my news forum as news updates, the only things that I haven't got working are parsing BB code and newlines and truncating long posts.
I've tried the code posted in this thread and a few other variants.
require_once(DIR . '/includes/class_bbcode.php');
says that /DIR/includes/class_bbcode.php does not exist. No, I did not enclose DIR in quotes. I've tried it both adding /forums to the beginning and chdir'ing to forums.
require_once('./includes/class_bbcode.php');
This at least finds the file (as does using the FQDN), if I chdir to my /forums directory (and hopefully remember to chdir back after!) -- BUT! all it does is throw up an error:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /(elided)/forums/includes/class_bbcode.php on line 166
include()ing global.php also throws an error:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /(elided)/forums/includes/class_bootstrap.php on line 26
An attempt to require_once class_bbcode in a global scope functions, but if I try to instantiate a new vB_BbCodeParser in a while loop, I get
Fatal error: Cannot instantiate non-existent class: vb_bbcodeparser in /(elided)/main.php on line 135
Marco van Herwaarden
04-15-2010, 11:35 AM
Start by checking the following 2 conditions:
- You must chdir() to the vBulletin installation directory before calling any of the vBulletin scripts.
- global.php should be the first to be included.
require_once(DIR . '/includes/class_bbcode.php');
says that /DIR/includes/class_bbcode.php does not exist. No, I did not enclose DIR in quotes. I've tried it both adding /forums to the beginning and chdir'ing to forums.
I think this is because 'DIR' is not defined, it's normally defined in includes/init.php. One of your errors is in class_bootstrap.php, are you working with a 4.0 version?
(ETA: I was in the middle of writing my post when Marco posted - you should probably just follow his instructions)
Citizen Bleys
04-15-2010, 09:12 PM
Some progress made.
Yeah, I'm working with 4.0; I found this thread via a search so I didn't notice what forum it was in. I was hoping to find my answer without posting, as I usually do on forums like this.
OK, so I included global.php at the start of the script. I've got chdir('forums') before the bbcode parsing loop and chdir('..') after it.
I think half my problem is that my host parses both PHP4 and PHP5 -- I had a .htaccess file in /forums that interpreted files ending in .php as PHP5, but in my / folder it was still being interpreted as PHP4. No wonder it didn't like vB4's PHP5 scripts.
Now I'm running into dependency issues that remind me of using RedHat. In 2001.
on attempt to instantiate a new vB_BbCodeParser, I get:
Fatal error: Call to a member function query_read_slave() on a non-object in /(elided)/forums/includes/class_bbcode.php on line 220
I tried a require_once on init.php but it didn't change anything.
Here's the full current code as it stands (global.php called in a different script which include()s this one)
/* 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
EDIT: Not sure if I should keep using this thread or repost the whole shebang in the right forum. ><
Marco van Herwaarden
04-16-2010, 08:56 AM
You should post in the correct forum.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.