parsing bbcode

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
Spivester
Registered User
Posts: 18
Joined: Mon Jan 17, 2005 4:27 pm
Location: Canada
Contact:

parsing bbcode

Post by Spivester » Wed May 23, 2007 2:59 pm

Hello,

I'm wondering if anyone can assist on this... In phpbb2 I was able to parse bbcode to html for use outside the forums.. ie a news page. In phpbb3 it appears to be different. I have this so far...

Code: Select all

require_once('forums/includes/functions.php');
require_once('forums/includes/functions_display.php'); 

$i = 0;
while ($i < $news_number) {
	$query="SELECT * FROM phpbb_posts WHERE post_id = $post_number[$i]";
	$result=mysql_query($query) or die('Query failed: ' . mysql_error());;

	$post_info = mysql_fetch_array($result, MYSQL_ASSOC);
	$post_subject[$i] = $post_info['post_subject'];
	$post_text[$i] = $post_info['post_text'];
	$this_uid[$i] = $post_info['bbcode_uid'];
	$this_bitfield[$i] = $post_info['bbcode_bitfield'];
	$enablebbcode[$i] = $post_info['enable_bbcode'];
	$enablesmiles[$i] = $post_info['enable_smiles'];
	$enablemagic[$i] = $post_info['enable_magic_url'];
	$i++;
}

$flags = (($enablebbcode[$i]) ? 1 : 0) + (($enablesmiles[$i]) ? 2 : 0) + (($enablemagic[$i]) ? 4 : 0);
$post_text[$i] = generate_text_for_display($post_text[$i], $this_uid[$i], $this_bitfield[$i], $flags);
This code outputs the text fine.... except it is totally removing bbcode from the $post_text[$i]. I have no errors... and I think it's quite close to working as the generate_text_for_display function found in "functions.php" appears to be replacing bbcode with nothing or removing it from the post altogether.

Can anyone help with this? Cheers ;)

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: parsing bbcode

Post by igorw » Wed May 23, 2007 4:51 pm

Here's how you parse BBCode in phpBB3:

Code: Select all

            $message = censor_text($row['post_text']);
            $bbcode_options = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
            $message = generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $bbcode_options);
            $message = str_replace("\n", '<br />', $message); 
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

User avatar
Spivester
Registered User
Posts: 18
Joined: Mon Jan 17, 2005 4:27 pm
Location: Canada
Contact:

Re: parsing bbcode

Post by Spivester » Wed May 23, 2007 8:36 pm

No joy for me. I still get blanks where there should be some bbcode.

I checked my variables and enable_bbcode, enable_smilies and enable_magic_url are all "1" in the posts I'm trying to parse. I get a bbcode_uid and a bbcode_bitfield for almost all the posts and the $bbcode_options variable ends up equalling "5".

Can you think of why bbcode would be removed rather than parsed to html? Does the bbcode template play a part in this?

Thanks for your help up to now.. cheers.

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: parsing bbcode

Post by christhatsme » Wed May 23, 2007 8:48 pm

was it inserted correctly?
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

User avatar
Spivester
Registered User
Posts: 18
Joined: Mon Jan 17, 2005 4:27 pm
Location: Canada
Contact:

Re: parsing bbcode

Post by Spivester » Tue May 29, 2007 4:45 pm

I assume it was inserted properly... it shows up fine in the actual forums. Its only when I run it through the parser... it comes out blank.

User avatar
RogueKamikazee
Registered User
Posts: 5
Joined: Sun Oct 29, 2006 8:02 pm
Contact:

Re: parsing bbcode

Post by RogueKamikazee » Wed Jun 27, 2007 1:23 am

Scenario: I'm currently re-writing a shoutbox I implemented into my v2 forums. Now converting it to v3 except im having trouble converting bbcodes.

Question: How do i take a message " [bbcode]some text[/bbcode] smilie " and get the the display output? I'm currently using

Code: Select all

$message_parser = new parse_message();
$message_parser->message = $shoutbox_text;
$message_parser->parse(true,false,true,false,false,false,false,true);
$shoutbox_text = $message_parser->message;
Which gives me the smiles and bbcode as [bbcode:bbcode_ui] , but i need the html output.

I'll have a look at what's in the dev Ajax shoutbox for an option, but advice would be appreicated.
Insanity is often the logic of an accurate mind overtasked

T50
Registered User
Posts: 333
Joined: Mon May 07, 2007 11:51 pm
Contact:

Re: parsing bbcode

Post by T50 » Wed Jun 27, 2007 2:52 am

suggestion to author,

Add another page to phpbb3 and use phpbb's bbcode system from that!
Free Webhosting with option of getting paid plan <-- No Ads, No Pop-ups, Absolutely free/ or use promo code T50 to get a 10% discount on paid plan!
Make a few $$ in under a few minutes, easy to do

Webmaster of a Northeast Wisconsin Boy Scout Troop Website, http://bsat50.info

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25230
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: parsing bbcode

Post by Paul » Wed Jun 27, 2007 8:01 am

RogueKamikazee wrote:Scenario: I'm currently re-writing a shoutbox I implemented into my v2 forums. Now converting it to v3 except im having trouble converting bbcodes.

Question: How do i take a message " [bbcode]some text[/bbcode] smilie " and get the the display output? I'm currently using

Code: Select all

$message_parser = new parse_message();
$message_parser->message = $shoutbox_text;
$message_parser->parse(true,false,true,false,false,false,false,true);
$shoutbox_text = $message_parser->message;
Which gives me the smiles and bbcode as [bbcode:bbcode_ui] , but i need the html output.

I'll have a look at what's in the dev Ajax shoutbox for an option, but advice would be appreicated.
http://www.phpbb.com/mods/documentation ... ting-posts there is a instruction how you can use the generate function, use them :)
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

Locked

Return to “[3.0.x] MOD Writers Discussion”