Tables in BBCode! Updated!
- layingback
- Site Admin
Tables in BBCode! Updated!
UPDATE: This thread has got very long and complex and the nbbcode hack has developed. It's at a pretty complete stage now, so starting a fresh thread here.
I needed basic table support, plus lists, and got to realising that if I needed it I'd better do it myself! So here it is...
Please note this is only basic table support. You can enter BBCodes that match their HTML equivalents table /table, tr /tr, th /th and td /td. Nothing fancy like colspan is supported. My goal was simple tables, to be entered by end-users to whom I didn't want to give HTML access - not because I didn't trust them, but because they might accidentally leave an open-ended HTML command... All of these have buttons, both on and off, help and FAQ entries.
While I was at it, I added buttons for the list BBCode functions that are already in the code. Plus 2 other functions that I like: IMGURL which lets you accomplish an img within a[url /url in a single operation (thanks to mikiemouse of EHP Designs for coding that), and PDFURL which places a URL link to a pdf and drops in the Adobe pdf icon automatically.
Finally an updated BBCode FAQ and a prominent link to it.
You will need to login to see the attachments.
Hope they are useful to someone.
I know of 1 problem with the table BBCodes: if you concatenate the table, tr and td codes without line breaks the table appears as you would expect. However if you, say, place each tr or td on its own line, then those line breaks are going to appear as extra br's above the table. I believe that these can be eliminated in the preg_replace command, but I couldn't figure out what code to look for. If anyone knows, I'll update.
Insert in includes/nbbcode.php starting at line 190
var imgurl_help = "'. $bbcode_common['imgurl'][0].' '.$bbcode_common['imgurl'][1].'";
var pdfurl_help = "'. $bbcode_common['pdfurl'][0].' '.$bbcode_common['pdfurl'][1].'";
var table_help= "'. $bbcode_common['table'][0].' '.$bbcode_common['table'][1].'";
var tr_help= "'. $bbcode_common['tr'][0].' '.$bbcode_common['tr'][1].'";
var th_help= "'. $bbcode_common['th'][0].' '.$bbcode_common['th'][1].'";
var td_help= "'. $bbcode_common['td'][0].' '.$bbcode_common['td'][1].'";
var list_help = "'. $bbcode_common['list'][0].' '.$bbcode_common['list'][1].'";
var nlist_help = "'. $bbcode_common['nlist'][0].' '.$bbcode_common['nlist'][1].'";
var alist_help = "'. $bbcode_common['alist'][0].' '.$bbcode_common['alist'][1].'";
var ilist_help = "'. $bbcode_common['ilist'][0].' '.$bbcode_common['ilist'][1].'";
var li_help = "'. $bbcode_common['li'][0].' '.$bbcode_common['li'][1].'";
Also starting at line 273
Also starting at line 539
# [table] and [/table] for table.
$patterns[] = '#\[table\]\r?\n?\t?(.*?)\[/table\]\r?\n?\t?#si';
$replacements[] = '<table class="BBCtable" style="border:0" cellpadding="5">\1</table>';
# [tr] and [/tr] for table row.
$patterns[] = '#\[tr\]\r?\n?\t?(.*?)\[/tr\]\r?\n?\t?#si';
$replacements[] = '<tr>\1</tr>';
# [th] and [/th] for table title.
$patterns[] = '#\[th\]\r?\n?\t?(.*?)\[/th\]\r?\n?\t?#si';
$replacements[] = '<th>\1</th>';
# [td] and [/td] for table field.
$patterns[] = '#\[td\]\r?\n?\t?(.*?)\[/td\]\r?\n?\t?#si';
$replacements[] = '<td>\1</td>';
// [imgurl url= ]image_url_here[/imgurl] code..
$patterns[] = "#\[imgurl url=([\w]+?://[^ \"\n\r\t<]*?)]([\w]+(://|\.|/)[^ (\"\n\r\t<]*?)\[/imgurl\]#si";
$replacements[] = "<a href=\"\\1\" target=\"_blank\"><img src=\"\\2\" border=\"0\" alt=\"\" /></a>";
# [pdfurl url=xxxx://www.cpgnuke.com]cpgnuke[/pdfurl]
$patterns[] = "#\[pdfurl url=([\w]+://[^ (\"\n\r\t<]*?)\](.*?)\[/pdfurl\]#is";
$replacements[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\1\" class=\"postlink\" rel=\"nofollow\">\\2 <img src=\"images/pdf_icon.gif\" border=\"0\" alt=\"\" /></a>";
Insert in language/english/bbcode.php starting at line 104
'imgurl' => array('URL with Image:','[imgurl url=Page URL]http://image path[/imgurl]'),
'pdfurl' => array('URL with PDF icon:','[pdfurl url=PDF URL]link text[/pdfurl]'),
'table' => array('Table:','[table]text[/table]'),
'tr' => array('Table row:','[tr]text[/tr] usage: [table][tr]text[/tr][/table]'),
'th' => array('Table title:','[th]text[/th] usage: [table][tr][th]text[/th][th]..[/th][/tr][/table]'),
'td' => array('Table field:','[td]text[/td] usage: [table][tr][td]text[/td][td]..[/td][/tr][/table]'),
'list' => array('Bulleted List:','[list]list[/list]'),
'nlist' => array('Numbered List:','[list=1]list[/list]'),
'alist' => array('Alpha List:','[list=a]list[/list]'),
'ilist' => array('Roman List:','[list=i]list[/list]'),
'li' => array('List item:','[*]text usage (all lists): [list][*]text[*]text [/list]'),
Update: You also need the following edits, listed further down this thread.
And you will require a PDF icon image if you want to display one, info later in this thread.
layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4
Ultima edición por layingback el Mon Apr 30, 2012 22:41, editado 3 veces
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
Have made these changes and looks like it works a treat! Thanks layingback.
Do you have an easy way of remembering what files you have edited? Only reason I ask is that when it comes to updating the site I tend to forget and end up overwriting all the little changes like this one
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1
- layingback
- Site Admin
Re: Tables in BBCode! Done!
- rosbifDo you have an easy way of remembering what files you have edited?
Yeah! I create a website, and record them all on there!
Also at a detail level I use a diff tool to compare new and old. Meld on Ubuntu, can't remember what I used to use on Windoze - it's been so long... CVS is best solution, but a bit of work to set up for all projects, so I reserve that just for the big stuff. Other possibility might be to save out diffs for all changes - assuming you have editor capable of this.
layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
I knew it wouldn't be simple!
I haven't used a diff tool before so maybe I should go looking at one. Forum would be easiest I agree!
I'm using SuperEdi as my editor but it doesn't seem to be that happy in vista. What do you use?
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1
- layingback
- Site Admin
Re: Tables in BBCode! Done!
Geany, although Notepad++ is pretty good under Windoze. Of course, nothing's very good under Vista
layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4
- warden
- Newbie
Re: Tables in BBCode! Done!
Is it possible to implement this with the NBBCode module from ehpdesigns.com?
I tried and got an error, so I was wondering if I was trying to do the impossible with no hope of success.
Thanks.
warden's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
L-3.x A-2.2x M-5.5x P-5.0x DF-9.4.0.0
- layingback
- Site Admin
Re: Tables in BBCode! Done!
warden, it should be quite straightforward I would have thought, although the locations and perhaps a few variable names will be different. But to be honest I don't have the time or the inclination to potentially mess up EHP's fine module. It may happen that I need it, but currently I have NBBCode for some sites and my Tables code on others - I've not needed both on the same site, as yet.
But I did post a feature request on EHP's site for you ...
layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4
- warden
- Newbie
Re: Tables in BBCode! Done!
Thank you.
warden's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
L-3.x A-2.2x M-5.5x P-5.0x DF-9.4.0.0
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
I've just discovered that the list function doesn't seem to work. [list] just appears as [list] without being translated. It does funny things here on your site too if you follow the format shown in the hover tip..
Have I done something wrong?
eg
[list][*]text[/*][/list]
gives
- text[/*]
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1
- layingback
- Site Admin
Re: Tables in BBCode! Done!
Should be:
- text
- text
- text
Click on BBCode FAQ for instructions
layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
Ah ok, it's correct in the FAQ but the mouseover instructions by the bullet are wrong..
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1
- layingback
- Site Admin
Re: Tables in BBCode! Done!
Thanks. Yes, too late to fix last nite, but edited now I believe. Last line of last insert.
layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
I seem to have a problem now with URL with Image, List Item and URL with PDF. The error shows up as Line 826, submit.html, object expected.
Incidentally there's a reference to images/pdf_icon.gif which I don't seem to have. Should I have that from somewhere?
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
Also, I think I mentioned this before somewhere but can't remember where, pressing any BBCode button always puts the code at the bottom of the text, rather than around the highlighted text for example...
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1
- rosbif
- BetaTester
Re: Tables in BBCode! Done!
Any thoughts on these last two posts (now that 3.2 is launched!!)
rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/4.1.22/5.2.17/9.3.4.1