Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2007, 04:47 PM
weicool weicool is offline
 
Join Date: Dec 2006
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Parsing BBCode to HTML

Hey everyone,

I'm currently pulling the latest posts from one of my forums directly from the database and putting it on my main site (non-vB).

However, unsurprisingly, there is a bunch of BBCode mixed within the text (the pagetext column of the post table). How can I parse this BBCode to return HTML? Which vB file must I include and which function should I use?
Reply With Quote
  #2  
Old 06-17-2007, 12:07 AM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This should be all you need;

PHP Code:
/*
Include and call the bbcode class
*/
require_once(DIR '/includes/class_bbcode.php');
$bbcode =& new vB_BbCodeParser($vbulletinfetch_tag_list());

/*
An example of using the class to parse data that contains bbcode
*/
$text 'Some text [b]with bbcode[/b] in it';

/* $forumid can be set to; 
- 'calendar' (follows bbcode rules for the calendar) 
- 'privatemessage' (follows bbcode rules for PMs) 
- 'usernote' (follows bbcode rules for usernotes)
- 'signature' (follows bbcode rules for signatures)
- 'nonforum' (follows "global" bbcode rules as defined in vBoptions)
- 'announcement' (follows bbcode rules for announcements)
- 'Any vaild forumid' (example; 1, 2, 17, etc).  Will follow bbcode rules for specified forumid.   The array "$forum" must be defined and the function "fetch_foruminfo" must be defined for this to work.
*/
$forumid 'nonforum'// just to make things simple..;0

$allowsmilie true// parse smilies? true = yes, false = no.

// ## The code below will convert the bbcode to html using the rules above.
$parsed_text $bbcode->parse($text$forumid$allowsmilie); 
Reply With Quote
  #3  
Old 06-17-2007, 06:31 AM
weicool weicool is offline
 
Join Date: Dec 2006
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Brad View Post
This should be all you need;

PHP Code:
/*
Include and call the bbcode class
*/
require_once(DIR '/includes/class_bbcode.php');
$bbcode =& new vB_BbCodeParser($vbulletinfetch_tag_list());

/*
An example of using the class to parse data that contains bbcode
*/
$text 'Some text [b]with bbcode[/b] in it';

/* $forumid can be set to; 
- 'calendar' (follows bbcode rules for the calendar) 
- 'privatemessage' (follows bbcode rules for PMs) 
- 'usernote' (follows bbcode rules for usernotes)
- 'signature' (follows bbcode rules for signatures)
- 'nonforum' (follows "global" bbcode rules as defined in vBoptions)
- 'announcement' (follows bbcode rules for announcements)
- 'Any vaild forumid' (example; 1, 2, 17, etc).  Will follow bbcode rules for specified forumid.   The array "$forum" must be defined and the function "fetch_foruminfo" must be defined for this to work.
*/
$forumid 'nonforum'// just to make things simple..;0

$allowsmilie true// parse smilies? true = yes, false = no.

// ## The code below will convert the bbcode to html using the rules above.
$parsed_text $bbcode->parse($text$forumid$allowsmilie); 
Thanks a lot!

However, when I tried to do that, I get this error message:

Fatal error: Class 'vBulletinHook' not found in /mnt/w0800/d09/s41/b027ae64/www/forums/includes/class_bbcode.php on line 2347

Looking at the code in class_bbcode.php, it seems to abruptly call on a vBulletinHook without ever declaring it. I'm very new to PHP...

What would be the problem here?
Reply With Quote
  #4  
Old 06-17-2007, 06:52 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'll need to have this above that code:
PHP Code:
$curdir cwd();
chdir('./PATH/TO/FORUMS/');
require_once(
'./global.php');
chdir($curdir); 
Reply With Quote
  #5  
Old 06-17-2007, 04:49 PM
weicool weicool is offline
 
Join Date: Dec 2006
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Almost seems to work...but still a little error:

$bbcode =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

That line seems to be problematic.

I get the following error message:

Fatal error: Call to a member function query_read_slave() on a non-object in /mnt/w0800/d09/s41/b027ae64/www/forums/includes/class_bbcode.php on line 198
Reply With Quote
  #6  
Old 06-18-2007, 06:25 PM
weicool weicool is offline
 
Join Date: Dec 2006
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can someone please give me the last bit of information I need to get this thing working...?
Reply With Quote
  #7  
Old 09-03-2007, 01:23 AM
Augusto Augusto is offline
 
Join Date: Dec 2006
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

here's a working sample of it that works in the forum installation directory:

PHP Code:
<?php

require_once('global.php');
require_once(
'includes/class_bbcode.php');
$bbcode =& new vB_BbCodeParser($vbulletinfetch_tag_list()); // call the bbcode class
$text 'Some text [b]with bbcode[/b] in it';  // data that contains bbcode
$forumid 'nonforum'// (follows "global" bbcode rules as defined in vBoptions)
$allowsmilie true// parse smilies? true = yes, false = no.
$parsed_text $bbcode->parse($text$forumid$allowsmilie);  // Parse the text
echo("<html>");
echo(
$parsed_text);
echo(
"</html>");

?>
save it as "testparser.php" and simply run it in your forum installation directory as www.yourforum.com/forum/testparser.php

it should print this: "Some text with bbcode in it"
Reply With Quote
  #8  
Old 09-05-2007, 09:30 AM
XManuX XManuX is offline
 
Join Date: Feb 2007
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm having exactly the same error message :

Fatal error: Call to a member function on a non-object in /path/class_bbcode.php on line 198

I'm trying to acheive the same thing : parsing bbcodes in posts that i am currently displaying outside the forum (non-vb.)

my code is :
PHP Code:
$cwd getcwd();
$vbpath $_SERVER['DOCUMENT_ROOT'] . get_option('vbb_VBRPATH');
chdir($vbpath);
require_once(
'./global.php');
chdir($cwd);
require_once(
$vbpath '/includes/class_bbcode.php'); 
$bbcode =& new vB_BbCodeParser($vbulletinfetch_tag_list()); 
no errors displayed since i added the last line

@Augusto : i tried your test successfully.
Reply With Quote
  #9  
Old 11-09-2007, 02:39 AM
dolbex dolbex is offline
 
Join Date: Aug 2005
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am still having a really tough time with pulling this off in 3.6. I continue to get the error:

Fatal error: Call to a member function query_read_slave() on a non-object in /var/www/newspail3/forums/includes/class_bbcode.php on line 213

from outside the forum directory.

--------------- Added [DATE]1194608789[/DATE] at [TIME]1194608789[/TIME] ---------------

Figured this out.

I had these examples embedded within functions. I don't quite understand why they wouldn't work but I assigned $bbcode when I was inside my forum directory

PHP Code:
chdir(FORUM_DIRECTORY);
require_once(
FORUM_DIRECTORY 'global.php');
require_once(
FORUM_DIRECTORY 'includes/class_bbcode.php');
$bbcode =& new vB_BbCodeParser($vbulletinfetch_tag_list());
chdir ($curdir); 
I then passed $bbcode into the function and that worked.
Reply With Quote
  #10  
Old 06-09-2009, 04:16 AM
jonbach jonbach is offline
 
Join Date: Nov 2008
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I can confirm the last post. This method does not work when part of a function, which is a big problem when integrating into some existing sites.

This works:
PHP Code:
$cwd getcwd();
chdir("/mypath");
include(
"/mypath/global.php"); 
include(
"/mypath/includes/class_bbcode.php"); 
$bb_parser =& new vB_BbCodeParser($vbulletinfetch_tag_list()); 
chdir($cwd);

function 
bb_convert_works($bb_parser$text){
    
$parsed_text $bb_parser->do_parse($text); 
    return 
$parsed_text;
}

$text "[url=http://www.google.com][b]Google[/b][/url]"
echo 
bb_convert_works($bb_parser$text); 
This does NOT work:
PHP Code:
function bb_convert_doesnt_work($text){
    
$cwd getcwd();
    
chdir("/mypath");
    include(
"/mypath/global.php"); 
    include(
"/mypath/includes/class_bbcode.php"); 
    
$bb_parser =& new vB_BbCodeParser($vbulletinfetch_tag_list()); 
    
chdir($cwd);
    
$parsed_text $bb_parser->do_parse($text); 
    return 
$parsed_text;
}

$text "[url=http://www.google.com][b]Google[/b][/url]"
echo 
bb_convert_doesnt_work($text); 
The errors I get when I try the second code are:
Quote:
Warning: array_keys() [function.array-keys]: The first argument should be an array in [path]/includes/functions.php on line 4227

Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 4227

Fatal error: Call to a member function query_read_slave() on a non-object in /mypath/includes/functions.php on line 3189
I have plenty of experience in PHP, but I haven't encountered a problem like this before. I really would prefer to not have to hack this together by hard coding the conversion code everywhere I need it. Does anyone have any ideas on why it breaks when within a function?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11147 seconds
  • Memory Usage 2,293KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete