]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
don't cache this at all
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php 
2
3 /* 
4
5   RichTablePlugin
6   A PhpWiki plugin that allows insertion of tables using a richer syntax
7   http://www.it.iitb.ac.in/~sameerds/phpwiki/index.php/RichTablePlugin
8  
9   Copyright (C) 2003 Sameer D. Sahasrabuddhe
10   
11   This program is free software; you can redistribute it and/or
12   modify it under the terms of the GNU General Public License
13   as published by the Free Software Foundation; either version 2
14   of the License, or (at your option) any later version.
15
16   This program is distributed in the hope that it will be useful,
17   but WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   GNU General Public License for more details.
20
21   You should have received a copy of the GNU General Public License
22   along with this program; if not, write to the Free Software
23   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
25 */
26
27 rcs_id('$Id: RichTable.php,v 1.2 2004-02-17 12:11:36 rurban Exp $');
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: 1.2 $");
49     }
50
51     function run($dbi, $argstr, &$request, $basepage) {
52
53         global $Theme;
54
55         $lines = preg_split('/\n/', $argstr);
56         $table = HTML::table();
57  
58                 if ($lines[0][0] == '*') {
59                         $line = substr(array_shift($lines),1);
60                         $attrs = $this->_parse_attr($line);
61                         foreach ($attrs as $key => $value) {
62                                 if (in_array ($key, array("id", "class", "title", "style",
63                                                                 "bgcolor", "frame", "rules", "border",
64                                                                 "cellspacing", "cellpadding",
65                                                                 "summary", "align", "width"))) {
66                                         $table->setAttr($key, $value);
67                                 }
68                         }
69                 }
70
71                 foreach ($lines as $line){
72                         if ($line[0] == "-") {
73                                 if (isset($row)) {
74                                         if (isset($cell)) {
75                                                 if (isset($content)) {
76                                                         $cell->pushContent(TransformText($content));
77                                                         unset($content);
78                                                 }
79                                                 $row->pushContent($cell);
80                                                 unset($cell);
81                                         }
82                                         $table->pushContent($row);
83                                 }       
84                                 $row = HTML::tr();
85                                 $attrs = $this->_parse_attr(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 ($line[0] == "|" and isset($row)) {
95                                 if (isset($cell)) {
96                                         if (isset ($content)) {
97                                                 $cell->pushContent(TransformText($content));
98                                                 unset($content);
99                                         }
100                                         $row->pushContent($cell);
101                                 }
102                                 $cell = HTML::td();
103                                 $line = substr($line, 1);
104                                 if ($line[0] == "*" ) {
105                                         $attrs = $this->_parse_attr(substr($line,1));
106                                         foreach ($attrs as $key => $value) {
107                                                 if (in_array ($key, array("id", "class", "title", "style",
108                                                                                         "colspan", "rowspan", "width", "height",
109                                                                                         "bgcolor", "align", "valign"))) {
110                                                         $cell->setAttr($key, $value);
111                                                 }
112                                         }
113                                         continue;
114                                 } 
115                         } 
116                         if (isset($row) and isset($cell)) {
117                                 $line = str_replace("?\>", "?>", $line);
118                                 $line = str_replace("\~", "~", $line);
119                                 $content .= $line . "\n";
120                         }
121                 }
122                 if (isset($row)) {
123                         if (isset($cell)) {
124                                 if (isset($content))
125                                         $cell->pushContent(TransformText($content));
126                                 $row->pushContent($cell);
127                         }
128                         $table->pushContent($row);
129                 }
130
131                 return $table;
132         }
133
134         function _parse_attr($line) {
135
136                 $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
137                 foreach ($attr_chunks as $attr_pair) {
138                         $key_val = preg_split("/\s*=\s*/", $attr_pair);
139                         $options[trim($key_val[0])] = trim($key_val[1]);
140                 }
141                 return $options;
142         }
143 };
144
145 ?>