3 class NP_Wtable extends NucleusPlugin {
7 return 'Convert table';
17 return 'http://nakahara21.com';
25 function getDescription()
27 return 'Convert table';
30 function supportsFeature($what) {
32 case 'SqlTablePrefix':
39 function getEventList()
46 function event_PreItem(&$data)
48 $this->currentItem =& $data["item"];
50 $this->currentItem->body = removeBreaks($this->currentItem->body);
51 // $this->currentItem->body = str_replace("\r\n", "\n", $this->currentItem->body);
52 $this->currentItem->body = preg_replace_callback("#\|(.*)\|\r\n#", array(&$this, 'list_table'), $this->currentItem->body);
53 $this->currentItem->body = preg_replace_callback("#\!(.*)\!#", array(&$this, 'convert_table'), $this->currentItem->body);
54 $this->currentItem->body = addBreaks($this->currentItem->body);
56 $this->currentItem->more = preg_replace_callback("#\|(.*?)\|#", array(&$this, 'convert_table'), $this->currentItem->more);
59 function list_table($text)
61 return "!" . $text[1] . "!";
64 function convert_table($text)
66 $rows = explode('!!', $text[1]);
67 for ($r =0; $r < count($rows); $r++) {
68 $cell = explode('|', $rows["$r"]);
69 for ($c = 0; $c < count($cell); $c++) {
70 $cols["$c"]["$r"] = $cell["$c"];
74 for ($c = 0; $c < count($cols); $c++) {
75 $cols["$c"] = array_reverse ($cols["$c"], TRUE);
77 // print_r($cols["$c"]);
78 foreach($cols["$c"] as $key => $val) {
81 $row["$key"]["$c"] = $val;
82 } elseif($val == '>') {
83 $row["$key"]["$c"] = $val;
84 } elseif($rowspan > 1) {
85 $row["$key"]["$c"] = '<td rowspan="' . intval($rowspan) . '">' . $val . '</td>';
88 $row["$key"]["$c"] = '<td>' . $val . '</td>';
92 $row = array_reverse ($row, TRUE);
95 for ($r = 0; $r < count($row); $r++) {
98 for ($c =0; $c < count($row["$r"]); $c++) {
99 if ($row["$r"]["$c"] == '~') {
101 } elseif ($row["$r"]["$c"] == '>') {
104 } elseif ($colspan > 1) {
105 $out .= str_replace('<td>', '<td colspan="' . intval($colspan) . '">', $row["$r"]["$c"]);
108 $out .= $row["$r"]["$c"];
115 return '<table border=1>' . $out . '</table>';