[RFC|Accepted] Updated BBcode engine

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by brunoais »

I'll answer according to the current plans in making this system (the current plans are not final):
leschek wrote:1. Would be possible to use Post ID (something like here), when creating custom BBCode?
If I understood it right, you should be able to do that but you will not be able to use the simplified system. You'll have to write the PHP yourself.
leschek wrote:2 .Will we (users) be able to use template conditions (IFs) when creating custom BBCode?
What kind of template conditions?
Anyway, you'll be able to write php code to execute the data that was captured yourself, the way you want. (I sure hope that answers it). So you'll be able to apply conditions to the BBCode.
leschek wrote:3 .Would be possible to add to Quote and Code BBCode option to expand and collapse the box?
We will provide some BBCodes like bold, quote, code, img, etc... As custom BBCodes, you may change them later so that they can use a button, or whatever, to expand and collapse as needed/requested.
Ofc, if this becomes a lot requested by the time we are writing the BBCodes, we will do it that way.
leschek
Registered User
Posts: 163
Joined: Tue Aug 28, 2012 1:30 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by leschek »

Thank you fore explanation.
brunoais wrote:
leschek wrote:1. Would be possible to use Post ID (something like here), when creating custom BBCode?
If I understood it right, you should be able to do that but you will not be able to use the simplified system. You'll have to write the PHP yourself.
I was asking about this, because some scripts have IDs and users can use post ID as part of unique ID, when they "convert" script into BBCode.
brunoais wrote:
leschek wrote:2 .Will we (users) be able to use template conditions (IFs) when creating custom BBCode?
What kind of template conditions?
Anyway, you'll be able to write php code to execute the data that was captured yourself, the way you want. (I sure hope that answers it). So you'll be able to apply conditions to the BBCode.
I was using on my forum two languages in one post, so the idea was to create 2 BBCodes for two languages and when user change board into English he/she will see only English text and when user change forum into second language he/she will see dafaul text. It was sometjing like this:

Code: Select all

<!-- IF S_USER_LANG == 'en' -->
show text
<!-- ELSE -->
show other text
<!-- ENDIF -->
Anyway I think it will be possible to do with php too, even for php beginner.
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by brunoais »

leschek wrote:
brunoais wrote:
leschek wrote:2 .Will we (users) be able to use template conditions (IFs) when creating custom BBCode?
What kind of template conditions?
Anyway, you'll be able to write php code to execute the data that was captured yourself, the way you want. (I sure hope that answers it). So you'll be able to apply conditions to the BBCode.
I was using on my forum two languages in one post, so the idea was to create 2 BBCodes for two languages and when user change board into English he/she will see only English text and when user change forum into second language he/she will see dafaul text. It was sometjing like this:

Code: Select all

<!-- IF S_USER_LANG == 'en' -->
show text
<!-- ELSE -->
show other text
<!-- ENDIF -->
Anyway I think it will be possible to do with php too, even for php beginner.
According to what is is now (this is an example):

Code: Select all

public function parse($name, $parameters, $inside){
	global $user;
	if(preg_match('%(.*?)<!-- ELSE -->(.*)%s', $inside, $matchResult)){
		if($parameters['lang'] == $user->lang['USER_LANG']){
			return $matchResult[1]   //show_text
		}else{
			return $matchResult[2]   //show_other_text 
		}
	}
leschek
Registered User
Posts: 163
Joined: Tue Aug 28, 2012 1:30 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by leschek »

Awesome, I will try it when 3.1 alpha will be out.
Thank you
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by brunoais »

Just an important note there.
There's no guarantee that this will be ready when phpBB3.1 comes out.
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by brunoais »

I have completed my analysis on jBBCode as asked by Exreaction.
The highlights of my tests and looking at the code are as follows:
With an input like this:

Code: Select all

	[b]
		[b] 
		boldy!
		[/b]
		[u]
			[b] 
				[u] 
					underlined bold
				[/u]
			[/b]
		[/u]
	[/b]
	[b]
	another bold
		[b]
			[u] 
			another underlined bold
			[/u]
		[/b]
		[u]
			[b] 
			[/b]
		[/u]
	[/b]
Parsing times (truncated):

Code: Select all

		     Mine				   jBBCode
Min:		0.00046110			0.00107502

Max:		0.00063514			0.00142199
I executed both 30 times and ignored the 1st one (it was always the one that took longer for both due to the compiling).

I made it such that the rules for clock starting and clock ending are the same. I.e. All the preparations to parse was not counted, only the parsing itself. I also removed the odd ones. If there was a time that was ridicilous low or high, I didn't count it.

Note: I had to strip down my simple test input (continue reading to know why):
Why mine is better:
  • Mine supports parameterized BBcodes. It is already prepared to allow a quote tag like this. jBBCode supports only as much as phpBB currently supports. A single parameter or no parameter.
  • Mine is faster even if I'm not using it in it's most optimized way.
  • Mine is prepared for stuff like (the extra spaces are for this forum not to parse it): [ name=abc]def]ghi[/ name] You just need to use the other option of making it: [ name="abc]def"]ghi[/ name] you can also use [ name="\"abc\"]def"]ghi[/ name] without any problems (it creates <tagname att="\"abc\"]def">ghi</tagname> . With jBBCode with this [ name=abc]def]ghi[/ name] you are stuck to <tagname att="abc">def]ghi</tagname>
Why mine is worse:
  • jBBCode's code is distributed over multiple files making it more Java-like organization. Mine is a single class and does it in multiple steps.
  • jBBCode is generalist and is made and optimized for multipurpose/wide-range of usages. Mine is optimized for a forum post.
These are the highlights I found while reading the source code and while testing it.
Opinions?

brunoais wrote:
EXreaction wrote:Do you think that distributing it over more files is a reason it might be slower? Or is it slower just because of the rest of the design?
For me, the problem is the design itself. The difference is small but quite noticeable. My version of php (5.4.?) takes good care of caching and knowing how to cache executable files. It only compiles them 1ce.
Just to confirm myself I "infiled" (placed all in the same file) all the classes. The times were, in average, less 0.0001 seconds to parse the input code. IMO, it's the algorithm itself. It works directly in the inputted string and not outside it. (I'm quite curious to know how fast is phpBB's... Oleg says it is really fast... I say it is buggy).
EXreaction wrote: I did like the way the TokenManager was designed, might that or something similar be useful for you or is your design going to be much faster? If you could do something similar, perhaps you could move some of the processing into a class like that so it does the work of finding the bbcodes, finding the start/end brackets, and then letting you go over the bbcodes it found to parse in a different class. That might make it a little more organized, easy to follow/understand, and much more re-usable in the future. It might be able to implement ArrayAccess, IteratorAggregate, Countable. If you don't think this would work just tell me so, I trust your opinion on this, you seem to have a much better idea of how to do this than I do. :)
The problem here is that I work in steps. Step1 so this. Step 2 do next thing. Step 3 do another thing. I'm making each step one method in the Class I'm making.
In each step it does x and x only in which the concept of x is a simple task. 1st, find candidate tags, 2nd, match opening with closing tags, 3rd step, make the tree out of the tags, etc..., etc...etc... As you can see, for these 3, each one has a simple task to solve, in concept. I'm still wondering if I can optimize this more without sacrificing readability. I have already scrapped some ideas because it would most likely be multi-stepping in the same step.
In jBBCode, the ideology is different. In jBBCode the objective is to distribute the workload over multiple classes such that each class has it's own specific job. In order to apply my specifics, I cannot work that way and make it efficient, at the same time. I'd need to change this such way that it is not what I meant it to be anymore, still a BBCode parser, but not with the ideology I'm after.
I think my code is easy to follow and understand, specially with the help of the comments. Well... I may create some simple graphs in the comments themselves to help understand what's happening in each step, if wanted.
Anyway, both ArrayAccess and IteratorAggregate don't make much sense here because this is a tree (ish). Anyway, nothing is against I implement the 2nd one. I would just need to force the user of the class to ask it to parse all the way before using its iterator (Or I would parse with I have when the iterator was asked). Same thing for ArrayAccess even though it does not make as much sense with ArrayAccess. Countable is... Number of BBCodes? Yeah... I could also do that, but parsing and validation is required first to prevent wrong numbers.
EXreaction wrote: Other than that my opinion on your analysis is that you should just stick with your own design.
Ok.
Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC|Accepted] Updated BBcode engine

Post by Oleg »

How is asymptotic performance of the libraries being tested? Where is the test source code?
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by brunoais »

My system, as it currently is made, does not support many BBCodes properly, only straight forward BBCodes that follow the general simple rule. Anyway:
Tests are made by reloading the page and registering the values obtained.
jBBCode test code:
https://gist.github.com/4249234
My class test code:
https://github.com/brunoais/phpbb3/blob ... gClass.php
User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC|Accepted] Updated BBcode engine

Post by callumacrae »

brunoais wrote:Why mine is better:
  • Mine supports parameterized BBcodes. It is already prepared to allow a quote tag like this. jBBCode supports only as much as phpBB currently supports. A single parameter or no parameter.
  • Mine is faster even if I'm not using it in it's most optimized way.
  • Mine is prepared for stuff like (the extra spaces are for this forum not to parse it): [ name=abc]def]ghi[/ name] You just need to use the other option of making it: [ name="abc]def"]ghi[/ name] you can also use [ name="\"abc\"]def"]ghi[/ name] without any problems (it creates <tagname att="\"abc\"]def">ghi</tagname> . With jBBCode with this [ name=abc]def]ghi[/ name] you are stuck to <tagname att="abc">def]ghi</tagname>
I don't see how any of them are important
Made by developers, for developers!
My blog
User avatar
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC|Accepted] Updated BBcode engine

Post by brunoais »

Why do you state that?
Post Reply