bbcode> creating tables

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
ArgoNaut_Iron
Registered User
Posts: 1
Joined: Fri Dec 13, 2002 12:46 pm

bbcode> creating tables

Post by ArgoNaut_Iron »

for some reason i can't create a simple table like
<table width="100%">
<tr><td>a</td><td>b</td>
<tr><td>a</td><td>b</td>
<tr><td>a</td><td>b</td>
<tr><td>a</td><td>b</td></table>


in a post. it shows 5 blank rules above the table. is it possible to make a working "table tag" with bbcode?

tnx in advance
talia679
Registered User
Posts: 716
Joined: Tue Mar 12, 2002 4:07 pm
Location: PA
Contact:

Post by talia679 »

I would love the ability to have tables ... this is a mod I would use!
Thanks, Talia
Tag You're It Writing Community || TYI Forums
Taleria - Talia's Gallery of 2000+ Links & 140+ Books
GameCrafters Guild – Gaming info and resources
LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

Post by LifeIsPain »

Well, it is possible, I have it worked out except for the fact that it doesn't use extra variables (for now) and it is really easy to mess up. So in order to use it, you have to be pretty specific, and extra characters are not liked. Note that I woked on this from a modification of bbcode.php that doesn't use templates, is split up into multiple files, but I will give the code changes I made if someone wants to run with it, and will also say what I think the code would have been with a standard install (not testing). Also please note that I am no longer using this code, I left behind for a different method (one where tables aren't in the code, that is left to my page layout)

Code: Select all

#-----[ OPEN ]------------
includes/bbcode.php

#------[ FIND ]--------------
	// ordered.
	$text = bbencode_first_pass_pda($text, $uid, $open_tag, "[/list]", "[/list:o]",  false, 'replace_listitems');

#------[ AFTER, ADD ]-------------------
	// [table] and [/table] for adding tables. Smart enough to know that it must be
	// nested correctly
	$text = bbencode_first_pass_pda($text, $uid, '[table]', '[/table]', '', false, 'replace_tablerows');

#------[ FIND ]--------------
	// [center] and [/center] for centering content
	$text = str_replace("[center:$uid]", $bbcode_tpl['center_open'], $text);
	$text = str_replace("[/center:$uid]", $bbcode_tpl['center_close'], $text);

#------[ AFTER, ADD ]-------------------
	// [table] and [/table] for tables
	$text = str_replace("[table:$uid]", $bbcode_tpl['table_open'], $text);
	$text = str_replace("[/table:$uid]", $bbcode_tpl['table_close'], $text);

	// [tr] and [/tr] for table rows
	$text = str_replace("[tr:$uid]", $bbcode_tpl['tr_open'], $text);
	$text = str_replace("[/tr:$uid]\r\n", $bbcode_tpl['tr_close'], $text);
	$text = str_replace("[/tr:$uid]", $bbcode_tpl['tr_close'], $text);

	// [td] and [/td] for table cells
	$text = str_replace("[td:$uid]", $bbcode_tpl['td_open'], $text);
	$text = str_replace("[/td:$uid]\r\n", $bbcode_tpl['td_close'], $text);
	$text = str_replace("[/td:$uid]", $bbcode_tpl['td_close'], $text);

#------[ FIND ]--------------
function replace_listitems($text, $uid)
{
	$text = str_replace("[*]", "[*:$uid]", $text);

	return $text;
}

#------[ AFTER, ADD ]--------------------
function replace_tablerows($text, $uid)
{
	$text = substr(bbencode_first_pass_pda(' '.$text, $uid, '[tr]', '[/tr]', '', false, 'replace_tablecells'), 1);

	return $text;
}

function replace_tablecells($text, $uid)
{
	$text = substr(bbencode_first_pass_pda(' '.$text, $uid, '[td]', '[/td]', '', false, ''), 1);

	return $text;
}

#------[ OPEN ]---------------
templates/subSilver/bbcode.tpl

#------[ FIND ]---------------
<!-- BEGIN listitem --><li><!-- END listitem -->

#------[ AFTER, ADD ]--------------
<!-- BEGIN table_open --><table><!-- END table_open -->
<!-- BEGIN table_close --></table><!-- END table_close -->

<!-- BEGIN tr_open --><tr><!-- END tr_open -->
<!-- BEGIN tr_close --></tr><!-- END tr_close -->

<!-- BEGIN td_open --><td><!-- END td_open -->
<!-- BEGIN td_close --></td><!-- END td_close -->

#------[ EOF ]-----------------
Ok, now to let you in a few of my problems. I was unable to get it to ignore bad calls such as:

Code: Select all

[table]bob is cool[tr][td]stuff[/td][/tr]
[tr]more[/tr][/table]
or other times where text is outside of the table rows, table cells that don't exist, but it is still accepted. But if you use good bbcode, the table works fine (oh, and don't use a line break after an opening comment, you get a bunch of blank lines). But if someone is able to run with the above, that is great.
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.
Post Reply

Return to “[2.0.x] MOD Requests”