From: <var...@us...> - 2011-01-07 10:05:03
|
Revision: 7819 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=7819&view=rev Author: vargenau Date: 2011-01-07 10:04:56 +0000 (Fri, 07 Jan 2011) Log Message: ----------- Move compute_tablecell to Wikicreoletable plugin Modified Paths: -------------- trunk/lib/plugin/WikicreoleTable.php trunk/lib/stdlib.php Modified: trunk/lib/plugin/WikicreoleTable.php =================================================================== --- trunk/lib/plugin/WikicreoleTable.php 2011-01-07 09:58:36 UTC (rev 7818) +++ trunk/lib/plugin/WikicreoleTable.php 2011-01-07 10:04:56 UTC (rev 7819) @@ -106,7 +106,7 @@ if (!isset($table[$i][$j])) { $table[$i][$j] = ''; } else if (preg_match('/@@/', $table[$i][$j])) { - $table[$i][$j] = compute_tablecell($table, $i, $j, $nbrows, $nbcols); + $table[$i][$j] = $this->_compute_tablecell($table, $i, $j, $nbrows, $nbcols); } } } @@ -147,6 +147,156 @@ return $row; } + /** + * Compute cell in spreadsheet table + * $table: two-dimensional table + * $i and $j: indexes of cell to compute + * $imax and $jmax: table dimensions + */ + function _compute_tablecell ($table, $i, $j, $imax, $jmax) { + + // What is implemented: + // @@=SUM(R)@@ : sum of cells in current row + // @@=SUM(C)@@ : sum of cells in current column + // @@=AVERAGE(R)@@ : average of cells in current row + // @@=AVERAGE(C)@@ : average of cells in current column + // @@=MAX(R)@@ : maximum value of cells in current row + // @@=MAX(C)@@ : maximum value of cells in current column + // @@=MIN(R)@@ : minimum value of cells in current row + // @@=MIN(C)@@ : minimum value of cells in current column + // @@=COUNT(R)@@ : number of cells in current row + // (numeric or not, excluding headers and current cell) + // @@=COUNT(C)@@ : number of cells in current column + // (numeric or not, excluding headers and current cell) + + $result=0; + $counter=0; + $found=false; + + if (strpos($table[$i][$j], "@@=SUM(C)@@") !== false) { + for ($index=0; $index<$imax; $index++) { + if (is_numeric($table[$index][$j])) { + $result += $table[$index][$j]; + } + } + return str_replace("@@=SUM(C)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=SUM(R)@@") !== false) { + for ($index=0; $index<$jmax; $index++) { + if (is_numeric($table[$i][$index])) { + $result += $table[$i][$index]; + } + } + return str_replace("@@=SUM(R)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=AVERAGE(C)@@") !== false) { + for ($index=0; $index<$imax; $index++) { + if (is_numeric($table[$index][$j])) { + $result += $table[$index][$j]; + $counter++; + } + } + $result=$result/$counter; + return str_replace("@@=AVERAGE(C)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=AVERAGE(R)@@") !== false) { + for ($index=0; $index<$jmax; $index++) { + if (is_numeric($table[$i][$index])) { + $result += $table[$i][$index]; + $counter++; + } + } + $result=$result/$counter; + return str_replace("@@=AVERAGE(R)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=MAX(C)@@") !== false) { + for ($index=0; $index<$imax; $index++) { + if (is_numeric($table[$index][$j])) { + if (!$found) { + $found=true; + $result=$table[$index][$j]; + } else { + $result = max($result, $table[$index][$j]); + } + } + } + if (!$found) { + $result=""; + } + return str_replace("@@=MAX(C)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=MAX(R)@@") !== false) { + for ($index=0; $index<$jmax; $index++) { + if (is_numeric($table[$i][$index])) { + if (!$found) { + $found=true; + $result=$table[$i][$index]; + } else { + $result = max($result, $table[$i][$index]); + } + } + } + if (!$found) { + $result=""; + } + return str_replace("@@=MAX(R)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=MIN(C)@@") !== false) { + for ($index=0; $index<$imax; $index++) { + if (is_numeric($table[$index][$j])) { + if (!$found) { + $found=true; + $result=$table[$index][$j]; + } else { + $result = min($result, $table[$index][$j]); + } + } + } + if (!$found) { + $result=""; + } + return str_replace("@@=MIN(C)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=MIN(R)@@") !== false) { + for ($index=0; $index<$jmax; $index++) { + if (is_numeric($table[$i][$index])) { + if (!$found) { + $found=true; + $result=$table[$i][$index]; + } else { + $result = min($result, $table[$i][$index]); + } + } + } + if (!$found) { + $result=""; + } + return str_replace("@@=MIN(R)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=COUNT(C)@@") !== false) { + for ($index=0; $index<$imax; $index++) { + // exclude header + if (!string_starts_with(trim($table[$index][$j]), "=")) { + $counter++; + } + } + $result = $counter-1; // exclude self + return str_replace("@@=COUNT(C)@@", $result, $table[$i][$j]); + + } else if (strpos($table[$i][$j], "@@=COUNT(R)@@") !== false) { + for ($index=0; $index<$jmax; $index++) { + // exclude header + if (!string_starts_with(trim($table[$i][$index]), "=")) { + $counter++; + } + } + $result = $counter-1; // exclude self + return str_replace("@@=COUNT(R)@@", $result, $table[$i][$j]); + } + + return $table[$i][$j]; + } + } // Local Variables: Modified: trunk/lib/stdlib.php =================================================================== --- trunk/lib/stdlib.php 2011-01-07 09:58:36 UTC (rev 7818) +++ trunk/lib/stdlib.php 2011-01-07 10:04:56 UTC (rev 7819) @@ -100,7 +100,6 @@ parse_attributes($line) is_image ($filename) is_video ($filename) - compute_tablecell ($table, $i, $j, $imax, $jmax) function: linkExistingWikiWord($wikiword, $linktext, $version) moved to: lib/WikiTheme.php @@ -2484,154 +2483,6 @@ } /** - * Compute cell in spreadsheet table - * $table: two-dimensional table - * $i and $j: indexes of cell to compute - * $imax and $jmax: table dimensions - */ -function compute_tablecell ($table, $i, $j, $imax, $jmax) { - - // What is implemented: - // @@=SUM(R)@@ : sum of cells in current row - // @@=SUM(C)@@ : sum of cells in current column - // @@=AVERAGE(R)@@ : average of cells in current row - // @@=AVERAGE(C)@@ : average of cells in current column - // @@=MAX(R)@@ : maximum value of cells in current row - // @@=MAX(C)@@ : maximum value of cells in current column - // @@=MIN(R)@@ : minimum value of cells in current row - // @@=MIN(C)@@ : minimum value of cells in current column - // @@=COUNT(R)@@ : number of cells in current row - // (numeric or not, excluding headers and current cell) - // @@=COUNT(C)@@ : number of cells in current column - // (numeric or not, excluding headers and current cell) - - $result=0; - $counter=0; - $found=false; - - if (strpos($table[$i][$j], "@@=SUM(C)@@") !== false) { - for ($index=0; $index<$imax; $index++) { - if (is_numeric($table[$index][$j])) { - $result += $table[$index][$j]; - } - } - return str_replace("@@=SUM(C)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=SUM(R)@@") !== false) { - for ($index=0; $index<$jmax; $index++) { - if (is_numeric($table[$i][$index])) { - $result += $table[$i][$index]; - } - } - return str_replace("@@=SUM(R)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=AVERAGE(C)@@") !== false) { - for ($index=0; $index<$imax; $index++) { - if (is_numeric($table[$index][$j])) { - $result += $table[$index][$j]; - $counter++; - } - } - $result=$result/$counter; - return str_replace("@@=AVERAGE(C)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=AVERAGE(R)@@") !== false) { - for ($index=0; $index<$jmax; $index++) { - if (is_numeric($table[$i][$index])) { - $result += $table[$i][$index]; - $counter++; - } - } - $result=$result/$counter; - return str_replace("@@=AVERAGE(R)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=MAX(C)@@") !== false) { - for ($index=0; $index<$imax; $index++) { - if (is_numeric($table[$index][$j])) { - if (!$found) { - $found=true; - $result=$table[$index][$j]; - } else { - $result = max($result, $table[$index][$j]); - } - } - } - if (!$found) { - $result=""; - } - return str_replace("@@=MAX(C)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=MAX(R)@@") !== false) { - for ($index=0; $index<$jmax; $index++) { - if (is_numeric($table[$i][$index])) { - if (!$found) { - $found=true; - $result=$table[$i][$index]; - } else { - $result = max($result, $table[$i][$index]); - } - } - } - if (!$found) { - $result=""; - } - return str_replace("@@=MAX(R)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=MIN(C)@@") !== false) { - for ($index=0; $index<$imax; $index++) { - if (is_numeric($table[$index][$j])) { - if (!$found) { - $found=true; - $result=$table[$index][$j]; - } else { - $result = min($result, $table[$index][$j]); - } - } - } - if (!$found) { - $result=""; - } - return str_replace("@@=MIN(C)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=MIN(R)@@") !== false) { - for ($index=0; $index<$jmax; $index++) { - if (is_numeric($table[$i][$index])) { - if (!$found) { - $found=true; - $result=$table[$i][$index]; - } else { - $result = min($result, $table[$i][$index]); - } - } - } - if (!$found) { - $result=""; - } - return str_replace("@@=MIN(R)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=COUNT(C)@@") !== false) { - for ($index=0; $index<$imax; $index++) { - if (!string_starts_with(trim($table[$index][$j]), "=")) { // exclude header - $counter++; - } - } - $result = $counter-1; // exclude self - return str_replace("@@=COUNT(C)@@", $result, $table[$i][$j]); - - } else if (strpos($table[$i][$j], "@@=COUNT(R)@@") !== false) { - for ($index=0; $index<$jmax; $index++) { - if (!string_starts_with(trim($table[$i][$index]), "=")) { // exclude header - $counter++; - } - } - $result = $counter-1; // exclude self - return str_replace("@@=COUNT(R)@@", $result, $table[$i][$j]); - } - - return $table[$i][$j]; -} - -/** * Remove accents from given text. */ function strip_accents($text) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |