]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/OldStyleTable.php
Minor fixes for new cached markup.
[SourceForge/phpwiki.git] / lib / plugin / OldStyleTable.php
1 <?php // -*-php-*-
2 rcs_id('$Id: OldStyleTable.php,v 1.6 2003-02-21 04:12:06 dairiki Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * OldStyleTable: Layout tables using the old table style.
25  *
26  * Usage:
27  * <pre>
28  *  <?plugin OldStyleTable
29  *  ||  __Name__               |v __Cost__   |v __Notes__
30  *  | __First__   | __Last__
31  *  |> Jeff       |< Dairiki   |^  Cheap     |< Not worth it
32  *  |> Marco      |< Polo      | Cheaper     |< Not available
33  *  ?>
34  * </pre>
35  *
36  * Note that multiple <code>|</code>'s lead to spanned columns,
37  * and <code>v</code>'s can be used to span rows.  A <code>&gt;</code>
38  * generates a right justified column, <code>&lt;</code> a left
39  * justified column and <code>^</code> a centered column
40  * (which is the default.)
41  *
42  * @author Geoffrey T. Dairiki
43  */
44
45 class WikiPlugin_OldStyleTable
46 extends WikiPlugin
47 {
48     function getName() {
49         return _("OldStyleTable");
50     }
51
52     function getDescription() {
53       return _("Layout tables using the old markup style.");
54     }
55
56     function getVersion() {
57         return preg_replace("/[Revision: $]/", '',
58                             "\$Revision: 1.6 $");
59     }
60
61     function getDefaultArguments() {
62         return array();
63     }
64
65     function run($dbi, $argstr, $request) {
66         global $Theme;
67         include_once('lib/InlineParser.php');
68         
69         $lines = preg_split('/\s*?\n\s*/', $argstr);
70         $table = HTML::table(array('cellpadding' => 1,
71                                    'cellspacing' => 1,
72                                    'border' => 1));
73
74         foreach ($lines as $line) {
75             if (!$line)
76                 continue;
77             if ($line[0] != '|')
78                 return $this->error(fmt("Line does not begin with a '|'."));
79             $table->pushContent($this->_parse_row($line));
80         }
81
82         return $table;
83     }
84
85     function _parse_row ($line) {
86
87         preg_match_all('/(\|+)(v*)([<>^]?)\s*(.*?)\s*(?=\||$)/',
88                        $line, $matches, PREG_SET_ORDER);
89
90         $row = HTML::tr();
91
92         foreach ($matches as $m) {
93             $attr = array();
94
95             if (strlen($m[1]) > 1)
96                 $attr['colspan'] = strlen($m[1]);
97             if (strlen($m[2]) > 0)
98                 $attr['rowspan'] = strlen($m[2]) + 1;
99
100             if ($m[3] == '^')
101                 $attr['align'] = 'center';
102             else if ($m[3] == '>')
103                 $attr['align'] = 'right';
104             else
105                 $attr['align'] = 'left';
106
107             // Assume new-style inline markup.
108             $content = TransformInline($m[4]);
109
110             $row->pushContent(HTML::td($attr, HTML::raw('&nbsp;'),
111                                        $content, HTML::raw('&nbsp;')));
112         }
113         return $row;
114     }
115 };
116
117 // $Log: not supported by cvs2svn $
118 // Revision 1.5  2003/01/18 21:48:59  carstenklapp
119 // Code cleanup:
120 // Reformatting & tabs to spaces;
121 // Added copyleft, getVersion, getDescription, rcs_id.
122 //
123
124 // (c-file-style: "gnu")
125 // Local Variables:
126 // mode: php
127 // tab-width: 8
128 // c-basic-offset: 4
129 // c-hanging-comment-ender-p: nil
130 // indent-tabs-mode: nil
131 // End:
132 ?>