5 A PhpWiki plugin that allows insertion of tables using a richer syntax.
6 Src: http://www.it.iitb.ac.in/~sameerds/phpwiki/index.php/RichTablePlugin
7 Docs: http://phpwiki.org/RichTablePlugin
10 * Copyright (C) 2003 Sameer D. Sahasrabuddhe
11 * Copyright (C) 2005 $ThePhpWikiProgrammingTeam
13 * This file is part of PhpWiki.
15 * PhpWiki is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * PhpWiki is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with PhpWiki; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 // error_reporting (E_ALL & ~E_NOTICE);
32 class WikiPlugin_RichTable
36 return _("RichTable");
39 function getDescription() {
40 return _("Layout tables using a very rich markup style.");
43 function getDefaultArguments() {
47 function getVersion() {
48 return preg_replace("/[Revision: $]/", '',
52 function run($dbi, $argstr, &$request, $basepage) {
54 include_once("lib/BlockParser.php");
55 // RichTablePlugin markup is new.
58 $lines = preg_split('/\n/', $argstr);
59 $table = HTML::table();
61 if ($lines[0][0] == '*') {
62 $line = substr(array_shift($lines),1);
63 $attrs = $this->_parse_attr($line);
64 foreach ($attrs as $key => $value) {
65 if (in_array ($key, array("id", "class", "title", "style",
66 "bgcolor", "frame", "rules", "border",
67 "cellspacing", "cellpadding",
68 "summary", "align", "width"))) {
69 $table->setAttr($key, $value);
74 foreach ($lines as $line){
75 if (substr($line,0,1) == "-") {
78 if (isset($content)) {
79 $cell->pushContent(TransformText($content, $markup, $basepage));
82 $row->pushContent($cell);
85 $table->pushContent($row);
88 $attrs = $this->_parse_attr(substr($line,1));
89 foreach ($attrs as $key => $value) {
90 if (in_array ($key, array("id", "class", "title", "style",
91 "bgcolor", "align", "valign"))) {
92 $row->setAttr($key, $value);
97 if (substr($line,0,1) == "|" and isset($row)) {
99 if (isset ($content)) {
100 $cell->pushContent(TransformText($content, $markup, $basepage));
103 $row->pushContent($cell);
106 $line = substr($line, 1);
107 if ($line[0] == "*" ) {
108 $attrs = $this->_parse_attr(substr($line,1));
109 foreach ($attrs as $key => $value) {
110 if (in_array ($key, array("id", "class", "title", "style",
111 "colspan", "rowspan", "width", "height",
112 "bgcolor", "align", "valign"))) {
113 $cell->setAttr($key, $value);
119 if (isset($row) and isset($cell)) {
120 $line = str_replace("?\>", "?>", $line);
121 $line = str_replace("\~", "~", $line);
122 if (empty($content)) $content = '';
123 $content .= $line . "\n";
129 $cell->pushContent(TransformText($content));
130 $row->pushContent($cell);
132 $table->pushContent($row);
137 function _parse_attr($line) {
138 // We allow attributes with or without quotes (")
139 // border=1, cellpadding="5"
140 // style="font-family: sans-serif; border-top:1px solid #dddddd;
141 // What will not work is style with comma inside, e. g.
142 // style="font-family: Verdana, Arial, Helvetica, sans-serif"
143 $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
145 foreach ($attr_chunks as $attr_pair) {
146 if (empty($attr_pair)) continue;
147 $key_val = preg_split("/\s*=\s*/", $attr_pair);
148 if (!empty($key_val[1]))
149 $options[trim($key_val[0])] = trim(str_replace("\"", "", $key_val[1]));
155 // $Log: not supported by cvs2svn $
156 // Revision 1.7 2005/05/06 17:44:24 rurban
157 // silence undefined offset 1 msg
159 // Revision 1.6 2005/04/09 08:16:00 rurban
160 // fix RichTablePlugin embedded plugin invocation. Bug #1044245
162 // Revision 1.5 2004/06/14 11:31:39 rurban
163 // renamed global $Theme to $WikiTheme (gforge nameclash)
164 // inherit PageList default options from PageList
165 // default sortby=pagename
166 // use options in PageList_Selectable (limit, sortby, ...)
167 // added action revert, with button at action=diff
168 // added option regex to WikiAdminSearchReplace
170 // Revision 1.4 2004/03/09 13:08:40 rurban
171 // fix undefined TransformText error: load BlockParser,
172 // get rid of warnings
180 // c-hanging-comment-ender-p: nil
181 // indent-tabs-mode: nil