Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles

Reply
 
Thread Tools
Parse BBCode (in 3.5)
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 06-07-2005, 10:00 PM

If you want to parse BBCodes somewhere in your hacks/scripts (assuming that global.php is already required):

PHP Code:
require_once(DIR '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
$parsed_text $parser->do_parse($text$do_html$do_smilies$do_bbcode$do_imgcode$do_nl2br$cachable); 
The parameters for method do_parse() are:
  • $text = Text to be parsed
  • $do_html = Whether to allow HTML or not (Default = false)
  • $do_smilies = Whether to parse smilies or not (Default = true)
  • $do_bbcode = Whether to parse BB code (Default = true)
  • $do_imgcode = Whether to parse the [img] BB code or not, independant of $do_bbcode (Default = true)
  • $do_nl2br = Whether to automatically replace new lines with HTML line breaks or not (Default = true)
    This should be set to false if you allow HTML.
  • $cachable = Whether the post text is cachable or not (Default = false)

All parameters except $text can be omitted and will use the defaults then.
Reply With Quote
  #42  
Old 03-15-2006, 10:11 PM
DrewM DrewM is offline
 
Join Date: Oct 2005
Posts: 564
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bump
Reply With Quote
  #43  
Old 03-17-2006, 02:54 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1) This not the place to ask question
2) Where do you set any values to $do_html, $do_smilies, $do_bbcode, $do_imgcode, $do_nl2br, $cachable
?
Reply With Quote
  #44  
Old 03-27-2006, 01:42 PM
STGU_daNo STGU_daNo is offline
 
Join Date: Jul 2004
Location: Winnipeg, MB, Canada
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is a question that is relevant to the thread:

Does the bbcode parser remove unwanted text, like if someone were to try submitting sql code? If not, what function removes code such as that? Is it simply addslashes?

I have an app that gets user text and stores it in the database, and I would like to be cautious and remove any possible threats to the system. I had put it in this thread but I have not had a response yet ... any help would be appreciated.
Reply With Quote
  #45  
Old 03-27-2006, 02:02 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Class vB_Input_Cleaner is what you want to have a look at.
Reply With Quote
  #46  
Old 05-05-2006, 01:34 PM
Dot50Cal Dot50Cal is offline
 
Join Date: Sep 2005
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, Andreas or someone else maybe? I just finished porting a plugin which was very vital to my site after 3 days. I didnt know any php or sql before doing this so thats what took me so long. It took a whole lot of trial and error.

Basically the plugin Im using is PluhNews. I've converted it to work with Vbulletin 3.5, as its been broken ever since 3.0 came out. Anyway, I've now run into a slight snag. I dont know jack squat about parsing VB code. The way this plugin works is, it rips posts from a specified forum and displays them on a non forum page. Essentially a news ripper.

So as you can see here - http://www.thehorrorisalive.com none of the VB code is being parsed, and rightfully so because I have NO idea how to impliment your code here. Right now Im using the following code to display the posts content

PHP Code:
while ($row mysql_fetch_array($sql_result2)) { 
   
$pagetext $row["pagetext"]; 
So wherever I want the post to be put, I put $pagetext.

Im assuming I need to somehow bind your command to run after pagetext, but being a newbie to php and sql I have no clue on how to do that and every attempt has ended in failure. This is probably a really simple request, and Id appreciate it if anyone who could answer it helps me out. As soon as its done Ill release the upgraded hack, since a lot of people still would like to use PluhNews.

Besides that I have a small infinite loop whenver I try to include global.php, which Im still hunting for. So any help is greatly appreciated.
Reply With Quote
  #47  
Old 05-05-2006, 08:43 PM
Aesma Deva Aesma Deva is offline
 
Join Date: Feb 2006
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try changing this:
PHP Code:
while ($row mysql_fetch_array($sql_result2)) {  
   
$pagetext $row["pagetext"]; 
To this:
PHP Code:
require_once(DIR '/includes/class_bbcode.php'); 
$parser =& new vB_BbCodeParser($vbulletinfetch_tag_list());
while (
$row mysql_fetch_array($sql_result2)) {  
   
$pagetext $parser->do_parse($row["pagetext"], falsetruetruetruetruefalse); 
(you can change the do_parse()'s arguments depending on what you want to parse, if you use it as I posted it now, HTML wouldn't be parsed, and smilies, BB code and the img BB code would be parsed)
I didn't understand your problem including global.php, though since it's a plugin and not an entirely new .php file, global.php should have already been included/requested.
Reply With Quote
  #48  
Old 05-09-2006, 09:34 PM
Dot50Cal Dot50Cal is offline
 
Join Date: Sep 2005
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Aesma, thank you very much! That solves my problem with my QUOTE tags not being translated to html! However I still have a serious error somewhere. You can see the page here
EDIT: FIXED!! WOO HOO!!!!
Reply With Quote
  #49  
Old 05-17-2006, 01:10 AM
aridha aridha is offline
 
Join Date: Jan 2005
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have used the same code and every thing is fine exept the QUOTE tags
Reply With Quote
  #50  
Old 06-29-2006, 10:39 PM
linc_ linc_ is offline
 
Join Date: Jun 2006
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there any way to define the HTML the parser will output to something else than the forum is using? For instance, to remove the "target="_blank"" from [url]'s and change the HTML that [QUOTE] is producing?
Reply With Quote
  #51  
Old 08-13-2006, 02:25 PM
rogersnm rogersnm is offline
 
Join Date: Apr 2006
Location: Cyberspace, UK
Posts: 729
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

After it goes through the bbcode parser it should be <a href="link" target="_blank">text</a> instead of text. So you should be able to do a str replace to remove it.
Reply With Quote
Reply

Thread Tools

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 11:53 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09628 seconds
  • Memory Usage 2,305KB
  • Queries Executed 25 (?)
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
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (1)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • 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