5 | aaaa | bbbb | cccc | eeee |
6 | 1... | 2... | 3... | 4... |
7 | ... | ... | ... | ... |
10 Will render the table as usual, but provide a [TableEditor] button,
11 which rerenders the table cells with lots of <textarea>s and another
12 [Save] button for easier editing.
14 While this feature was meant for large tables, it may not work out
15 that well for some browsers - because they often aren't prepared for
16 more than a few <textarea> and other <form> <input> fields.
20 $ewiki_plugins["mpi"]["tableeditor"] = "ewiki_mpi_tableeditor";
21 function ewiki_mpi_tableeditor($action, $args, &$iii, &$s) {
23 global $ewiki_id, $ewiki_data;
26 $rel = 5/2; // favoured ratio width to height
27 $SEP = "|"; // table cell separator ("|", or "||" for other Wikis);
30 $w_stretch = 1.17; // + 17%
35 #-- analyze current table for cell sizes
37 foreach (explode("\n", trim($args["_"])) as $row) {
38 $t[] = explode($SEP, trim(trim($row), $SEP));
44 for ($row=0; $row<$y; $row++) {
45 for ($col=0; $col<$x; $col++) {
46 $len = strlen($t[$row][$col]);
52 $h = max((int) ($len/$w), $h_min);
53 $w = (int) ($w * $w_stretch);
57 $t_widths[$col] = max($t_widths[$col], $w);
58 $t_heights[$row] = max($t_heights[$row], $h);
63 #-- store -----------------------------------------------------------
64 $o = '<div class="mpi TableEditor">';
65 if ($_REQUEST["te_save"]) {
67 $data = ewiki_db::GET($ewiki_id);
68 if ($data && ($_REQUEST["te_d_ver"] == $data["version"])) {
70 if (!preg_match_all('/<\?plugin:?\s*TableEditor/i', $data["content"], $uu)) {
71 $o .= "Could not detect the exact position of the TableEditor inside the page. Not saved.<br />";
73 elseif (count($uu[0]) >= 2) {
74 $o .= "There can only be <b>one</b> TableEditor call in a page!<br />";
78 $t = $_REQUEST["te_d"];
79 foreach ($t as $y=>$row) {
81 foreach ($row as $x=>$cell) {
82 $t[$y][$x] = trim(strtr($cell, "\r\n\t\f", " "));
83 $empty = $empty && empty($t[$y][$x]);
89 $src .= "$SEP " . implode(" $SEP ", $t[$y]) . " $SEP\n";
92 $data["content"] = preg_replace(
93 '/<\?plugin:?\s*TableEditor.+?\?>/is',
94 "<?plugin TableEditor\n\n$src\n?>",
97 ewiki_data_update($data);
100 ewiki_db::WRITE($data);
105 $o .= ewiki_t("ERRVERSIONSAVE") . "<br />\n";
110 #-- output start ----------------------------------------------------
111 $o .= '<form action="'.$_SERVER["REQUEST_URI"].'" method="POST" enctype="multipart/form-data">'
112 . '<input type="hidden" name="te_d_ver" value="'.($ewiki_data["version"]).'">'
113 . '<input type="hidden" name="id" value="'.htmlentities($ewiki_id).'">';
115 #-- print <textarea> table variant
116 if ($_REQUEST["te_load"]) {
117 $o .= '<input type="submit" name="te_save" value="SaveTable"><br />';
118 $o .= '<table border="1" cellspacing="1" cellpadding="2">';
119 if ($add_empty_row) {
122 for ($row=0; $row<$y; $row++) {
123 for ($col=0; $col<$x; $col++) {
124 $t[$row][$col] = "<textarea style=\"border:none;background:transparent;\" name=\"te_d[$row][$col]\" cols=\"$t_widths[$col]\" rows=\"$t_heights[$row]\" wrap=\"soft\">"
125 . htmlentities(trim($t[$row][$col]))
128 $o .= '<tr><td>' . implode('</td><td>', $t[$row]) . '</td></tr>' . "\n";
133 #-- reconvert into WikiMarkup, and insert into $iii
135 #-- insert <html> form at current position
136 $o .= '<input type="submit" name="te_load" value="TableEditor"><br />';
138 $iii[$in][0] = "WILL BE REPLACED with \$o...";
140 #-- mk table markup, insert into $iii
142 foreach ($t as $row) {
143 $src .= "$SEP " . implode(" $SEP ", $row) . " $SEP\n";
147 array_slice($iii, 0, $in+1),
148 array(array($src, 0x137F, "core")),
149 array_slice($iii, $in+1)
152 // the following return($o); will insert the <form> into
153 // the current input buffer $iii[$in][0] later
156 $o .= "</form></div>\n";