]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
Harmonize file footer
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
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
21  * along with PhpWiki; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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         return _("RichTable");
35     }
36
37     function getDescription() {
38       return _("Layout tables using a very rich markup style.");
39     }
40
41     function getDefaultArguments() {
42         return array();
43     }
44
45     function run($dbi, $argstr, &$request, $basepage) {
46             global $WikiTheme;
47         include_once("lib/BlockParser.php");
48         // RichTablePlugin markup is new.
49         $markup = 2.0;
50
51         $lines = preg_split('/\n/', $argstr);
52         $table = HTML::table();
53
54         if ($lines[0][0] == '*') {
55             $line = substr(array_shift($lines),1);
56             $attrs = parse_attributes($line);
57             foreach ($attrs as $key => $value) {
58                 if (in_array ($key, array("id", "class", "title", "style",
59                                           "bgcolor", "frame", "rules", "border",
60                                           "cellspacing", "cellpadding",
61                                           "summary", "align", "width"))) {
62                     $table->setAttr($key, $value);
63                 }
64             }
65         }
66
67         foreach ($lines as $line){
68             if (substr($line,0,1) == "-") {
69                 if (isset($row)) {
70                     if (isset($cell)) {
71                         if (isset($content)) {
72                             if (is_numeric(trim($content))) {
73                                 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
74                             } else {
75                                 $cell->pushContent(TransformText($content, $markup, $basepage));
76                             }
77                             unset($content);
78                         }
79                         $row->pushContent($cell);
80                         unset($cell);
81                     }
82                     $table->pushContent($row);
83                 }
84                 $row = HTML::tr();
85                 $attrs = parse_attributes(substr($line,1));
86                 foreach ($attrs as $key => $value) {
87                     if (in_array ($key, array("id", "class", "title", "style",
88                                               "bgcolor", "align", "valign"))) {
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                             $cell->setAttr($key, $value);
115                         }
116                     }
117                     continue;
118                 }
119             }
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";
125             }
126         }
127         if (isset($row)) {
128             if (isset($cell)) {
129                 if (isset($content)) {
130                     if (is_numeric(trim($content))) {
131                         $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
132                     } else {
133                         $cell->pushContent(TransformText($content, $markup, $basepage));
134                     }
135                 }
136                 $row->pushContent($cell);
137             }
138             $table->pushContent($row);
139         }
140         return $table;
141     }
142 }
143
144 // Local Variables:
145 // mode: php
146 // tab-width: 8
147 // c-basic-offset: 4
148 // c-hanging-comment-ender-p: nil
149 // indent-tabs-mode: nil
150 // End:
151 ?>