From: <sy...@us...> - 2005-12-08 19:30:15
|
Update of /cvsroot/tikiwiki/tiki/lib/wiki-plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8008/lib/wiki-plugins Modified Files: wikiplugin_split.php Log Message: edit section via {SPLIT(first=col,edit=y)}. Works only for wiki page yet Index: wikiplugin_split.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/wiki-plugins/wikiplugin_split.php,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- wikiplugin_split.php 1 Nov 2005 17:30:11 -0000 1.24 +++ wikiplugin_split.php 8 Dec 2005 19:30:04 -0000 1.25 @@ -13,10 +13,11 @@ * Both paramaters have default value 'y' * first='col': r1c1---r2c1---r3c1@@@r1c2---r2c2 (the editorial way) * first='line' (default): r1c1---r1c2@@@r2c1---r2c2 (the html table way) + * if first=col,edit=y, each section of the split is editable */ function wikiplugin_split_help() { - return tra("Split a page into rows and columns").":<br />~np~{SPLIT(joincols=>[y|n|0|1],fixedsize=>[y|n|0|1],colsize=>size1|size2|...,first=>[col|line])}".tra("row1col1")."---".tra("row1col2")."@@@".tra("row2col1")."---".tra("row2col2")."{SPLIT}~/np~"; + return tra("Split a page into rows and columns").":<br />~np~{SPLIT(joincols=>[y|n|0|1],fixedsize=>[y|n|0|1],colsize=>size1|size2|...,first=>[col|line], edit=>y|n)}".tra("row1col1")."---".tra("row1col2")."@@@".tra("row2col1")."---".tra("row2col2")."{SPLIT}~/np~"; } /* @@ -25,21 +26,26 @@ * start of new line ('\n' character - e.g. lists and headers)... such * user lines must stay with the same layout when applying * this plugin to render them properly after... + * $data = the preparsed data (plugin, code, np.... already parsed) + * $pos is the position in the object where the non-parsed data begins */ -function wikiplugin_split($data, $params) { - global $tikilib; +function wikiplugin_split($data, $params, $pos) { + global $tikilib, $tiki_p_admin_wiki; global $replacement; // Remove first <ENTER> if exists... // it may be here if present after {SPLIT()} in original text - if (substr($data, 0, 2) == "\r\n") $data = substr($data, 2); + if (substr($data, 0, 2) == "\r\n") + $data2 = substr($data, 2); + else + $data2 = $data; - extract ($params,EXTR_SKIP); + extract ($params, EXTR_SKIP); $fixedsize = (!isset($fixedsize) || $fixedsize == 'y' || $fixedsize == 1 ? true : false); $joincols = (!isset($joincols) || $joincols == 'y' || $joincols == 1 ? true : false); // Split data by rows and cells - $sections = preg_split("/@@@+/", $data); + $sections = preg_split("/@@@+/", $data2); $rows = array(); $maxcols = 0; foreach ($sections as $i) @@ -74,11 +80,15 @@ for ($i=0;$i<$maxcols;$i++) { $tdsize[$i]=floor($tdsize[$i]/$tdtotal*100); } + $tdtotaltd=floor($tdtotal/100*100); } else { - $tdsize=array_fill(0,$maxcols,$columnSize); + $tdsize=array_fill(0,$maxcols,$columnSize); + $tdtotaltd = 100; } + + if (!isset($edit)) $edit = 'n'; - $result = '<table border="0" cellpadding="0" cellspacing="0" '.($fixedsize ? ' width="100%"' : '').'>'; + $result = '<table border="0" cellpadding="0" cellspacing="0" '.($fixedsize ? ' width="'.$tdtotaltd.'%"' : '').' class="split">'; // Attention: Dont forget to remove leading empty line in section ... // it should remain from previous '---' line... @@ -104,24 +114,93 @@ $result .= "</tr>"; } - } else { - $result .= '<tr>'; - foreach ($rows as $r) { - $idx = 0; - $result .= '<td valign="top" '.($fixedsize ? ' width="'.$tdsize[$idx].'%"' : '').'>'; - foreach ($r as $i) { - if (substr($i, 0, 2) == "\r\n") - $i = substr($i, 2); - $result .= '<div class="split">'.preg_replace("/\\r\\n/", "<br />\r\n", $i).'</div>'; - } - $result .= '</td>'; + } else { // column first + if ($edit == 'y') { + global $user; + if (isset($_REQUEST['page'])) { + $type = 'wiki page'; + $object = $_REQUEST['page']; + if ($tiki_p_admin_wiki == 'y' || $tiki_p_admin == 'y') + $perm = true; + else + $perm = $tikilib->user_has_perm_on_object($user, $object, $type, 'tiki_p_edit'); + } else { // TODO: other object type + $perm = false; + } } - $result .= '</tr>'; + $ind = 0; + $result .= '<tr>'; + foreach ($rows as $r) { + $idx = 0; + $result .= '<td valign="top" '.($fixedsize ? ' width="'.$tdsize[$idx].'%"' : '').'>'; + foreach ($r as $i) { + if (substr($i, 0, 2) == "\r\n") { + $i = substr($i, 2); + $ind += 2; + } + $result .= '<div class="split">'; + if ($edit == 'y' && $perm) { + $result .= '<a href="tiki-edit_wiki_section.php?object='.$object.'&type='.$type.'&pos='.$pos.'&cell='.$idx.'">' + .'<img src="img/icons/edit.gif" alt="'.tra('edit').'" title="'.tra('edit').'" align="right" /></a>'; + $ind += strlen($i); + while (isset($data[$ind]) && ($data[$ind] == '-' || $data[$ind] == '@')) + ++$ind; + } + $result .= preg_replace("/\\r\\n/", "<br />\r\n", $i). '</div>'; + ++$idx; + } + $result .= '</td>'; + } + $result .= '</tr>'; } // Close HTML table (no \n at end!) $result .= "</table>"; return $result; } - +// find the real start and the real end of a cell +// $pos = start pos in the non parsed data of all the split cells +// $cell = cellule indice +function wikiplugin_split_cell($data, $pos, $cell) { + $start = $pos; + $end = $pos; + $no_parsed = '~np~|~pp~|\\<pre\\>|\\<PRE\\>'; + $no_parsed_end = ''; + $match = '@@@+|----*|\{SPLIT\}|\{SPLIT\(|~np~|~pp~|\\<pre\\>|\\<PRE\\>'; + while (true) { + if (!preg_match("#($match)#m", substr($data, $pos), $matches)) { + if ($cell) + $end = $start; + break; + } else { + $end = $pos + strpos(substr($data, $pos), $matches[1]); + $start_next_tag = $end + strlen($matches[1]); + if (substr($matches[1], 0, 4) == '----') { + } else if (substr($matches[1], 0, 3) == '@@@' || $matches[1] == '---') { + if (!$cell) + break; + --$cell; + if (!$cell) + $start = $start_next_tag; + } elseif ($matches[1] == $match) { + $match = '@@@+|----*|\{SPLIT\}|\{SPLIT\(|~np~|~pp~|\\<pre\\>|\\<PRE\\>'; + } elseif ($matches[1] == '{SPLIT}') { + if (!$cell) + break; + } elseif ($matches[1] == '{SPLIT(') { + $match = '{SPLIT}'; + } elseif ($matches[1] == '~np~') { + $match = '~/np~'; + } elseif ($matches[1] == '~pp~') { + $match = '~/pp~'; + } elseif ($matches[1] == '<pre>') { + $match = '</pre>'; + } elseif ($matches[1] == '<PRE>') { + $match = '</PRE>'; + } + $pos = $start_next_tag; + } + } + return array($start, $end - $start); +} ?> |