From: <var...@us...> - 2009-01-02 11:04:12
|
Revision: 6363 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=6363&view=rev Author: vargenau Date: 2009-01-02 11:04:05 +0000 (Fri, 02 Jan 2009) Log Message: ----------- Add spreadsheet capability to Wikicreole tables Modified Paths: -------------- trunk/lib/plugin/WikicreoleTable.php Modified: trunk/lib/plugin/WikicreoleTable.php =================================================================== --- trunk/lib/plugin/WikicreoleTable.php 2009-01-02 10:54:00 UTC (rev 6362) +++ trunk/lib/plugin/WikicreoleTable.php 2009-01-02 11:04:05 UTC (rev 6363) @@ -75,7 +75,7 @@ global $WikiTheme; include_once('lib/InlineParser.php'); - $table = HTML::table(array('class' => "bordered")); + $table = array(); $lines = preg_split('/\s*?\n\s*/', $argstr); @@ -84,18 +84,42 @@ continue; } $line = trim($line); - // If lines ends with a '|', remove it + // If line ends with a '|', remove it if ($line[strlen($line)-1] == '|') { $line = substr($line, 0, -1); } if ($line[0] != '|') { // trigger_error(sprintf(_("Line %s does not begin with a '|'."), $line), E_USER_WARNING); } else { - $table->pushContent($this->_parse_row($line, $basepage)); + $table[] = $this->_parse_row($line, $basepage); } } - return $table; + $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 { + $htmlrow->pushContent(HTML::td(TransformInline($cell, 2.0, $basepage))); + } + } + $htmltable->pushContent($htmlrow); + } + return $htmltable; } function _parse_row ($line, $basepage) { @@ -105,19 +129,34 @@ preg_match_all("/(\\|+) \s* ($cell_content) \s* (?=\\||\$)/x", $line, $matches, PREG_SET_ORDER); - $row = HTML::tr(); + $row = array(); foreach ($matches as $m) { $cell = $m[2]; - if ($cell[0] == '=') { - $cell = trim(substr($cell, 1)); - $row->pushContent(HTML::th(TransformInline($cell, 2.0, $basepage))); - } else { - $row->pushContent(HTML::td(TransformInline($cell, 2.0, $basepage))); - } + $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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |