]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
silence undefined offset 1 msg
[SourceForge/phpwiki.git] / lib / plugin / RichTable.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RichTable.php,v 1.7 2005-05-06 17:44:24 rurban Exp $');
3 /**
4   RichTablePlugin
5   A PhpWiki plugin that allows insertion of tables using a richer syntax.
6   Src: http://www.it.iitb.ac.in/~sameerds/phpwiki/index.php/RichTablePlugin
7   Docs: http://phpwiki.org/RichTablePlugin
8 */
9 /* 
10  * Copyright (C) 2003 Sameer D. Sahasrabuddhe
11  * Copyright (C) 2005 $ThePhpWikiProgrammingTeam
12  *
13  * This file is part of PhpWiki.
14  *
15  * PhpWiki is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  * 
20  * PhpWiki is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * 
25  * You should have received a copy of the GNU General Public License
26  * along with PhpWiki; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 */
29
30 // error_reporting (E_ALL & ~E_NOTICE);
31
32 class WikiPlugin_RichTable
33 extends WikiPlugin
34 {
35     function getName() {
36         return _("RichTable");
37     }
38
39     function getDescription() {
40       return _("Layout tables using a very rich markup style.");
41     }
42
43     function getDefaultArguments() {
44         return array();
45     }
46
47     function getVersion() {
48         return preg_replace("/[Revision: $]/", '',
49                             "\$Revision: 1.7 $");
50     }
51
52     function run($dbi, $argstr, &$request, $basepage) {
53         global $WikiTheme;
54         include_once("lib/BlockParser.php");
55         // RichTablePlugin markup is new.
56         $markup = 2.0; 
57
58         $lines = preg_split('/\n/', $argstr);
59         $table = HTML::table();
60  
61         if ($lines[0][0] == '*') {
62             $line = substr(array_shift($lines),1);
63             $attrs = $this->_parse_attr($line);
64             foreach ($attrs as $key => $value) {
65                 if (in_array ($key, array("id", "class", "title", "style",
66                                           "bgcolor", "frame", "rules", "border",
67                                           "cellspacing", "cellpadding",
68                                           "summary", "align", "width"))) {
69                     $table->setAttr($key, $value);
70                 }
71             }
72         }
73         
74         foreach ($lines as $line){
75             if (substr($line,0,1) == "-") {
76                 if (isset($row)) {
77                     if (isset($cell)) {
78                         if (isset($content)) {
79                             $cell->pushContent(TransformText($content, $markup, $basepage));
80                             unset($content);
81                         }
82                         $row->pushContent($cell);
83                         unset($cell);
84                     }
85                     $table->pushContent($row);
86                 }       
87                 $row = HTML::tr();
88                 $attrs = $this->_parse_attr(substr($line,1));
89                 foreach ($attrs as $key => $value) {
90                     if (in_array ($key, array("id", "class", "title", "style",
91                                               "bgcolor", "align", "valign"))) {
92                         $row->setAttr($key, $value);
93                     }
94                 }
95                 continue;
96             }
97             if (substr($line,0,1) == "|" and isset($row)) {
98                 if (isset($cell)) {
99                     if (isset ($content)) {
100                         $cell->pushContent(TransformText($content, $markup, $basepage));
101                         unset($content);
102                     }
103                     $row->pushContent($cell);
104                 }
105                 $cell = HTML::td();
106                 $line = substr($line, 1);
107                 if ($line[0] == "*" ) {
108                     $attrs = $this->_parse_attr(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                     $cell->pushContent(TransformText($content));
130                 $row->pushContent($cell);
131             }
132             $table->pushContent($row);
133         }
134         return $table;
135     }
136
137     function _parse_attr($line) {
138         $attr_chunks = preg_split("/\s*,\s*/", strtolower($line));
139         $options = array();
140         foreach ($attr_chunks as $attr_pair) {
141             if (empty($attr_pair)) continue;
142             $key_val = preg_split("/\s*=\s*/", $attr_pair);
143             if (!empty($key_val[1]))
144                 $options[trim($key_val[0])] = trim($key_val[1]);
145         }
146         return $options;
147     }
148 }
149
150 // $Log: not supported by cvs2svn $
151 // Revision 1.6  2005/04/09 08:16:00  rurban
152 // fix RichTablePlugin embedded plugin invocation. Bug #1044245
153 //
154 // Revision 1.5  2004/06/14 11:31:39  rurban
155 // renamed global $Theme to $WikiTheme (gforge nameclash)
156 // inherit PageList default options from PageList
157 //   default sortby=pagename
158 // use options in PageList_Selectable (limit, sortby, ...)
159 // added action revert, with button at action=diff
160 // added option regex to WikiAdminSearchReplace
161 //
162 // Revision 1.4  2004/03/09 13:08:40  rurban
163 // fix undefined TransformText error: load BlockParser,
164 // get rid of warnings
165 //
166
167 // For emacs users
168 // Local Variables:
169 // mode: php
170 // tab-width: 8
171 // c-basic-offset: 4
172 // c-hanging-comment-ender-p: nil
173 // indent-tabs-mode: nil
174 // End:
175 ?>