From b081e262b17e0409d75b608f15192588cd99217c Mon Sep 17 00:00:00 2001
From: Adrian Lang <lang@cosmocode.de>
Date: Thu, 19 Nov 2009 14:57:35 +0100
Subject: [PATCH] Dynamically create edit buttons for parts of a page

darcs-hash:20091119135735-e4919-3bc4872d1b1f8236571f936406db15bb0018610c.gz
---
 inc/html.php | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/inc/html.php b/inc/html.php
index 29dddbe74..48d4370dc 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -91,14 +91,18 @@ function html_secedit_button($matches){
     global $ID;
     global $INFO;
 
-    $section = $matches[2];
-    $name = $matches[1];
+    $edittarget = ($matches[1] === 'SECTION') ? 'plain' :
+                  strtolower($matches[1]);
+
+    $section = $matches[3];
+    $name = $matches[2];
 
     $secedit  = '';
     $secedit .= '<div class="secedit">';
     $secedit .= html_btn('secedit',$ID,'',
             array('do'      => 'edit',
-                'lines'   => "$section",
+                'lines'   => $section,
+                'edittarget' => $edittarget,
                 'rev' => $INFO['lastmod']),
             'post', $name);
     $secedit .= '</div>';
@@ -113,11 +117,13 @@ function html_secedit_button($matches){
 function html_secedit($text,$show=true){
     global $INFO;
 
+    $regexp = '#<!-- ([A-Z]+) (?:"(.*)" )?\[(\d+-\d*)\] -->#';
+
     if($INFO['writable'] && $show && !$INFO['rev']){
-        $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
+        $text = preg_replace_callback($regexp,
                 'html_secedit_button', $text);
     }else{
-        $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
+        $text = preg_replace($regexp,'',$text);
     }
 
     return $text;
-- 
GitLab