View Full Version : Parse BBCode (in 3.5)
Andreas
08 Jun 2005, 20:10
If you want to parse BBCodes somewhere in your hacks/scripts (assuming that global.php is already required):
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
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.
VBCoder
16 Jun 2005, 04:40
Can this only be used to go from BBCode --> HTML? Or can it also go from HTML --> BBCode?
Andreas
16 Jun 2005, 04:43
Yes, Class vB_CodeParser can only be userd for BBCode -> HTML.
For limited HTML -> BBCode use convert_wysiwyg_html_to_bbcode() in functions_wysiwyg.php
VBCoder
16 Jun 2005, 14:44
Kirby,
Thanks. I've noticed that convert_ can handle < and > properly, but leaves " as " - not " . Any ideas?
How can I do this in vB 3.0.7?
Could this be used to fix the /me problem in quotes for 3.5 RC 1?
Search is my friend.
Thanks for posting this, was looking for a hint and this saved me lots of time.
chanzero
11 Aug 2005, 05:32
help for a noob please :) if i have the following...
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
if i understand what this code does, i should get back something like this:
parsed text = My Review! (http://www.mysite.com/reviews.php?id=4661)
but i just get
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Ky Kiske
11 Aug 2005, 06:57
How do you do this if it's like forum.yoursite.com? And that directory has a password?
chanzero
30 Aug 2005, 18:44
help for a noob please :) if i have the following...
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
if i understand what this code does, i should get back something like this:
parsed text = My Review! (http://www.mysite.com/reviews.php?id=4661)
but i just get
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
i should note that kirby helped me figure this out by pointing out that i did not definie $do_html, $do_smilies, $do_bbcode, $do_imgcode, etc
thanks kirby!
And how do you define them? ;)
KingSpade
14 Sep 2005, 06:11
And how do you define them? ;)
I must be missing something because I've yet to get this to work for me :). I've got the following and I've tried just about all that I can and nothing is working for me. If anyone could help, I'd appreciate it very much.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Brinnie
19 Sep 2005, 19:05
Kirby, how would one go about adding this to the FAQ manager?
CapinPete
01 Oct 2005, 03:14
In my case I had to use the following code:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
I am pretty much a php noob and it took me a good hour to figure this out. I guess its because I declared the parser as an object at the beginning of the script. I am using a function that gets the last 10 posts in a forum and displays it as HTML for use on the homepage. As we all SHOULD know, php requires that you declare a variable "global" if its outside your function.
Man1c M0g
10 Oct 2005, 22:52
Well, I've fiddled with all the suggestions here for the last 2 hours and I still can't get anything to work! Here's the errors I get:
Fatal error: Call to a member function on a non-object in /home/httpd/vhosts/biorust.com/subdomains/forums/httpdocs/includes/class_bbcode.php on line 181
Fatal error: Call to a member function on a non-object in /home/httpd/vhosts/biorust.com/subdomains/forums/httpdocs/includes/functions.php on line 4308
Andreas
10 Oct 2005, 23:00
Wrong Thread.
Please post a new Thread in vB 3.5 Modification Questions and attach the Code you are using.
These errors mean that the vBulletin Registry Object ($vbulletin) does not have a valid reference for the database object.
Man1c M0g
10 Oct 2005, 23:09
Wrong Thread.
Please post a new Thread in vB 3.5 Modification Questions and attach the Code you are using.
These errors mean the the vBulletin Registry Object ($vbulletin) does not have a valid reference for the database object.
Actually... what you just said goes a long way towards solving the problem! Thanks! :D
CommuneZoom
19 Oct 2005, 18:57
Actually... what you just said goes a long way towards solving the problem! Thanks! :D
Something small I noticed, which is probably more than obvious for those more experienced, although unless I specifically define true or false in the parse line, it will not convert the BBCode.
It will not parse simply by including the variables.
MetalAges
20 Oct 2005, 19:28
I'm trying to get an index page (www.ultimatemetal.com) to work with the same code I used to have. It worked fine in 3.0.7 . The only issue is the bbcode stuff (which is why I am in this thread :) ). I exchanged the code I had:
require_once('includes/functions_bbcodeparse.php');
with the code at the beginning of this post:
require_once('includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_text = $parser->do_parse($text, $do_html, $do_smilies, $do_bbcode, $do_imgcode, $do_nl2br, $cachable);;
I get this same error message with both:
Fatal error: Call to undefined function: parse_bbcode() in /home/mahke/public_html/index-test.php on line 32
Line 32 is: $articlelength1 = parse_bbcode($articles['pagetext']);
Am I brainfarting on something here?
i should note that kirby helped me figure this out by pointing out that i did not definie $do_html, $do_smilies, $do_bbcode, $do_imgcode, etc
thanks kirby!
Maybe this is my issue? Chanzero or anyone else, can you elaborate on how to define this properly?
Andreas
20 Oct 2005, 21:30
Well, the parse_bbcode() call needs to be $parser->do_parse() instead :)
MetalAges
20 Oct 2005, 21:32
Excellent! works....still in the middle of learning all this code so, I thank you for the help! :)
donBLACK
21 Oct 2005, 04:18
can this be used to allow bb code in custom titles?
nvm i got it
SilverDawn
23 Oct 2005, 03:42
nm I got it! Thanks so much!
Oreamnos
06 Nov 2005, 03:50
What do i need to do to make it turn non-bbcoded url's into links (like what vb does when you just type a url into the post without using bbcode)?
noonespecial
11 Nov 2005, 22:04
I've been trying to get this to work in the member.php file so that bbcode will be parsed for user profiles --
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Just isn't working though.
noonespecial
21 Nov 2005, 02:35
Help???
Oreamnos
21 Nov 2005, 02:47
Help???
are you getting any errors?
are you sure the profile fields have things to be parsed?
are the things you are trying to parse being excluded by a 'false' default setting of the function?
noonespecial
21 Nov 2005, 07:21
are you getting any errors?
are you sure the profile fields have things to be parsed?
are the things you are trying to parse being excluded by a 'false' default setting of the function?
No errors.
Yah, it just comes out as the text with bbcode showing.
Not that I know of... the code above is what I'm using and all I want is for BBcode to work for a custom profile field.
Oreamnos
21 Nov 2005, 08:08
Try this:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
if this doesn't work, then i have to imagine you are passing the wrong value to the function, ie. $profilefield['value']
noonespecial
21 Nov 2005, 08:48
Try this:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
if this doesn't work, then i have to imagine you are passing the wrong value to the function, ie. $profilefield['value']
Nope, didn't work. I assumed it was that value because of this thread: http://www.vbulletin.org/forum/showthread.php?t=70962&highlight=bbcode+profile
I know that's 3.0, so maybe it's changed? Does anyone know the correct syntax for me? I just need BBcode to be parsed in custom profile field 27.
noonespecial
26 Nov 2005, 08:01
Someone, anyone, PLEASE help ....
Andreas
27 Nov 2005, 01:32
I've been trying to get this to work in the member.php file so that bbcode will be parsed for user profiles --
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Just isn't working though.
Works fine. Though, for performance reasons I would split it into 2 Plugins.
Kristoph
27 Nov 2005, 14:35
just a quick one... got this working great for including posts on my front page, but it is trying to find the smilies in /images/smilies, when infact they're in /community/images/smilies....
is there a quick fix around this built into the vbcodeparser class? or should I just use str_replace on the outputted string?
cheers!
noonespecial
08 Dec 2005, 07:07
Anyone know any way to parse $thread[preview] - I can't figure out where or how to do it for the life of me. It's in functions_forumdisplay.php ..
Found it. Much easier then I thought.
Ratchet
14 Dec 2005, 20:45
just a quick one... got this working great for including posts on my front page, but it is trying to find the smilies in /images/smilies, when infact they're in /community/images/smilies....
is there a quick fix around this built into the vbcodeparser class? or should I just use str_replace on the outputted string?
cheers!
I just used str_replace as you mentioned. Seemed easy. Something like this should work:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
As an aside, I couldn't get this code working either until I replaced do_parse() with parse(). Dunno what the difference is.
ericgtr
15 Dec 2005, 18:49
I have a custom bbcode which shows an inline media player. I have struggled with this for hours but cannot come up with a solution to make it so only registered members can see it. All I really need is to prevent guest from viewing it.
SHANE-D-PAIN
07 Jan 2006, 09:17
This is so frustrating. I am trying to create a plugin that will parse html in certain userinfo fields.
So far I have this as a plugin in member_complete:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Any ideas?
Oreamnos
08 Jan 2006, 09:59
This is so frustrating. I am trying to create a plugin that will parse html in certain userinfo fields.
So far I have this as a plugin in member_complete:
Any ideas?
this might help: http://www.vbulletin.org/forum/showthread.php?t=103460
bigtime
17 Jan 2006, 21:10
Hi,
The following code will display posts on a non forum page in the home directory. However, when I try to parse the bbcode it doesn't work.
Any ideas?
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Why won't this work I'm trying to make it parse my page stuff it's loading it form the db and it just won't parse my php code is:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Andreas
17 Mar 2006, 04:54
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
?
STGU_daNo
27 Mar 2006, 15:42
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 (http://www.vbulletin.org/forum/showthread.php?p=931847) but I have not had a response yet ... any help would be appreciated.
Andreas
27 Mar 2006, 16:02
Class vB_Input_Cleaner is what you want to have a look at.
Dot50Cal
05 May 2006, 15:34
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
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
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.
Aesma Deva
05 May 2006, 22:43
Try changing this:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
To this:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
(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.
Dot50Cal
09 May 2006, 23:34
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!!!!
I have used the same code and every thing is fine exept the QUOTE tags
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?
rogersnm
13 Aug 2006, 16:25
After it goes through the bbcode parser it should be <a href="link" target="_blank">text</a> instead of text (link). So you should be able to do a str replace to remove it.
harmor19
14 Aug 2006, 23:15
I liked to turn off the bbcode and have any bbcode stripped from the text.
I know how to turn off bbcode but how do I strip it?
bigtime
17 Sep 2006, 21:41
Hi,
Using 3.6.1 and trying to parse bbcode on a non-vb page at the bottom of http://www.defend.net.
Could someone please let me know how to correct this code so that the bbcode will be parsed? I read this thread and tried some things but couldn't get it working.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Hi,
I am trying hard as well to include custom BB tags I have created myself but no go. The do_parse function will not include it as hard as I try. Same with Quotes, they are not being parsed at all. Did I miss a command somewhere?
I have this initially:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
IMG does get parsed but so far Quotes and any custom BB codes do not.
Thanks for any help in advance
peterska2
06 Dec 2006, 17:17
If you require assistance with some code that you are writing, please use the programming discussions forum.
Thank you.
keithsl
16 Jan 2007, 05:52
I'm using this same code and I'm having some problems with Japanese text. I made a separate thread about it: http://www.vbulletin.org/forum/showthread.php?t=136248
You guys rock. Thanks so much for sharing this information.
Steve M
13 Mar 2008, 21:38
Ok my turn for help:
This is my code:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Trying to get bbcoder for stickied threads to parse but it won't parse. If I change it any other way than it is now, it will make the sticky threads vanish.
Thanks
Steve
Opserty
13 Mar 2008, 23:32
Ok my turn for help:
This is my code:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Trying to get bbcoder for stickied threads to parse but it won't parse. If I change it any other way than it is now, it will make the sticky threads vanish.
Thanks
Steve
You need to find where the threadbit template is evaluated for stickied threads, ensure this code is placed just before it, also remove the last line, I don' think you need it.
In 3.7.x, I got every phrased, except the smiles, even though I pass "true" through:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
"allowsmilie" does equal 1.
Steve M
15 Mar 2008, 06:18
Opserty, thanks, I'll give it a go later.
--------------- Added 1205610787 at 1205610787 ---------------
Opserty: Tried that, makes all the sticky's vanish. So I'm not too sure, gonna keep playing with it and hope I figure it out.
hellbringer80
05 Sep 2008, 05:53
Wow great man, thanks, very useful!
i want to use a script outside of the folder where the forum is installed, but when i include the global.php with "require_once('forum/global.php');" the my script doesn't works anymore..?
Do i need to include anything else which has the reference to the folder or so?
(when i put my script in the forum folder is seems to work fine)
BlackxRam
12 Oct 2008, 12:52
in 3.6 how can I get BBcode and Line Breaks to work properly in the Profile Pages? Especially in Custom Fields?
MTGDarkness
28 Feb 2009, 11:27
Two questions.
1. Does this work with 3.7.x?
2. What's the right syntax to make $text the combination of three variables? I have this right now:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
And in the postbit template, I intend to use a conditional to replace $message with $parsed_text if both fields are filled in. However, the message comes up as blank. I checked the source code and came up with just the start of the post div. I'm guessing it's because my syntax is wrong; specifically
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Fox Mc Cloud
21 Nov 2009, 12:48
If you want to parse BBCodes somewhere in your hacks/scripts (assuming that global.php is already required):
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
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.
Thanks, that was what I needed :D
vBulletin® v3.6.12, Copyright ©2000-2012, Jelsoft Enterprises Ltd.