]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
Add return argument
[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 getName()
34     {
35         return _("RichTable");
36     }
37
38     function getDescription()
39     {
40         return _("Layout tables using a very rich markup style.");
41     }
42
43     function getDefaultArguments()
44     {
45         return array();
46     }
47
48     function run($dbi, $argstr, &$request, $basepage)
49     {
50         include_once 'lib/BlockParser.php';
51         // RichTablePlugin markup is new.
52         $markup = 2.0;
53
54         $lines = preg_split('/\n/', $argstr);
55         $table = HTML::table();
56
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"))
65                 ) {
66                     $table->setAttr($key, $value);
67                 }
68             }
69         }
70
71         foreach ($lines as $line) {
72             if (substr($line, 0, 1) == "-") {
73                 if (isset($row)) {
74                     if (isset($cell)) {
75                         if (isset($content)) {
76                             if (is_numeric(trim($content))) {
77                                 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
78                             } else {
79                                 $cell->pushContent(TransformText($content, $markup, $basepage));
80                             }
81                             unset($content);
82                         }
83                         $row->pushContent($cell);
84                         unset($cell);
85                     }
86                     $table->pushContent($row);
87                 }
88                 $row = HTML::tr();
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"))
93                     ) {
94                         $row->setAttr($key, $value);
95                     }
96                 }
97                 continue;
98             }
99             if (substr($line, 0, 1) == "|" and isset($row)) {
100                 if (isset($cell)) {
101                     if (isset ($content)) {
102                         if (is_numeric(trim($content))) {
103                             $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
104                         } else {
105                             $cell->pushContent(TransformText($content, $markup, $basepage));
106                         }
107                         unset($content);
108                     }
109                     $row->pushContent($cell);
110                 }
111                 $cell = HTML::td();
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"))
119                         ) {
120                             $cell->setAttr($key, $value);
121                         }
122                     }
123                     continue;
124                 }
125             }
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";
131             }
132         }
133         if (isset($row)) {
134             if (isset($cell)) {
135                 if (isset($content)) {
136                     if (is_numeric(trim($content))) {
137                         $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
138                     } else {
139                         $cell->pushContent(TransformText($content, $markup, $basepage));
140                     }
141                 }
142                 $row->pushContent($cell);
143             }
144             $table->pushContent($row);
145         }
146         return $table;
147     }
148 }
149
150 // Local Variables:
151 // mode: php
152 // tab-width: 8
153 // c-basic-offset: 4
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil
156 // End: