2 rcs_id('$Id: OldStyleTable.php,v 1.10 2004-06-14 11:31:39 rurban 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 border||=0 summary=""
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: $]/", '',
58 "\$Revision: 1.10 $");
61 function getDefaultArguments() {
71 function handle_plugin_args_cruft($argstr, $args) {
75 function run($dbi, $argstr, &$request, $basepage) {
77 include_once('lib/InlineParser.php');
79 $args = $this->getArgs($argstr, $request);
80 $default = $this->getDefaultArguments();
81 foreach (array('cellpadding','cellspacing','border') as $arg) {
82 if (!is_numeric($args[$arg])) {
83 $args[$arg] = $default[$arg];
86 $lines = preg_split('/\s*?\n\s*/', $argstr);
87 $table_args = array();
88 $default_args = array_keys($default);
89 foreach ($default_args as $arg) {
90 if ($args[$arg] == '' and $default[$arg] == '')
91 continue; // ignore '' arguments
92 if ($arg == 'caption')
93 $caption = $args[$arg];
95 $table_args[$arg] = $args[$arg];
97 $table = HTML::table($table_args);
99 $table->pushContent(HTML::caption(array('valign'=>'top'),$caption));
100 foreach ($lines as $line) {
103 if (strstr($line,"=")) {
104 $tmp = explode("=",$line);
105 if (in_array(trim($tmp[0]),$default_args))
109 return $this->error(fmt("Line does not begin with a '|'."));
110 $table->pushContent($this->_parse_row($line, $basepage));
116 function _parse_row ($line, $basepage) {
117 $brkt_link = "\\[ .*? [^]\s] .*? \\]";
118 $cell_content = "(?: [^[] | ".ESCAPE_CHAR."\\[ | $brkt_link )*?";
120 preg_match_all("/(\\|+) (v*) ([<>^]?) \s* ($cell_content) \s* (?=\\||\$)/x",
121 $line, $matches, PREG_SET_ORDER);
125 foreach ($matches as $m) {
128 if (strlen($m[1]) > 1)
129 $attr['colspan'] = strlen($m[1]);
130 if (strlen($m[2]) > 0)
131 $attr['rowspan'] = strlen($m[2]) + 1;
134 $attr['align'] = 'center';
135 else if ($m[3] == '>')
136 $attr['align'] = 'right';
138 $attr['align'] = 'left';
140 // Assume new-style inline markup.
141 $content = TransformInline($m[4], 2.0, $basepage);
143 $row->pushContent(HTML::td($attr, HTML::raw(' '),
144 $content, HTML::raw(' ')));
150 // $Log: not supported by cvs2svn $
151 // Revision 1.9 2004/02/17 12:11:36 rurban
152 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
154 // Revision 1.8 2004/01/24 23:37:08 rurban
155 // Support more options: caption (seperate tag), border, summary, cellpadding,
157 // Fixes some errors from the version from the mailinglist.
159 // Revision 1.7 2003/02/21 23:00:35 dairiki
160 // Fix SF bug #676309.
162 // Also fix new bugs introduced with cached markup changes.
164 // Revision 1.6 2003/02/21 04:12:06 dairiki
165 // Minor fixes for new cached markup.
167 // Revision 1.5 2003/01/18 21:48:59 carstenklapp
169 // Reformatting & tabs to spaces;
170 // Added copyleft, getVersion, getDescription, rcs_id.
173 // (c-file-style: "gnu")
178 // c-hanging-comment-ender-p: nil
179 // indent-tabs-mode: nil