]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RichTable.php
Use parse_attributes function from stdlib
[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 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                             $cell->pushContent(TransformText($content, $markup, $basepage));
79                             unset($content);
80                         }
81                         $row->pushContent($cell);
82                         unset($cell);
83                     }
84                     $table->pushContent($row);
85                 }       
86                 $row = HTML::tr();
87                 $attrs = parse_attributes(substr($line,1));
88                 foreach ($attrs as $key => $value) {
89                     if (in_array ($key, array("id", "class", "title", "style",
90                                               "bgcolor", "align", "valign"))) {
91                         $row->setAttr($key, $value);
92                     }
93                 }
94                 continue;
95             }
96             if (substr($line,0,1) == "|" and isset($row)) {
97                 if (isset($cell)) {
98                     if (isset ($content)) {
99                         $cell->pushContent(TransformText($content, $markup, $basepage));
100                         unset($content);
101                     }
102                     $row->pushContent($cell);
103                 }
104                 $cell = HTML::td();
105                 $line = substr($line, 1);
106                 if ($line[0] == "*" ) {
107                     $attrs = parse_attributes(substr($line,1));
108                     foreach ($attrs as $key => $value) {
109                         if (in_array ($key, array("id", "class", "title", "style",
110                                                   "colspan", "rowspan", "width", "height",
111                                                   "bgcolor", "align", "valign"))) {
112                             $cell->setAttr($key, $value);
113                         }
114                     }
115                     continue;
116                 } 
117             } 
118             if (isset($row) and isset($cell)) {
119                 $line = str_replace("?\>", "?>", $line);
120                 $line = str_replace("\~", "~", $line);
121                 if (empty($content)) $content = '';
122                 $content .= $line . "\n";
123             }
124         }
125         if (isset($row)) {
126             if (isset($cell)) {
127                 if (isset($content))
128                     $cell->pushContent(TransformText($content, $markup, $basepage));
129                 $row->pushContent($cell);
130             }
131             $table->pushContent($row);
132         }
133         return $table;
134     }
135 }
136
137 // For emacs users
138 // Local Variables:
139 // mode: php
140 // tab-width: 8
141 // c-basic-offset: 4
142 // c-hanging-comment-ender-p: nil
143 // indent-tabs-mode: nil
144 // End:
145 ?>