カテゴリ | |
---|---|
サマリ | テーブルの種類を増やしたい |
バージョン | 1.4.7 |
投稿者 | gnil |
状態 | 完了 |
投稿日 | 2010-05-25 (火) 01:16:04 |
自分で作成した表のスタイルを複数使い分けたいです。
質問箱/4243の方法を試しましたが<table>のclass指定ができないので他の方法はありませんでしょうか?
if (! preg_match('/^\|(.+)\|([hHfFcC]?)$/', $text, $out)) {の部分が被っている後半の改造だと予想して、回答していますが。 -- 2010-05-25 (火) 21:46:53
if (! preg_match('/^\|(.+)\|([hHfFcC]?)$/', $text, $out)) {の部分は
if (! preg_match('/^\|(.+)\|([hHfFcCsS]?)([12]?)$/', $text, $out)) {見たいに変えればいいのですかね?
// '|'-separated table function & Factory_Table(& $root, $text) { - if (! preg_match('/^\|(.+)\|([hHfFcC]?)$/', $text, $out)) { + if (! preg_match('/^\|(.+)\|([hHfFcCsS]?)([12]?)$/', $text, $out)) { return Factory_Inline($text); } else { return new Table($out); } }
- function toString() + function toString($flag = '') { if ($this->rowspan == 0 || $this->colspan == 0) return ''; - $param = ' class="style_' . $this->tag . '"'; + $param = ' class="style_' . $this->tag . $flag . '"'; if ($this->rowspan > 1) $param .= ' rowspan="' . $this->rowspan . '"'; if ($this->colspan > 1) {
class Table extends Element { var $type; var $types; var $col; // number of column + var $style_table; + var $style_cell; function Table($out) { parent::Element(); $cells = explode('|', $out[1]); $this->col = count($cells); $this->type = strtolower($out[2]); $this->types = array($this->type); + $this->style_cell = array($out[3]); $is_template = ($this->type == 'c'); $row = array(); - foreach ($cells as $cell) - $row[] = & new TableCell($cell, $is_template); + $this->style_table = 'style_table'; + if($this->type == 's') { + $this->style_table = trim(array_shift($cells)); + for ($ncol = 0; $ncol < $this->col; $ncol++) + $row[] = & new TableCell('', $is_template); + } else { + foreach ($cells as $cell) + $row[] = & new TableCell($cell, $is_template); + } $this->elements[] = $row;
function & insert(& $obj) { $this->elements[] = $obj->elements[0]; $this->types[] = $obj->type; + $this->style_cell[] = $obj->style_cell[0]; return $this; }
// Set colspan and style $stylerow = NULL; + $stylecss = ''; foreach (array_keys($this->elements) as $nrow) { $row = & $this->elements[$nrow]; - if ($this->types[$nrow] == 'c') + if ($this->types[$nrow] == 'c') { $stylerow = & $row; + $stylecss = & $this->style_cell[$nrow]; + } else if ($stylecss != '' && $this->style_cell[$nrow] == '') { + $this->style_cell[$nrow] = $stylecss; + } $colspan = 1; foreach (array_keys($row) as $ncol) { if ($row[$ncol]->colspan == 0) {
// toString $string = ''; foreach ($parts as $type => $part) { +// $flag = 0; $part_string = ''; foreach (array_keys($this->elements) as $nrow) { if ($this->types[$nrow] != $type) continue; + +// switch ($flag) +// { +// case 1: +// ++$flag; +// break; +// +// default: +// $flag = 1; +// } + if ($this->style_cell[$nrow] == '') { +// $tmp = $flag; + $tmp = '1'; + } else { + $tmp = $this->style_cell[$nrow]; + } $row = & $this->elements[$nrow]; $row_string = ''; foreach (array_keys($row) as $ncol) - $row_string .= $row[$ncol]->toString(); + $row_string .= $row[$ncol]->toString($tmp); $part_string .= $this->wrap($row_string, 'tr'); } $string .= $this->wrap($part_string, $part); } - $string = $this->wrap($string, 'table', ' class="style_table" cellspacing="1" border="0"'); + $string = $this->wrap($string, 'table', ' class="' . + htmlspecialchars($this->style_table) . '" cellspacing="1" border="0"'); return $this->wrap($string, 'div', ' class="ie5"'); }