_parse_row($line, $basepage); } } $nbrows = sizeof($table); $nbcols = sizeof($table[0]); for ($i=0; $i<$nbrows; $i++) { for ($j=0; $j<$nbcols; $j++) { if ($table[$i][$j][0] == '@') { $table[$i][$j] = $this->_compute($table, $i, $j, $nbrows, $nbcols); } } } $htmltable = HTML::table(array('class' => "bordered")); foreach ($table as $row) { $htmlrow = HTML::tr(); foreach ($row as $cell) { if ($cell[0] == '=') { $cell = trim(substr($cell, 1)); $htmlrow->pushContent(HTML::th(TransformInline($cell, 2.0, $basepage))); } else { if (is_numeric($cell)) { $htmlrow->pushContent(HTML::td(array('style' => "text-align:right"), $cell)); } else { $htmlrow->pushContent(HTML::td(TransformInline($cell, 2.0, $basepage))); } } } $htmltable->pushContent($htmlrow); } return $htmltable; } function _parse_row ($line, $basepage) { $brkt_link = "\\[ .*? [^]\s] .*? \\]"; $cell_content = "(?: [^[] | ".ESCAPE_CHAR."\\[ | $brkt_link )*?"; preg_match_all("/(\\|+) \s* ($cell_content) \s* (?=\\||\$)/x", $line, $matches, PREG_SET_ORDER); $row = array(); foreach ($matches as $m) { $cell = $m[2]; $row[]= $cell; } return $row; } function _compute ($mytable, $i, $j, $imax, $jmax) { // What is implemented: // @@SUM(R)@@ : sum of cells in current row // @@SUM(C)@@ : sum of cells in current column $result=0; if (trim($mytable[$i][$j]) == "@@SUM(C)@@") { for ($index=0; $index<$imax; $index++) { $result += $mytable[$index][$j]; } } if (trim($mytable[$i][$j]) == "@@SUM(R)@@") { for ($index=0; $index<$jmax; $index++) { $result += $mytable[$i][$index]; } } return $result; } } // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>