setAttr("id", GenerateId("MediawikiTable")); if (substr($lines[0],0,2) == "{|") { // Start of table $lines[0] = substr($lines[0],2); } if (($lines[0][0] != '|') and ($lines[0][0] != '!')) { $line = array_shift($lines); $attrs = parse_attributes($line); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) { $table->setAttr($key, $value); } } } foreach ($lines as $line){ if (substr($line,0,2) == "|}") { // End of table continue; } if (substr($line,0,2) == "|-") { if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } unset($content); } $row->pushContent($cell); unset($cell); } if (isset($thead)) { $thead->pushContent($row); $table->pushContent($thead); unset($thead); $tbody = HTML::tbody(); } else { $tbody->pushContent($row); } } $row = HTML::tr(); $attrs = parse_attributes(substr($line,2)); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) { $row->setAttr($key, $value); } } continue; } // Table summary if (substr($line,0,2) == "|=") { $line = substr($line,2); $table->setAttr("summary", trim($line)); } // Table caption if (substr($line,0,2) == "|+") { $caption = HTML::caption(); $line = substr($line,2); $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); if (($pospipe !== false) && (($posbracket === false) || ($posbracket > $pospipe))) { $attrs = parse_attributes(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "align", "lang"))) { $caption->setAttr($key, $value); } } $line=substr($line, $pospipe+1); } $caption->pushContent(trim($line)); $table->pushContent($caption); } if (((substr($line,0,1) == "|") or (substr($line,0,1) == "!")) and isset($row)) { if (isset($cell)) { if (isset ($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } unset($content); } $row->pushContent($cell); } if (substr($line,0,1) == "!") { $cell = HTML::th(); // Header $thead = HTML::thead(); } else { $cell = HTML::td(); if (!isset($tbody)) $tbody = HTML::tbody(); } $line = substr($line, 1); // If there is a "|" in the line, the start of line // (before the "|") is made of attributes. // The end of the line (after the "|") is the cell content // This is not true if the pipe is inside [], {{}} or {{{}}} // | [foo|bar] // The following cases must work: // | foo // | [foo|bar] // | class="xxx" | foo // | class="xxx" | [foo|bar] // | {{tmpl|arg=val}} // | {{image.png|alt}} // | {{{ xxx | yyy }}} $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); $poscurly = strpos($line, "{"); if (($pospipe !== false) && (($posbracket === false) || ($posbracket > $pospipe)) && (($poscurly === false) || ($poscurly > $pospipe))) { $attrs = parse_attributes(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array ($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) { $cell->setAttr($key, $value); } } $line=substr($line, $pospipe+1); if (is_numeric(trim($line))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($line))); } else { $cell->pushContent(TransformText(trim($line), $markup, $basepage)); } continue; } } if (isset($row) and isset($cell)) { $line = str_replace("?\>", "?>", $line); $line = str_replace("\~", "~", $line); if (empty($content)) $content = ''; $content .= $line . "\n"; } } if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } } $row->pushContent($cell); } $tbody->pushContent($row); $table->pushContent($tbody); } return $table; } } // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>