Adapting bbcode to non-topic content

Discussion forum for MOD Writers regarding MOD Development.
Locked
schwim
Registered User
Posts: 147
Joined: Sat Jun 04, 2005 8:03 am

Adapting bbcode to non-topic content

Post by schwim »

Hi there everyone!

I'm trying to implement bbcode parsing in my phpBB3 session integrated site. I would like to use it in a comments system as well as a document viewing system, both of which will utilize the standard bbcodes. I'm using the wiki page as a guideline:

https://wiki.phpbb.com/Practical.Displa ... rnal_pages

The issue I ran into is that I don't know what to do with bitfield and uid.

I've included the two files:

Code: Select all

include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
And I've gotten stuck at this part:

Code: Select all

		$bbcode = new bbcode(base64_encode($bbcode_bitfield));         
		$bbcode->bbcode_second_pass($doc_body, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield'])
1) Can someone tell me what I need to do to have a $bbcode_bitfield for the document or comment?

2) Each document has a unique ID, can I use that for bbcode_uid?

Any help would be greatly appreciated!
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Adapting bbcode to non-topic content

Post by AmigoJack »

schwim wrote:$bbcode_bitfield
That's a collection of bits (in other languages known as flags) for saving post settings, like: "Do not automatically parse URLs", "Disable smilies", "Disable BBCode" and so on. For each post these options must be saved separately. And if you want to use BBCodes I suggest doing the same, because sooner or later you definitly want one setting to change.
schwim wrote:bbcode_uid
This is rendered by the class parse_message and used to later distinguish BBCodes from BBCode-look-alikes. Just have a look on how posts are stored in the database table: it's not the same what users entered, but a pre-parsed format. Which is made for performance reasons, so everytime you want to display it you don't have to do every step of parsing again.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
schwim
Registered User
Posts: 147
Joined: Sat Jun 04, 2005 8:03 am

Re: Adapting bbcode to non-topic content

Post by schwim »

Hi there AmigoJack and thanks so much for your help!

So, looking at the phpBB code, it looks like I need to take care of things on the posting side. I see I need to include a few more files:

Code: Select all

include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
And run it though the parser?

Code: Select all

$message_parser = new parse_message();
$message_parser->message = $doc_body;
$doc_body = $message_parser->message;
$doc_bitfield = $message_parser->bbcode_bitfield;
$doc_uid = $message_parser->bbcode_uid;
Would that suffice on the submission end of things or am I way off base?
User avatar
T0ny
Registered User
Posts: 1383
Joined: Sun Jan 29, 2006 8:42 pm
Location: Lancashire
Name: Tony

Re: Adapting bbcode to non-topic content

Post by T0ny »

Here's a quick example of using the generate_text_* functions in phpBB

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

//---

$doc_body = ' [b]bold text[/b] , [i]some italic text[/i] , [email protected]';

echo($doc_body . '<br><br>');

// first step (the 3 trues are : allow_bbcode, allow_urls, allow_smilies)
$bbcode_uid = $bbcode_bitfield = $flags = '';
generate_text_for_storage($doc_body, $bbcode_uid, $bbcode_bitfield, $flags, true, true, true);

// then store these 3 vars in the database
echo('$doc_body : ' . $doc_body . '<br>');
echo('$bbcode_uid : ' . $bbcode_uid . '<br>');
echo('$bbcode_bitfield : ' . $bbcode_bitfield . '<br><br>');


// then later, when you want to display the text, retrieve the 3 vars and ...
$flags = OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES | OPTION_FLAG_LINKS;
$display_me = generate_text_for_display($doc_body, $bbcode_uid, $bbcode_bitfield, $flags);

echo($display_me);
schwim
Registered User
Posts: 147
Joined: Sat Jun 04, 2005 8:03 am

Re: Adapting bbcode to non-topic content

Post by schwim »

Wow, Tony! Thanks so much for that! It looks fantastic!

How does it get away with not needing the additional function includes, if I might ask?
User avatar
T0ny
Registered User
Posts: 1383
Joined: Sun Jan 29, 2006 8:42 pm
Location: Lancashire
Name: Tony

Re: Adapting bbcode to non-topic content

Post by T0ny »

everything it needs is included when you include the common.php file or by the generate_text_* functions themselves
schwim
Registered User
Posts: 147
Joined: Sat Jun 04, 2005 8:03 am

Re: Adapting bbcode to non-topic content

Post by schwim »

Hi there TOny,

I've got a couple questions I've run into while implementing.

Would editing simply consist of changing the function:

Code: Select all

$flags = OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES | OPTION_FLAG_LINKS;
$display_me = generate_text_for_edit($doc_body, $bbcode_uid, $bbcode_bitfield, $flags);
Or should I be adding something into the mix. Initial test looks like it's working properly, but just wanted to make sure.

Second question is: No matter what I set for the allowed three switches in generate_text_for_display, does this line remain the same? Meaning instead of true, true, true it were true, false, true

Code: Select all

$flags = OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES | OPTION_FLAG_LINKS;
The reason I'm asking is because I'd like to turn off bbcode completely for one group, allow bbcode and smilies but not links for another.
User avatar
T0ny
Registered User
Posts: 1383
Joined: Sun Jan 29, 2006 8:42 pm
Location: Lancashire
Name: Tony

Re: Adapting bbcode to non-topic content

Post by T0ny »

generate_text _for_edit only takes 3 parameters:
function generate_text_for_edit($text, $uid, $flags)

so no need to pass the bitfield (also remember it returns an array, not a string)


The 3 boolean parameters to generate_text_for_storage() determine which elements are processed, so setting each to false will deny the current user the ability to use the relevant feature. I honestly don't know what the intended purpose of 'flags' is, I've always just set them all :)
schwim
Registered User
Posts: 147
Joined: Sat Jun 04, 2005 8:03 am

Re: Adapting bbcode to non-topic content

Post by schwim »

I think I understand that. So far, it seems to be working. I need to remove some certain bbcode, like code, flash and attachment. Is the best way to handle this just to remove the cases from bbcode.php and if so, do I need to renumber the remaining codes?:

Code: Select all

				case 8:
					$this->bbcode_cache[$bbcode_id] = array(
						'preg' => array(
							'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'	=> "\$this->bbcode_second_pass_code('\$1', '\$2')",
						)
					);
				break;
Or should I be handling this elsewhere?
Locked

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