]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php
2
3 /*
4  * Copyright (C) 2003 Sameer D. Sahasrabuddhe
5  * Copyright (C) 2005 $ThePhpWikiProgrammingTeam
6  * Copyright (C) 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7  *
8  * This file is part of PhpWiki.
9  *
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.
14  *
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.
19  *
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.
23 */
24
25 /**
26  * RichTablePlugin
27  * A PhpWiki plugin that allows insertion of tables using a richer syntax.
28  */
29
30 class WikiPlugin_RichTable
31     extends WikiPlugin
32 {
33     function getDescription()
34     {
35         return _("Layout tables using a very rich markup style.");
36     }
37
38     function getDefaultArguments()
39     {
40         return array();
41     }
42
43     function run($dbi, $argstr, &$request, $basepage)
44     {
45         include_once 'lib/BlockParser.php';
46         // RichTablePlugin markup is new.
47         $markup = 2.0;
48
49         $lines = preg_split('/\n/', $argstr);
50         $table = HTML::table();
51
52         if ($lines[0][0] == '*') {
53             $line = substr(array_shift($lines), 1);
54             $attrs = parse_attributes($line);
55             foreach ($attrs as $key => $value) {
56                 if (in_array($key, array("id", "class", "title", "style",
57                     "bgcolor", "frame", "rules", "border",
58                     "cellspacing", "cellpadding",
59                     "summary", "align", "width"))
60                 ) {
61                     $table->setAttr($key, $value);
62                 }
63             }
64         }
65
66         foreach ($lines as $line) {
67             if (substr($line, 0, 1) == "-") {
68                 if (isset($row)) {
69                     if (isset($cell)) {
70                         if (isset($content)) {
71                             if (is_numeric(trim($content))) {
72                                 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
73                             } else {
74                                 $cell->pushContent(TransformText($content, $markup, $basepage));
75                             }
76                             unset($content);
77                         }
78                         $row->pushContent($cell);
79                         unset($cell);
80                     }
81                     $table->pushContent($row);
82                 }
83                 $row = HTML::tr();
84                 $attrs = parse_attributes(substr($line, 1));
85                 foreach ($attrs as $key => $value) {
86                     if (in_array($key, array("id", "class", "title", "style",
87                         "bgcolor", "align", "valign"))
88                     ) {
89                         $row->setAttr($key, $value);
90                     }
91                 }
92                 continue;
93             }
94             if (substr($line, 0, 1) == "|" and isset($row)) {
95                 if (isset($cell)) {
96                     if (isset ($content)) {
97                         if (is_numeric(trim($content))) {
98                             $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
99                         } else {
100                             $cell->pushContent(TransformText($content, $markup, $basepage));
101                         }
102                         unset($content);
103                     }
104                     $row->pushContent($cell);
105                 }
106                 $cell = HTML::td();
107                 $line = substr($line, 1);
108                 if ($line[0] == "*") {
109                     $attrs = parse_attributes(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                         ) {
115                             $cell->setAttr($key, $value);
116                         }
117                     }
118                     continue;
119                 }
120             }
121             if (isset($row) and isset($cell)) {
122                 $line = str_replace("?\>", "?>", $line);
123                 $line = str_replace("\~", "~", $line);
124                 if (empty($content)) $content = '';
125                 $content .= $line . "\n";
126             }
127         }
128         if (isset($row)) {
129             if (isset($cell)) {
130                 if (isset($content)) {
131                     if (is_numeric(trim($content))) {
132                         $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
133                     } else {
134                         $cell->pushContent(TransformText($content, $markup, $basepage));
135                     }
136                 }
137                 $row->pushContent($cell);
138             }
139             $table->pushContent($row);
140         }
141         return $table;
142     }
143 }
144
145 // Local Variables:
146 // mode: php
147 // tab-width: 8
148 // c-basic-offset: 4
149 // c-hanging-comment-ender-p: nil
150 // indent-tabs-mode: nil
151 // End: