2 rcs_id('$Id: OldStyleTable.php,v 1.6 2003-02-21 04:12:06 dairiki Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
24 * OldStyleTable: Layout tables using the old table style.
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
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>></code>
38 * generates a right justified column, <code><</code> a left
39 * justified column and <code>^</code> a centered column
40 * (which is the default.)
42 * @author Geoffrey T. Dairiki
45 class WikiPlugin_OldStyleTable
49 return _("OldStyleTable");
52 function getDescription() {
53 return _("Layout tables using the old markup style.");
56 function getVersion() {
57 return preg_replace("/[Revision: $]/", '',
61 function getDefaultArguments() {
65 function run($dbi, $argstr, $request) {
67 include_once('lib/InlineParser.php');
69 $lines = preg_split('/\s*?\n\s*/', $argstr);
70 $table = HTML::table(array('cellpadding' => 1,
74 foreach ($lines as $line) {
78 return $this->error(fmt("Line does not begin with a '|'."));
79 $table->pushContent($this->_parse_row($line));
85 function _parse_row ($line) {
87 preg_match_all('/(\|+)(v*)([<>^]?)\s*(.*?)\s*(?=\||$)/',
88 $line, $matches, PREG_SET_ORDER);
92 foreach ($matches as $m) {
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;
101 $attr['align'] = 'center';
102 else if ($m[3] == '>')
103 $attr['align'] = 'right';
105 $attr['align'] = 'left';
107 // Assume new-style inline markup.
108 $content = TransformInline($m[4]);
110 $row->pushContent(HTML::td($attr, HTML::raw(' '),
111 $content, HTML::raw(' ')));
117 // $Log: not supported by cvs2svn $
118 // Revision 1.5 2003/01/18 21:48:59 carstenklapp
120 // Reformatting & tabs to spaces;
121 // Added copyleft, getVersion, getDescription, rcs_id.
124 // (c-file-style: "gnu")
129 // c-hanging-comment-ender-p: nil
130 // indent-tabs-mode: nil