Révision | 3e2e3016390a7550c3cdc0c3cfc6f8d41d719927 (tree) |
---|---|
l'heure | 2014-11-30 10:24:01 |
Auteur | henoheno <henoheno> |
Commiter | umorigu |
BugTrack2/269: YTable(): Cleanup
@@ -654,46 +654,61 @@ class Table extends Element | ||
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | -// , title1 , title2 , title3 | |
658 | -// , cell1 , cell2 , cell3 | |
659 | -// , cell4 , cell5 , cell6 | |
657 | +// , cell1 , cell2 , cell3 | |
658 | +// , cell4 , cell5 , cell6 | |
659 | +// , cell7 , right,== | |
660 | +// ,left ,==, cell8 | |
660 | 661 | class YTable extends Element |
661 | 662 | { |
662 | - var $col; | |
663 | + var $col; // Number of columns | |
663 | 664 | |
664 | - function YTable($_value) | |
665 | + // TODO: Seems unable to show literal '==' without tricks. | |
666 | + // But it will be imcompatible. | |
667 | + // TODO: Why toString() or toXHTML() here | |
668 | + function YTable($row = array('cell1 ', ' cell2 ', ' cell3')) | |
665 | 669 | { |
666 | 670 | parent::Element(); |
667 | 671 | |
668 | - $align = $value = $matches = array(); | |
669 | - foreach($_value as $val) { | |
670 | - if (preg_match('/^(\s+)?(.+?)(\s+)?$/', $val, $matches)) { | |
671 | - $align[] =($matches[1] != '') ? | |
672 | - ((isset($matches[3]) && $matches[3] != '') ? | |
673 | - ' style="text-align:center"' : | |
674 | - ' style="text-align:right"' | |
675 | - ) : ''; | |
676 | - $value[] = $matches[2]; | |
672 | + $str = array(); | |
673 | + $col = count($row); | |
674 | + | |
675 | + $matches = $_value = $_align = array(); | |
676 | + foreach($row as $cell) { | |
677 | + if (preg_match('/^(\s+)?(.+?)(\s+)?$/', $cell, $matches)) { | |
678 | + if ($matches[2] == '==') { | |
679 | + // Colspan | |
680 | + $_value[] = FALSE; | |
681 | + $_align[] = FALSE; | |
682 | + } else { | |
683 | + $_value[] = $matches[2]; | |
684 | + if ($matches[1] == '') { | |
685 | + $_align[] = ''; // left | |
686 | + } else if (isset($matches[3])) { | |
687 | + $_align[] = 'center'; | |
688 | + } else { | |
689 | + $_align[] = 'right'; | |
690 | + } | |
691 | + } | |
677 | 692 | } else { |
678 | - $align[] = ''; | |
679 | - $value[] = $val; | |
693 | + $_value[] = $cell; | |
694 | + $_align[] = ''; | |
680 | 695 | } |
681 | 696 | } |
682 | - $this->col = count($value); | |
683 | - $colspan = array(); | |
684 | - foreach ($value as $val) | |
685 | - $colspan[] = ($val == '==') ? 0 : 1; | |
686 | - $str = ''; | |
687 | - $count = count($value); | |
688 | - for ($i = 0; $i < $count; $i++) { | |
689 | - if ($colspan[$i]) { | |
690 | - while ($i + $colspan[$i] < $count && $value[$i + $colspan[$i]] == '==') | |
691 | - $colspan[$i]++; | |
692 | - $colspan[$i] = ($colspan[$i] > 1) ? ' colspan="' . $colspan[$i] . '"' : ''; | |
693 | - $str .= '<td class="style_td"' . $align[$i] . $colspan[$i] . '>' . make_link($value[$i]) . '</td>'; | |
694 | - } | |
697 | + | |
698 | + for ($i = 0; $i < $col; $i++) { | |
699 | + if ($_value[$i] === FALSE) continue; | |
700 | + $colspan = 1; | |
701 | + while (isset($_value[$i + $colspan]) && $_value[$i + $colspan] === FALSE) ++$colspan; | |
702 | + $colspan = ($colspan > 1) ? ' colspan="' . $colspan . '"' : ''; | |
703 | + $align = $_align[$i] ? ' style="text-align:' . $_align[$i] . '"' : ''; | |
704 | + $str[] = '<td class="style_td"' . $align . $colspan . '>'; | |
705 | + $str[] = make_link($_value[$i]); | |
706 | + $str[] = '</td>'; | |
707 | + unset($_value[$i], $_align[$i]); | |
695 | 708 | } |
696 | - $this->elements[] = $str; | |
709 | + | |
710 | + $this->col = $col; | |
711 | + $this->elements[] = implode('', $str); | |
697 | 712 | } |
698 | 713 | |
699 | 714 | function canContain(& $obj) |
@@ -710,8 +725,9 @@ class YTable extends Element | ||
710 | 725 | function toString() |
711 | 726 | { |
712 | 727 | $rows = ''; |
713 | - foreach ($this->elements as $str) | |
728 | + foreach ($this->elements as $str) { | |
714 | 729 | $rows .= "\n" . '<tr class="style_tr">' . $str . '</tr>' . "\n"; |
730 | + } | |
715 | 731 | $rows = $this->wrap($rows, 'table', ' class="style_table" cellspacing="1" border="0"'); |
716 | 732 | return $this->wrap($rows, 'div', ' class="ie5"'); |
717 | 733 | } |