--- wakka.php.orig 2006-07-02 19:19:50.000000000 +0200
+++ wakka.php 2006-07-06 15:07:17.000000000 +0200
@@ -68,7 +68,8 @@
if ((!is_array($things)) && ($things == 'closetags'))
{
- if (2 < $trigger_table) echo ('');
+ if (3 < $trigger_table) echo ('');
+ else if (2 < $trigger_table) echo ('');
else if (1 < $trigger_table) echo ('');
if (2 < $trigger_rowgroup) echo ('');
else if (1 < $trigger_rowgroup) echo ('');
@@ -91,27 +92,21 @@
return;
}
- if ( preg_match("/^\|(\?)(.*?)\|\n$/", $thing, $matches) )
- {
- if ( $trigger_table == 0 )
- {
- $trigger_table = 1;
- return '
'."\n";
- }
- }
- // table. trigger means: 0==no table, 1==in table no cell, 2==in table data cell, 3==in table header cell
- else if ( preg_match("/^\|(=|!|#)?(c|r|h|f|b)?(\d*)?(?:,)?(\d*)?\|(\n)?$/", $thing, $matches) )
+ // table. trigger means: 0==no table, 1==in table no cell, 2==in table data cell, 3==in table header cell, 4==in caption
+ else if ( preg_match("/^\|(\?|!|=|\[|\]|#)?(\(.*?\))?\|(\n)?$/", $thing, $matches) )
{
//Set up the two variables that will aggregate the html markup
$close_part = '';
$open_part = '';
- //First catch is header|caption|rowgroup, second is attribute, third is colspan, fourth is rowspan, fifth is linebreak.
- if ( $trigger_table == 4 )
- {
+ $linebreak_after_open = '';
+ //First catch is caption|header|rowgroup, second is attributes, third is linebreak.
+ if ( $trigger_table == 4 ) {
+ $close_part = ''."\n";
$trigger_table = 1;
- return ''."\n"; //Can return here, it is closed.
+ return $close_part;
}
- else if ( $trigger_table == 3 )
+
+ if ( $trigger_table == 3 )
{
$close_part = '';
}
@@ -119,7 +114,7 @@
{
$close_part = '';
}
- else if ( $trigger_table == 1 )
+ else if ( $trigger_table == 1 || $matches[1] == '!')
{
$close_part = '';
}
@@ -129,7 +124,7 @@
$close_part = ''."\n";
}
- if ( $trigger_table > 1 && $matches[5] == "\n" )
+ if ( $trigger_table > 1 && $matches[3] == "\n" )
{
$trigger_table = 1;
return $close_part .= ''."\n"; //Can return here, it is closed-
@@ -137,10 +132,16 @@
if ( $matches[1] == '!' )
{
+ $trigger_table = 1;
+ $open_part = '';
+ $open_part = ' 1 )
- {
- $open_part .= ' colspan="'.$matches[3].'"';
- }
-
- if ( $matches[4] && $matches[4] > 1 )
- {
- $open_part .= ' rowspan="'.$matches[4].'"';
- }
- $open_part .= '>';
+
+ }
+
+ if ( preg_match("/\((.*)\)/", $matches[2], $attribs ) )
+ {
+ $hints = array('core', 'i18n');
+ if ($trigger_table == 2 || $trigger_table == 3) $hints[] = 'cell';
+ else $hints[] = 'other_table';
+ $open_part .= parse_attributes($attribs, $hints);
}
- return $close_part . $open_part;
+
+ $open_part .= '>';
+ return $close_part . $open_part . $linebreak_after_open;
}
else if ( $trigger_table == 1 )
{
@@ -581,6 +568,44 @@
}
}
+if (!function_exists("parse_attributes")) # DotMG [many lines] : Unclosed tags fix!
+{
+ function parse_attributes($attribs, $hints) {
+
+ static $attributes = array(
+ 'core' => array( 'c' => 'class','i' => 'id','s' => 'style','t' => 'title'),
+ 'i18n' => array( 'd' => 'dir','l' => 'xml:lang'),
+ 'cell' => array( 'a' => 'abbr','h' => 'headers','o' => 'scope','x' => 'colspan','y' => 'rowspan','z' => 'axis'),
+ 'other_table' => array( 'p' => 'span','u' => 'summary')
+ );
+
+ $attribs = preg_split('/;(?=.:)/', $attribs[1]);
+ $return_value = '';
+
+ foreach ( $attribs as $attrib )
+ {
+ list ($key, $value) = explode(':', $attrib, 2);
+ foreach ( $hints as $hint )
+ {
+ $temp = $attributes[$hint];
+ if ($temp) $a = $temp[$key];
+ if ($a) break;
+ }
+
+ if (!$a)
+ {
+ echo ''."\n";
+ }
+ else
+ {
+ $return_value .= ' '.$a.'="'.$value.'"';
+ }
+ }
+
+ return $return_value;
+ }
+}
+
$text = str_replace("\r\n", "\n", $text);
// replace 4 consecutive spaces at the beginning of a line with tab character