]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php // -*-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         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         include_once 'lib/BlockParser.php';
47         // RichTablePlugin markup is new.
48         $markup = 2.0;
49
50         $lines = preg_split('/\n/', $argstr);
51         $table = HTML::table();
52
53         if ($lines[0][0] == '*') {
54             $line = substr(array_shift($lines),1);
55             $attrs = parse_attributes($line);
56             foreach ($attrs as $key => $value) {
57                 if (in_array ($key, array("id", "class", "title", "style",
58                                           "bgcolor", "frame", "rules", "border",
59                                           "cellspacing", "cellpadding",
60                                           "summary", "align", "width"))) {
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                         $row->setAttr($key, $value);
89                     }
90                 }
91                 continue;
92             }
93             if (substr($line,0,1) == "|" and isset($row)) {
94                 if (isset($cell)) {
95                     if (isset ($content)) {
96                         if (is_numeric(trim($content))) {
97                             $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
98                         } else {
99                             $cell->pushContent(TransformText($content, $markup, $basepage));
100                         }
101                         unset($content);
102                     }
103                     $row->pushContent($cell);
104                 }
105                 $cell = HTML::td();
106                 $line = substr($line, 1);
107                 if ($line[0] == "*" ) {
108                     $attrs = parse_attributes(substr($line,1));
109                     foreach ($attrs as $key => $value) {
110                         if (in_array ($key, array("id", "class", "title", "style",
111                                                   "colspan", "rowspan", "width", "height",
112                                                   "bgcolor", "align", "valign"))) {
113                             $cell->setAttr($key, $value);
114                         }
115                     }
116                     continue;
117                 }
118             }
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";
124             }
125         }
126         if (isset($row)) {
127             if (isset($cell)) {
128                 if (isset($content)) {
129                     if (is_numeric(trim($content))) {
130                         $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
131                     } else {
132                         $cell->pushContent(TransformText($content, $markup, $basepage));
133                     }
134                 }
135                 $row->pushContent($cell);
136             }
137             $table->pushContent($row);
138         }
139         return $table;
140     }
141 }
142
143 // Local Variables:
144 // mode: php
145 // tab-width: 8
146 // c-basic-offset: 4
147 // c-hanging-comment-ender-p: nil
148 // indent-tabs-mode: nil
149 // End: