]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
renamed global $Theme to $WikiTheme (gforge nameclash)
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RichTable.php,v 1.5 2004-06-14 11:31:39 rurban Exp $');
3 /**
4   RichTablePlugin
5   A PhpWiki plugin that allows insertion of tables using a richer syntax
6   http://www.it.iitb.ac.in/~sameerds/phpwiki/index.php/RichTablePlugin
7 */
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 // error_reporting (E_ALL & ~E_NOTICE);
27
28 class WikiPlugin_RichTable
29 extends WikiPlugin
30 {
31     function getName() {
32         return _("RichTable");
33     }
34
35     function getDescription() {
36       return _("Layout tables using a very rich markup style.");
37     }
38
39     function getDefaultArguments() {
40         return array();
41     }
42
43     function getVersion() {
44         return preg_replace("/[Revision: $]/", '',
45                             "\$Revision: 1.5 $");
46     }
47
48     function run($dbi, $argstr, &$request, $basepage) {
49         global $WikiTheme;
50         include_once("lib/BlockParser.php");
51
52         $lines = preg_split('/\n/', $argstr);
53         $table = HTML::table();
54  
55         if ($lines[0][0] == '*') {
56             $line = substr(array_shift($lines),1);
57             $attrs = $this->_parse_attr($line);
58             foreach ($attrs as $key => $value) {
59                 if (in_array ($key, array("id", "class", "title", "style",
60                                           "bgcolor", "frame", "rules", "border",
61                                           "cellspacing", "cellpadding",
62                                           "summary", "align", "width"))) {
63                     $table->setAttr($key, $value);
64                 }
65             }
66         }
67         
68         foreach ($lines as $line){
69             if (substr($line,0,1) == "-") {
70                 if (isset($row)) {
71                     if (isset($cell)) {
72                         if (isset($content)) {
73                             $cell->pushContent(TransformText($content));
74                             unset($content);
75                         }
76                         $row->pushContent($cell);
77                         unset($cell);
78                     }
79                     $table->pushContent($row);
80                 }       
81                 $row = HTML::tr();
82                 $attrs = $this->_parse_attr(substr($line,1));
83                 foreach ($attrs as $key => $value) {
84                     if (in_array ($key, array("id", "class", "title", "style",
85                                               "bgcolor", "align", "valign"))) {
86                         $row->setAttr($key, $value);
87                     }
88                 }
89                 continue;
90             }
91             if (substr($line,0,1) == "|" and isset($row)) {
92                 if (isset($cell)) {
93                     if (isset ($content)) {
94                         $cell->pushContent(TransformText($content));
95                         unset($content);
96                     }
97                     $row->pushContent($cell);
98                 }
99                 $cell = HTML::td();
100                 $line = substr($line, 1);
101                 if ($line[0] == "*" ) {
102                     $attrs = $this->_parse_attr(substr($line,1));
103                     foreach ($attrs as $key => $value) {
104                         if (in_array ($key, array("id", "class", "title", "style",
105                                                   "colspan", "rowspan", "width", "height",
106                                                   "bgcolor", "align", "valign"))) {
107                             $cell->setAttr($key, $value);
108                         }
109                     }
110                     continue;
111                 } 
112             } 
113             if (isset($row) and isset($cell)) {
114                 $line = str_replace("?\>", "?>", $line);
115                 $line = str_replace("\~", "~", $line);
116                 if (empty($content)) $content = '';
117                 $content .= $line . "\n";
118             }
119         }
120         if (isset($row)) {
121             if (isset($cell)) {
122                 if (isset($content))
123                     $cell->pushContent(TransformText($content));
124                 $row->pushContent($cell);
125             }
126             $table->pushContent($row);
127         }
128         return $table;
129     }
130
131     function _parse_attr($line) {
132         $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
133         $options = array();
134         foreach ($attr_chunks as $attr_pair) {
135             if (empty($attr_pair)) continue;
136             $key_val = preg_split("/\s*=\s*/", $attr_pair);
137             $options[trim($key_val[0])] = trim($key_val[1]);
138         }
139         return $options;
140     }
141 }
142
143 // $Log: not supported by cvs2svn $
144 // Revision 1.4  2004/03/09 13:08:40  rurban
145 // fix undefined TransformText error: load BlockParser,
146 // get rid of warnings
147 //
148
149 // For emacs users
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:
157 ?>