4 * Copyright (C) 2003 Sameer D. Sahasrabuddhe
5 * Copyright (C) 2005 $ThePhpWikiProgrammingTeam
6 * Copyright (C) 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
8 * This file is part of PhpWiki.
10 * PhpWiki is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * PhpWiki is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * A PhpWiki plugin that allows insertion of tables using a richer syntax.
30 class WikiPlugin_RichTable
35 return _("RichTable");
38 function getDescription()
40 return _("Layout tables using a very rich markup style.");
43 function getDefaultArguments()
48 function run($dbi, $argstr, &$request, $basepage)
50 include_once 'lib/BlockParser.php';
51 // RichTablePlugin markup is new.
54 $lines = preg_split('/\n/', $argstr);
55 $table = HTML::table();
57 if ($lines[0][0] == '*') {
58 $line = substr(array_shift($lines), 1);
59 $attrs = parse_attributes($line);
60 foreach ($attrs as $key => $value) {
61 if (in_array($key, array("id", "class", "title", "style",
62 "bgcolor", "frame", "rules", "border",
63 "cellspacing", "cellpadding",
64 "summary", "align", "width"))
66 $table->setAttr($key, $value);
71 foreach ($lines as $line) {
72 if (substr($line, 0, 1) == "-") {
75 if (isset($content)) {
76 if (is_numeric(trim($content))) {
77 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
79 $cell->pushContent(TransformText($content, $markup, $basepage));
83 $row->pushContent($cell);
86 $table->pushContent($row);
89 $attrs = parse_attributes(substr($line, 1));
90 foreach ($attrs as $key => $value) {
91 if (in_array($key, array("id", "class", "title", "style",
92 "bgcolor", "align", "valign"))
94 $row->setAttr($key, $value);
99 if (substr($line, 0, 1) == "|" and isset($row)) {
101 if (isset ($content)) {
102 if (is_numeric(trim($content))) {
103 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
105 $cell->pushContent(TransformText($content, $markup, $basepage));
109 $row->pushContent($cell);
112 $line = substr($line, 1);
113 if ($line[0] == "*") {
114 $attrs = parse_attributes(substr($line, 1));
115 foreach ($attrs as $key => $value) {
116 if (in_array($key, array("id", "class", "title", "style",
117 "colspan", "rowspan", "width", "height",
118 "bgcolor", "align", "valign"))
120 $cell->setAttr($key, $value);
126 if (isset($row) and isset($cell)) {
127 $line = str_replace("?\>", "?>", $line);
128 $line = str_replace("\~", "~", $line);
129 if (empty($content)) $content = '';
130 $content .= $line . "\n";
135 if (isset($content)) {
136 if (is_numeric(trim($content))) {
137 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
139 $cell->pushContent(TransformText($content, $markup, $basepage));
142 $row->pushContent($cell);
144 $table->pushContent($row);
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil