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
12 * Copyright (C) 2008 Marc-Etienne Vargenau, Alcatel-Lucent
14 * This file is part of PhpWiki.
16 * PhpWiki is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * PhpWiki is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with PhpWiki; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 // error_reporting (E_ALL & ~E_NOTICE);
33 class WikiPlugin_RichTable
37 return _("RichTable");
40 function getDescription() {
41 return _("Layout tables using a very rich markup style.");
44 function getDefaultArguments() {
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
53 function run($dbi, $argstr, &$request, $basepage) {
55 include_once("lib/BlockParser.php");
56 // RichTablePlugin markup is new.
59 $lines = preg_split('/\n/', $argstr);
60 $table = HTML::table();
62 if ($lines[0][0] == '*') {
63 $line = substr(array_shift($lines),1);
64 $attrs = $this->_parse_attr($line);
65 foreach ($attrs as $key => $value) {
66 if (in_array ($key, array("id", "class", "title", "style",
67 "bgcolor", "frame", "rules", "border",
68 "cellspacing", "cellpadding",
69 "summary", "align", "width"))) {
70 $table->setAttr($key, $value);
75 foreach ($lines as $line){
76 if (substr($line,0,1) == "-") {
79 if (isset($content)) {
80 $cell->pushContent(TransformText($content, $markup, $basepage));
83 $row->pushContent($cell);
86 $table->pushContent($row);
89 $attrs = $this->_parse_attr(substr($line,1));
90 foreach ($attrs as $key => $value) {
91 if (in_array ($key, array("id", "class", "title", "style",
92 "bgcolor", "align", "valign"))) {
93 $row->setAttr($key, $value);
98 if (substr($line,0,1) == "|" and isset($row)) {
100 if (isset ($content)) {
101 $cell->pushContent(TransformText($content, $markup, $basepage));
104 $row->pushContent($cell);
107 $line = substr($line, 1);
108 if ($line[0] == "*" ) {
109 $attrs = $this->_parse_attr(substr($line,1));
110 foreach ($attrs as $key => $value) {
111 if (in_array ($key, array("id", "class", "title", "style",
112 "colspan", "rowspan", "width", "height",
113 "bgcolor", "align", "valign"))) {
114 $cell->setAttr($key, $value);
120 if (isset($row) and isset($cell)) {
121 $line = str_replace("?\>", "?>", $line);
122 $line = str_replace("\~", "~", $line);
123 if (empty($content)) $content = '';
124 $content .= $line . "\n";
130 $cell->pushContent(TransformText($content, $markup, $basepage));
131 $row->pushContent($cell);
133 $table->pushContent($row);
138 function _parse_attr($line) {
139 // We allow attributes with or without quotes (")
140 // border=1, cellpadding="5"
141 // style="font-family: sans-serif; border-top:1px solid #dddddd;
142 // What will not work is style with comma inside, e. g.
143 // style="font-family: Verdana, Arial, Helvetica, sans-serif"
144 $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
146 foreach ($attr_chunks as $attr_pair) {
147 if (empty($attr_pair)) continue;
148 $key_val = preg_split("/\s*=\s*/", $attr_pair);
149 if (!empty($key_val[1]))
150 $options[trim($key_val[0])] = trim(str_replace("\"", "", $key_val[1]));
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil