Forums / Cotonti / Support / BBcode help

tensh
#1 2011-11-12 17:30

Hi,

I want to add the following bbcodes to my site:

	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) vspace=(\d*) border=(\d*) align=(\w*) hspace=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" vspace="$2" border="$3" align="$4" hspace="$5" height="$6" alt="$7" src="$8">', true, 128, 'fckeditor');	
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) vspace=(\d*) align=(\w*) hspace=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" vspace="$2" align="$3" hspace="$4" height="$5" alt="$6" src="$7">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) vspace=(\d*) border=(\d*) hspace=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" vspace="$2" border="$3" hspace="$4" height="$5" alt="$6" src="$7">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) border=(\d*) hspace=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" border="$2" hspace="$3" height="$4" alt="$5" src="$6">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) vspace=(\d*) border=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" vspace="$2" border="$3" height="$4" alt="$5" src="$6">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) border=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" border="$2" height="$3" alt="$4" src="$5">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) align=(\w*) hspace=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" align="$2" hspace="$3" height="$4" alt="$5" src="$6">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) vspace=(\d*) align=(\w*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" vspace="$2" align="$3" height="$4" alt="$5" src="$6">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) align=(\w*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" align="$2" height="$3" alt="$4" src="$5">', true, 128, 'fckeditor');	
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) border=(\d*) align=(\w*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" border="$2" align="$3" height="$4" alt="$5" src="$6">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) border=(\d*) align=(\w*) hspace=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" border="$2" align="$3" hspace="$4" height="$5" alt="$6" src="$7">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) vspace=(\d*) border=(\d*) align=(\w*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" vspace="$2" border="$3" align="$4" height="$5" alt="$6" src="$7">', true, 128, 'fckeditor');
	sed_bbcode_add('img', 'pcre', '\[img width=(\d*) height=(\d*) alt=(.*?[^"\';:\?])\]((?:http://|https://|ftp://)?[^"\';:\?\[]+\.(?:jpg|jpeg|gif|png))\[/img\]', '<img width="$1" height="$2" src="$4" alt="$3" />', true, 128, 'fckeditor');

I'm trying to make it work because I want a better image support with bbcode fckeditor for Genoa. The only thing is that Cotonti doesn't like these codes. The result is that page_html doesn't want to get parsed at all (during page edit) and even though page_text has some text in it, the page on site is blank (parser protests)

I can't really tell where I made a mistake... I don't like all that regexes. Please help, I'm fighting with it for a long time already :)

Trustmaster
#2 2011-11-12 18:51

It would help a lot if you first found which one of them (or if any of them) causes this problem using the method of exclusion (adding those bbcodes one by one). It's a suicide checking all these regexps at once for consistency.

May the Source be with you!
tensh
#3 2011-11-12 19:14

... good idea :) I'll be back in half an hour.

Added 24 minutes later:

... I can't reproduce O_O Now it works nice...

BUT... the bbcodes don't work if alt is empty (it happens). What would you recommend to make it always work? Always put a space there...?

Added 14 minutes later:

yes, it's something about the alt attribute. If the bbcode ends with alt=] , then errors appear.

How to prevent it?

Added 1 hour later:

OK, I found a way... I just made it required in fckeditor >_> I'll get back when I stumble upon more problems.

Generally I'm glad with my progress, I edited (ekhm... hacked >_> but we all know how it looks like: no proper tpls) Genoa pfs a little to make the standalone version compatible with fckeditor. :) So when I click "image" and then "browse", PFS standalone pops up and I can chose images from PFS. :) Yay! Then fckeditor calculates width and height and I can start playing with it.

Just now I have to add hundreds of image bbcodes to handle all that vspace hspace border etc crap ^_^ (excuse my french). But I think it will be worth it.

This post was edited by tensh (2011-11-12 21:38, 12 years ago)
Trustmaster
#4 2011-11-13 10:03

To allow empty alt contents, replace

alt=(.*?[^"\';:\?])

with

alt=(.*?[^"\';:\?]?)
May the Source be with you!