Log in

View Full Version : I need help parsing BBCode


just.b.jealous
12-17-2010, 04:38 AM
I've made a custom page by making a new template called "TEST" then using the following PHP code:

<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE & ~8192);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test'); // change this depending on this files name
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('TEST',);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
eval('print_output("' . fetch_template('TEST') . '");');
?>

Saved it as "test.php",.. then view it to see whatever I put into the "TEST" template. Right now I have it pulling the most recent threads, posters name, date posted, and the contents of the post itself. Everything is working fine except the BBCode isn't being formatted after being pulled from the DB, can anybody help me figure this out, ??

Digital Jedi
12-17-2010, 06:43 PM
Did you ever make any of the edits PirdOPrey5 showed you in the thread where you initially asked this question?

just.b.jealous
12-19-2010, 09:58 PM
I have now, but I'm still stuck.....


You need to initialize and use the BB Code parser...
In the php file near the top add the lines:


require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($GLOBALS['vbulletin'], fetch_tag_list(),true);


Then you can use this line (change the $rawthread and $parsedthread variables to your needs) to get the parsed output (BB Code converted to HTML)

$parsedthread= $bbcode_parser->parse($rawthread ,'nonforum', true);

The "true" on the end is to parse smilies too... if you don't want smilies make it "false".

awesome, thanks for helping me out,.. I'm a little stuck at the moment though,.. could you take a look at my test.php page for me- it's still not parsing BBCode,..

<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE & ~8192);
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($GLOBALS['vbulletin'], fetch_tag_list(),true);
$parsedthread= $bbcode_parser->parse($rawthread ,'nonforum', true);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test'); // change this depending on this files name
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('TEST',);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
eval('print_output("' . fetch_template('TEST') . '");');
?>

Using:
require_once(DIR . '/includes/class_bbcode.php');
Gives me this error:
Warning: require_once(DIR/includes/class_bbcode.php) [function.require-once]: failed to open stream: No such file or directory in /forum/test.php on line 4
Fatal error: require_once() [function.require]: Failed opening required 'DIR/includes/class_bbcode.php' (include_path='.:/usr/local/php5/lib/php') in /forum/test.php on line 4

Using: require_once('./includes/class_bbcode.php');
Gives me this error:
Fatal error: Class 'vBulletinHook' not found in /forum/includes/class_bbcode.php on line 2463




I'm also a little confused on what to do with:
Then you can use this line (change the $rawthread and $parsedthread variables to your needs) to get the parsed output (BB Code converted to HTML)

kh99
12-19-2010, 10:11 PM
I think that stuff you added (starting with the require_once class_bbcode.php) needs to go below the require_once('./global.php');