--- wakka.php.orig 2006-07-02 19:19:50.000000000 +0200 +++ wakka.php 2006-07-13 12:52:36.000000000 +0200 @@ -46,6 +46,7 @@ static $br = 1; static $trigger_table = 0; static $trigger_rowgroup = 0; + static $trigger_colgroup = 0; static $trigger_bold = 0; static $trigger_italic = 0; static $trigger_underline = 0; @@ -68,7 +69,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 +93,23 @@ return; } - if ( preg_match("/^\|(\?)(.*?)\|\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) ) { - 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) ) - { - //Set up the two variables that will aggregate the html markup + //Set up the 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 = ''; + $selfclose = ''; + + //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,28 +117,41 @@ { $close_part = ''; } - else if ( $trigger_table == 1 ) + else if ( $trigger_table == 1 || $matches[1] == '!') { $close_part = ''; } else { //This is actually opening the table (i.e. nothing at all to close). + $trigger_table = 1; $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- } + + if ( $trigger_colgroup == 1 && $matches[3] == "\n" ) + { + $trigger_colgroup = 0; + return $close_part .= ''."\n"; //Can return here, it is closed- + } if ( $matches[1] == '!' ) { + $trigger_table = 1; + $open_part = '
1 ) - { - $open_part .= ' colspan="'.$matches[3].'"'; - } - - if ( $matches[4] && $matches[4] > 1 ) - { - $open_part .= ' rowspan="'.$matches[4].'"'; - } - $open_part .= '>'; + } - return $close_part . $open_part; + + if ( preg_match("/\((.*)\)/", $matches[2], $attribs ) ) + { +// $hints = array('core' => 'core', 'i18n' => 'i18n'); + $hints = array(); + if ($trigger_table == 2 || $trigger_table == 3) $hints['cell'] = 'cell'; + else $hints['other_table'] = 'other_table'; + $open_part .= parse_attributes($attribs, $hints); + } + + $open_part .= $selfclose.'>'; + return $close_part . $open_part . $linebreak_after_open; } else if ( $trigger_table == 1 ) { @@ -581,6 +596,48 @@ } } +if (!function_exists("parse_attributes")) +{ + 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') + ); + + //adds in default hints ( core + i18n ) + $hints['core'] = 'core'; + $hints['i18n'] = 'i18n'; + + $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