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
33 function getDescription()
35 return _("Layout tables using a very rich markup style.");
38 function getDefaultArguments()
43 function run($dbi, $argstr, &$request, $basepage)
45 include_once 'lib/BlockParser.php';
47 $lines = preg_split('/\n/', $argstr);
48 $table = HTML::table();
50 if ($lines[0][0] == '*') {
51 $line = substr(array_shift($lines), 1);
52 $attrs = parse_attributes($line);
53 foreach ($attrs as $key => $value) {
54 if (in_array($key, array("id", "class", "title", "style",
55 "bgcolor", "frame", "rules", "border",
56 "cellspacing", "cellpadding",
57 "summary", "align", "width"))
59 $table->setAttr($key, $value);
64 foreach ($lines as $line) {
65 if (substr($line, 0, 1) == "-") {
68 if (isset($content)) {
69 if (is_numeric(trim($content))) {
70 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
72 $cell->pushContent(TransformText($content, $basepage));
76 $row->pushContent($cell);
79 $table->pushContent($row);
82 $attrs = parse_attributes(substr($line, 1));
83 foreach ($attrs as $key => $value) {
84 if (in_array($key, array("id", "class", "title", "style",
85 "bgcolor", "align", "valign"))
87 $row->setAttr($key, $value);
92 if (substr($line, 0, 1) == "|" and isset($row)) {
94 if (isset ($content)) {
95 if (is_numeric(trim($content))) {
96 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
98 $cell->pushContent(TransformText($content, $basepage));
102 $row->pushContent($cell);
105 $line = substr($line, 1);
106 if ($line[0] == "*") {
107 $attrs = parse_attributes(substr($line, 1));
108 foreach ($attrs as $key => $value) {
109 if (in_array($key, array("id", "class", "title", "style",
110 "colspan", "rowspan", "width", "height",
111 "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";
128 if (isset($content)) {
129 if (is_numeric(trim($content))) {
130 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
132 $cell->pushContent(TransformText($content, $basepage));
135 $row->pushContent($cell);
137 $table->pushContent($row);
147 // c-hanging-comment-ender-p: nil
148 // indent-tabs-mode: nil