diff options
Diffstat (limited to 'inc/html.php')
-rw-r--r-- | inc/html.php | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/inc/html.php b/inc/html.php index a6ec628cf..c2b0db17d 100644 --- a/inc/html.php +++ b/inc/html.php @@ -82,48 +82,63 @@ function html_login(){ } /** - * prints a section editing button - * used as a callback in html_secedit + * inserts section edit buttons if wanted or removes the markers * * @author Andreas Gohr <andi@splitbrain.org> */ -function html_secedit_button($matches){ - global $ID; +function html_secedit($text,$show=true){ global $INFO; - $nr = $matches[1]; - $target = strtolower($matches[2]); + $regexp = '#<!-- EDIT(\d+) ([A-Z]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; - $name = $matches[3]; - $section = $matches[4]; + if(!$INFO['writable'] || !$show || $INFO['rev']){ + return preg_replace($regexp,'',$text); + } - return "<div class='secedit editbutton_$target editbutton_$nr'>" . - html_btn('secedit',$ID,'', - array('do' => 'edit', - 'lines' => $section, - 'edittarget' => $target, - 'rev' => $INFO['lastmod']), - 'post', $name) . '</div>'; + return preg_replace_callback($regexp, + 'html_secedit_button', $text); } /** - * inserts section edit buttons if wanted or removes the markers + * prepares section edit button data for event triggering + * used as a callback in html_secedit * + * @triggers HTML_SECEDIT_BUTTON * @author Andreas Gohr <andi@splitbrain.org> */ -function html_secedit($text,$show=true){ +function html_secedit_button($matches){ + $data = array('id' => $matches[1], + 'target' => strtolower($matches[2]), + 'range' => $matches[count($matches) - 1]); + if (count($matches) === 5) { + $data['name'] = $matches[3]; + } + + return trigger_event('HTML_SECEDIT_BUTTON', $data, + 'html_secedit_get_button'); +} + +/** + * prints a section editing button + * used as default action form HTML_SECEDIT_BUTTON + * + * @author Adrian Lang <lang@cosmocode.de> + */ +function html_secedit_get_button($data) { + global $ID; global $INFO; - $regexp = '#<!-- EDIT(\d+) ([A-Z]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; + if (!isset($data['name']) || $data['name'] === '') return; - if($INFO['writable'] && $show && !$INFO['rev']){ - $text = preg_replace_callback($regexp, - 'html_secedit_button', $text); - }else{ - $text = preg_replace($regexp,'',$text); - } + $name = $data['name']; + unset($data['name']); - return $text; + return "<div class='secedit editbutton_" . $data['target'] . + " editbutton_" . $data['id'] . "'>" . + html_btn('secedit', $ID, '', + array_merge(array('do' => 'edit', + 'rev' => $INFO['lastmod']), $data), + 'post', $name) . '</div>'; } /** |