]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
Add fieldset
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4   RichTablePlugin
5   A PhpWiki plugin that allows insertion of tables using a richer syntax.
6 */
7 /* 
8  * Copyright (C) 2003 Sameer D. Sahasrabuddhe
9  * Copyright (C) 2005 $ThePhpWikiProgrammingTeam
10  * Copyright (C) 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
11  *
12  * This file is part of PhpWiki.
13  *
14  * PhpWiki is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  * 
19  * PhpWiki is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with PhpWiki; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 */
28
29 // error_reporting (E_ALL & ~E_NOTICE);
30
31 class WikiPlugin_RichTable
32 extends WikiPlugin
33 {
34     function getName() {
35         return _("RichTable");
36     }
37
38     function getDescription() {
39       return _("Layout tables using a very rich markup style.");
40     }
41
42     function getDefaultArguments() {
43         return array();
44     }
45
46     function getVersion() {
47         return preg_replace("/[Revision: $]/", '',
48                             "\$Revision$");
49     }
50
51     function run($dbi, $argstr, &$request, $basepage) {
52         global $WikiTheme;
53         include_once("lib/BlockParser.php");
54         // RichTablePlugin markup is new.
55         $markup = 2.0; 
56
57         $lines = preg_split('/\n/', $argstr);
58         $table = HTML::table();
59  
60         if ($lines[0][0] == '*') {
61             $line = substr(array_shift($lines),1);
62             $attrs = parse_attributes($line);
63             foreach ($attrs as $key => $value) {
64                 if (in_array ($key, array("id", "class", "title", "style",
65                                           "bgcolor", "frame", "rules", "border",
66                                           "cellspacing", "cellpadding",
67                                           "summary", "align", "width"))) {
68                     $table->setAttr($key, $value);
69                 }
70             }
71         }
72         
73         foreach ($lines as $line){
74             if (substr($line,0,1) == "-") {
75                 if (isset($row)) {
76                     if (isset($cell)) {
77                         if (isset($content)) {
78                             if (is_numeric(trim($content))) {
79                                 $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
80                             } else {
81                                 $cell->pushContent(TransformText($content, $markup, $basepage));
82                             }
83                             unset($content);
84                         }
85                         $row->pushContent($cell);
86                         unset($cell);
87                     }
88                     $table->pushContent($row);
89                 }       
90                 $row = HTML::tr();
91                 $attrs = parse_attributes(substr($line,1));
92                 foreach ($attrs as $key => $value) {
93                     if (in_array ($key, array("id", "class", "title", "style",
94                                               "bgcolor", "align", "valign"))) {
95                         $row->setAttr($key, $value);
96                     }
97                 }
98                 continue;
99             }
100             if (substr($line,0,1) == "|" and isset($row)) {
101                 if (isset($cell)) {
102                     if (isset ($content)) {
103                         if (is_numeric(trim($content))) {
104                             $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
105                         } else {
106                             $cell->pushContent(TransformText($content, $markup, $basepage));
107                         }
108                         unset($content);
109                     }
110                     $row->pushContent($cell);
111                 }
112                 $cell = HTML::td();
113                 $line = substr($line, 1);
114                 if ($line[0] == "*" ) {
115                     $attrs = parse_attributes(substr($line,1));
116                     foreach ($attrs as $key => $value) {
117                         if (in_array ($key, array("id", "class", "title", "style",
118                                                   "colspan", "rowspan", "width", "height",
119                                                   "bgcolor", "align", "valign"))) {
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 // For emacs users
151 // Local Variables:
152 // mode: php
153 // tab-width: 8
154 // c-basic-offset: 4
155 // c-hanging-comment-ender-p: nil
156 // indent-tabs-mode: nil
157 // End:
158 ?>