2 rcs_id('$Id: RichTable.php,v 1.5 2004-06-14 11:31:39 rurban Exp $');
5 A PhpWiki plugin that allows insertion of tables using a richer syntax
6 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.
26 // error_reporting (E_ALL & ~E_NOTICE);
28 class WikiPlugin_RichTable
32 return _("RichTable");
35 function getDescription() {
36 return _("Layout tables using a very rich markup style.");
39 function getDefaultArguments() {
43 function getVersion() {
44 return preg_replace("/[Revision: $]/", '',
48 function run($dbi, $argstr, &$request, $basepage) {
50 include_once("lib/BlockParser.php");
52 $lines = preg_split('/\n/', $argstr);
53 $table = HTML::table();
55 if ($lines[0][0] == '*') {
56 $line = substr(array_shift($lines),1);
57 $attrs = $this->_parse_attr($line);
58 foreach ($attrs as $key => $value) {
59 if (in_array ($key, array("id", "class", "title", "style",
60 "bgcolor", "frame", "rules", "border",
61 "cellspacing", "cellpadding",
62 "summary", "align", "width"))) {
63 $table->setAttr($key, $value);
68 foreach ($lines as $line){
69 if (substr($line,0,1) == "-") {
72 if (isset($content)) {
73 $cell->pushContent(TransformText($content));
76 $row->pushContent($cell);
79 $table->pushContent($row);
82 $attrs = $this->_parse_attr(substr($line,1));
83 foreach ($attrs as $key => $value) {
84 if (in_array ($key, array("id", "class", "title", "style",
85 "bgcolor", "align", "valign"))) {
86 $row->setAttr($key, $value);
91 if (substr($line,0,1) == "|" and isset($row)) {
93 if (isset ($content)) {
94 $cell->pushContent(TransformText($content));
97 $row->pushContent($cell);
100 $line = substr($line, 1);
101 if ($line[0] == "*" ) {
102 $attrs = $this->_parse_attr(substr($line,1));
103 foreach ($attrs as $key => $value) {
104 if (in_array ($key, array("id", "class", "title", "style",
105 "colspan", "rowspan", "width", "height",
106 "bgcolor", "align", "valign"))) {
107 $cell->setAttr($key, $value);
113 if (isset($row) and isset($cell)) {
114 $line = str_replace("?\>", "?>", $line);
115 $line = str_replace("\~", "~", $line);
116 if (empty($content)) $content = '';
117 $content .= $line . "\n";
123 $cell->pushContent(TransformText($content));
124 $row->pushContent($cell);
126 $table->pushContent($row);
131 function _parse_attr($line) {
132 $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
134 foreach ($attr_chunks as $attr_pair) {
135 if (empty($attr_pair)) continue;
136 $key_val = preg_split("/\s*=\s*/", $attr_pair);
137 $options[trim($key_val[0])] = trim($key_val[1]);
143 // $Log: not supported by cvs2svn $
144 // Revision 1.4 2004/03/09 13:08:40 rurban
145 // fix undefined TransformText error: load BlockParser,
146 // get rid of warnings
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil