* < Jeff |< Dairiki |^ Cheap |< Not worth it * |> Marco |< Polo | Cheaper |< Not available * >> * * * Note that multiple |'s lead to spanned columns, * and v's can be used to span rows. A > * generates a right justified column, < a left * justified column and ^ a centered column * (which is the default.) * * @author Geoffrey T. Dairiki */ class WikiPlugin_OldStyleTable extends WikiPlugin { function getName() { return _("OldStyleTable"); } function getDescription() { return _("Layout tables using the old markup style."); } function getDefaultArguments() { return array( 'caption' => '', 'cellpadding' => '1', 'cellspacing' => '1', 'border' => '1', 'summary' => '', ); } function handle_plugin_args_cruft($argstr, $args) { return; } function run($dbi, $argstr, &$request, $basepage) { include_once 'lib/InlineParser.php'; $args = $this->getArgs($argstr, $request); $default = $this->getDefaultArguments(); foreach (array('cellpadding', 'cellspacing', 'border') as $arg) { if (!is_numeric($args[$arg])) { $args[$arg] = $default[$arg]; } } $lines = preg_split('/\s*?\n\s*/', $argstr); $table_args = array(); $default_args = array_keys($default); foreach ($default_args as $arg) { if ($args[$arg] == '' and $default[$arg] == '') continue; // ignore '' arguments if ($arg == 'caption') $caption = $args[$arg]; else $table_args[$arg] = $args[$arg]; } $table = HTML::table($table_args); if (!empty($caption)) $table->pushContent(HTML::caption($caption)); if (preg_match("/^\s*(cellpadding|cellspacing|border|caption|summary)/", $lines[0])) $lines[0] = ''; foreach ($lines as $line) { if (!$line) continue; if (strstr($line, "=")) { $tmp = explode("=", $line); if (in_array(trim($tmp[0]), $default_args)) continue; } if ($line[0] != '|') { // bogus error if argument trigger_error(sprintf(_("Line %s does not begin with a '|'."), $line), E_USER_WARNING); } else { $table->pushContent($this->_parse_row($line, $basepage)); } } return $table; } function _parse_row($line, $basepage) { $brkt_link = "\\[ .*? [^]\s] .*? \\]"; $cell_content = "(?: [^[] | " . ESCAPE_CHAR . "\\[ | $brkt_link )*?"; preg_match_all("/(\\|+) (v*) ([<>^]?) \s* ($cell_content) \s* (?=\\||\$)/x", $line, $matches, PREG_SET_ORDER); $row = HTML::tr(); foreach ($matches as $m) { $attr = array(); if (strlen($m[1]) > 1) $attr['colspan'] = strlen($m[1]); if (strlen($m[2]) > 0) $attr['rowspan'] = strlen($m[2]) + 1; if ($m[3] == '^') $attr['align'] = 'center'; else if ($m[3] == '>') $attr['align'] = 'right'; else $attr['align'] = 'left'; // Assume new-style inline markup. $content = TransformInline($m[4], 2.0, $basepage); $row->pushContent(HTML::td($attr, HTML::raw(' '), $content, HTML::raw(' '))); } return $row; } } // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: