4 * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5 * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * OldStyleTable: Layout tables using the old table style.
29 * <<OldStyleTable border||=0
30 * || __Name__ |v __Cost__ |v __Notes__
31 * | __First__ | __Last__
32 * |> Jeff |< Dairiki |^ Cheap |< Not worth it
33 * |> Marco |< Polo | Cheaper |< Not available
37 * Note that multiple <code>|</code>'s lead to spanned columns,
38 * and <code>v</code>'s can be used to span rows. A <code>></code>
39 * generates a right justified column, <code><</code> a left
40 * justified column and <code>^</code> a centered column
41 * (which is the default.)
43 * @author Geoffrey T. Dairiki
46 class WikiPlugin_OldStyleTable
49 function getDescription()
51 return _("Layout tables using the old markup style.");
54 function getDefaultArguments()
64 function handle_plugin_args_cruft($argstr, $args)
69 function getWikiPageLinks($argstr, $basepage)
72 if (empty($backlinks)) {
74 $this->run($request->_dbi, $argstr, $request, $basepage);
81 * @param string $argstr
82 * @param WikiRequest $request
83 * @param string $basepage
86 function run($dbi, $argstr, &$request, $basepage)
92 include_once 'lib/InlineParser.php';
94 $args = $this->getArgs($argstr, $request);
95 $default = $this->getDefaultArguments();
96 foreach (array('cellpadding', 'cellspacing', 'border') as $arg) {
97 if (!is_numeric($args[$arg])) {
98 $args[$arg] = $default[$arg];
101 $lines = preg_split('/\s*?\n\s*/', $argstr);
102 $table_args = array();
103 $default_args = array_keys($default);
104 foreach ($default_args as $arg) {
105 if ($args[$arg] == '' and $default[$arg] == '')
106 continue; // ignore '' arguments
107 if ($arg == 'caption')
108 $caption = $args[$arg];
110 $table_args[$arg] = $args[$arg];
112 $table = HTML::table($table_args);
113 if (!empty($caption))
114 $table->pushContent(HTML::caption($caption));
115 if (preg_match("/^\s*(cellpadding|cellspacing|border|caption)/", $lines[0]))
117 foreach ($lines as $line) {
120 if (strstr($line, "=")) {
121 $tmp = explode("=", $line);
122 if (in_array(trim($tmp[0]), $default_args))
125 if ($line[0] != '|') {
126 // bogus error if argument
127 trigger_error(sprintf(_("Line %s does not begin with a '|'."), $line), E_USER_WARNING);
129 $table->pushContent($this->parse_row($line, $basepage));
136 private function parse_row($line, $basepage)
138 $bracket_link = "\\[ .*? [^]\s] .*? \\]";
139 $cell_content = "(?: [^[] | " . ESCAPE_CHAR . "\\[ | $bracket_link )*?";
141 preg_match_all("/(\\|+) (v*) ([<>^]?) \s* ($cell_content) \s* (?=\\||\$)/x",
142 $line, $matches, PREG_SET_ORDER);
146 foreach ($matches as $m) {
149 if (strlen($m[1]) > 1)
150 $attr['colspan'] = strlen($m[1]);
151 if (strlen($m[2]) > 0)
152 $attr['rowspan'] = strlen($m[2]) + 1;
155 $attr['class'] = 'align-center';
156 else if ($m[3] == '>')
157 $attr['class'] = 'align-right';
159 $attr['class'] = 'align-left';
161 $content = TransformInline($m[4], $basepage);
163 $row->pushContent(HTML::td($attr, HTML::raw(' '),
164 $content, HTML::raw(' ')));
174 // c-hanging-comment-ender-p: nil
175 // indent-tabs-mode: nil