Topic: Rewrite bbcode functions

I think it could be useful to rewrite some of the bbcode functions in /include/parser.php. Now, I'm not clamoring to see these changes right away but I think they would be helpful in the future.

Here's what I'm thinking:

(1) Move much of what preparse_bbcode() is doing into do_bbcode() or into some other function. (Look at dropping preparse_bbcode() altogether?tricked out RegExps can take up the slack and process the text with less preg_replace() calls.)

(2) Rearrange things so that there's only one copy of the bbcode patterns (lets say, in a new bbcode_patterns() function).

(3) Now, do_bbcode() can get its pattern arrays by calling bbcode_patterns().


So what's the point?:

These changes will help PunBB better cooperate with preview and WYSIWYG editor mods. PunBB will act the same as before, but future mods will have easy access to a master bbcode pattern list. A JavaScript editor mod could start sharing code with PunBB's standard editor.

I think this will be useful in the future because, as web apps mature, WYSIWYG editors are going to be the norm. People are going to expect them and anything less will be seen as old and unfriendly.

Later when a mature JavaScript WYSIWYG mod emerges, it could be offered as a convenient plug-in or even wrapped into the PunBB core.

In the case of JavaScript plug-ins: There are differences between PHP's and JavaScript's RegExp patterns but they could be converted by the mod.

Latest Open Source project: [img=Templar PHP]http://code.google.com/p/templarphp/logo?logo_id=1251758459[/img]

TemplarPHP - A cascading template framework for PHP.

Re: Rewrite bbcode functions

Along those changes, a quite useful thing to have would be to allow multiple "markup" (or encoding) for posting. A common requested example is Textile.

Not code them or implement them, just leave rooms (and hooks) for them so that the 1.3 plugins may easily implement them for example.

Re: Rewrite bbcode functions

I think that this type of internal rearrangement is a step in that direction. A master list of pattern?replacement pairs could allow for an easy Textile mod.

The BBCode patterns would be replaced with the Textile patterns and the replacement values would get a little tweak:
    BBCode --> $masterList['\\[url=([^\\]]+)\\](.*?)\\[\\/url\\]'] = '<a href="$1">$2</a>';
      Textile --> $masterList['"([^"]*)":http://([^ ]*)'] = '<a href="http://$2">$1</a>';

Note: The patterns above have not been tested and could be cleaned up quite a bit (I haven't been regexing in PHP for a while).

Latest Open Source project: [img=Templar PHP]http://code.google.com/p/templarphp/logo?logo_id=1251758459[/img]

TemplarPHP - A cascading template framework for PHP.

Re: Rewrite bbcode functions

I think it's a good idea. However, there are few things I dislike more than fiddling with regular expressions. If we go through with this, I think giving all the bbcode regexps an overhaul is a good idea. We need a regexp guru. Anyone? Shawn, how are you at regular expressions?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Rewrite bbcode functions

Rickard wrote:

Anyone? Shawn, how are you at regular expressions?

My regex is pretty good. I'd be happy to help with this.

Latest Open Source project: [img=Templar PHP]http://code.google.com/p/templarphp/logo?logo_id=1251758459[/img]

TemplarPHP - A cascading template framework for PHP.

6

Re: Rewrite bbcode functions

While you are both at it could you sort things out so that

(b) = <b>
(strong) = <strong>
(i) = <i>
(em) = <em>
(del) = <del>
(img="a nice sunset") = <img alt="a nice sunset"
(img) = <img alt="No description provided"

Though to be honest, the img tag is the only one I am really bothered about.

Re: Rewrite bbcode functions

ShawnBrown: Great. I'll contact you via e-mail.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Rewrite bbcode functions

I have a question, why the BBcode [center] or [align] aren't implemented yet ?

Re: Rewrite bbcode functions

Xzorg6 wrote:

I have a question, why the BBcode [center] or [align] aren't implemented yet ?

Hmm, that really isn't what this topic is for, but anyway, the Extra BBCodes should take care of the [align] tag for you.

Looking for a certain modification for your forum? Please take a look here before posting.