6 A PhpWiki plugin that allows insertion of tables using a richer syntax
7 http://www.it.iitb.ac.in/~sameerds/phpwiki/index.php/RichTablePlugin
9 Copyright (C) 2003 Sameer D. Sahasrabuddhe
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 rcs_id('$Id: RichTable.php,v 1.2 2004-02-17 12:11:36 rurban Exp $');
29 error_reporting (E_ALL & ~E_NOTICE);
31 class WikiPlugin_RichTable
35 return _("RichTable");
38 function getDescription() {
39 return _("Layout tables using a very rich markup style.");
42 function getDefaultArguments() {
46 function getVersion() {
47 return preg_replace("/[Revision: $]/", '',
51 function run($dbi, $argstr, &$request, $basepage) {
55 $lines = preg_split('/\n/', $argstr);
56 $table = HTML::table();
58 if ($lines[0][0] == '*') {
59 $line = substr(array_shift($lines),1);
60 $attrs = $this->_parse_attr($line);
61 foreach ($attrs as $key => $value) {
62 if (in_array ($key, array("id", "class", "title", "style",
63 "bgcolor", "frame", "rules", "border",
64 "cellspacing", "cellpadding",
65 "summary", "align", "width"))) {
66 $table->setAttr($key, $value);
71 foreach ($lines as $line){
72 if ($line[0] == "-") {
75 if (isset($content)) {
76 $cell->pushContent(TransformText($content));
79 $row->pushContent($cell);
82 $table->pushContent($row);
85 $attrs = $this->_parse_attr(substr($line,1));
86 foreach ($attrs as $key => $value) {
87 if (in_array ($key, array("id", "class", "title", "style",
88 "bgcolor", "align", "valign"))) {
89 $row->setAttr($key, $value);
94 if ($line[0] == "|" and isset($row)) {
96 if (isset ($content)) {
97 $cell->pushContent(TransformText($content));
100 $row->pushContent($cell);
103 $line = substr($line, 1);
104 if ($line[0] == "*" ) {
105 $attrs = $this->_parse_attr(substr($line,1));
106 foreach ($attrs as $key => $value) {
107 if (in_array ($key, array("id", "class", "title", "style",
108 "colspan", "rowspan", "width", "height",
109 "bgcolor", "align", "valign"))) {
110 $cell->setAttr($key, $value);
116 if (isset($row) and isset($cell)) {
117 $line = str_replace("?\>", "?>", $line);
118 $line = str_replace("\~", "~", $line);
119 $content .= $line . "\n";
125 $cell->pushContent(TransformText($content));
126 $row->pushContent($cell);
128 $table->pushContent($row);
134 function _parse_attr($line) {
136 $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
137 foreach ($attr_chunks as $attr_pair) {
138 $key_val = preg_split("/\s*=\s*/", $attr_pair);
139 $options[trim($key_val[0])] = trim($key_val[1]);