* 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 getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 1.11 $"); } 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) { global $WikiTheme; 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(array('valign'=>'top'),$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; } }; // $Log: not supported by cvs2svn $ // Revision 1.10 2004/06/14 11:31:39 rurban // renamed global $Theme to $WikiTheme (gforge nameclash) // inherit PageList default options from PageList // default sortby=pagename // use options in PageList_Selectable (limit, sortby, ...) // added action revert, with button at action=diff // added option regex to WikiAdminSearchReplace // // Revision 1.9 2004/02/17 12:11:36 rurban // 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, ...) // // Revision 1.8 2004/01/24 23:37:08 rurban // Support more options: caption (seperate tag), border, summary, cellpadding, // cellspacing // Fixes some errors from the version from the mailinglist. // // Revision 1.7 2003/02/21 23:00:35 dairiki // Fix SF bug #676309. // // Also fix new bugs introduced with cached markup changes. // // Revision 1.6 2003/02/21 04:12:06 dairiki // Minor fixes for new cached markup. // // Revision 1.5 2003/01/18 21:48:59 carstenklapp // Code cleanup: // Reformatting & tabs to spaces; // Added copyleft, getVersion, getDescription, rcs_id. // // (c-file-style: "gnu") // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>