DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:section_editor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devel:section_editor [2013-11-02 02:16]
Klap-in
devel:section_editor [2018-04-06 21:42]
LarsDW223 Update for upcoming release "Greebo"
Line 7: Line 7:
 The XHTML renderer provides two methods for the DIV section edit marking: The XHTML renderer provides two methods for the DIV section edit marking:
  
-  * [[xref>startSectionEdit()|startSectionEdit($bytepos_start, $section_type, $section_title = null)]] \\ Returns a classname and save the position. +  * [[xref>startSectionEdit()|startSectionEdit($start, $data)]] \\ Returns a classname and save the position. 
-  * [[xref>finishSectionEdit()|finishSectionEdit($bytepos_end = null)]] \\ Places a marker with data about this editable section.+  * [[xref>finishSectionEdit()|finishSectionEdit($end = null, $hid = null)]] \\ Places a marker with data about this editable section.
  
 These are used to create markers in the xhtml output of the renderer and after the render is done, a replacement or remove of the markers by [[xref>html_secedit|html_secedit($text,$show=true)]] is executed. These are used to create markers in the xhtml output of the renderer and after the render is done, a replacement or remove of the markers by [[xref>html_secedit|html_secedit($text,$show=true)]] is executed.
  
 Note that ''finishSectionEdit()'' assumes correctly nested edit sections. To use this methods, you will need to save your byte positions in your ''handle()'' method of your syntax plugin. Note that ''finishSectionEdit()'' assumes correctly nested edit sections. To use this methods, you will need to save your byte positions in your ''handle()'' method of your syntax plugin.
 +
 +Before DokuWiki release "Greebo" the method signatures were different:
 +
 +  * startSectionEdit($bytepos_start, $section_type, $section_title = null)
 +  * finishSectionEdit($bytepos_end = null)
 +
 +But do not worry. You can easily write backwards compatible code by checking the definition of ''SEC_EDIT_PATTERN'' as done in the example code below.
  
 A step-by-step example for a syntax plugin: A step-by-step example for a syntax plugin:
  
 <file php syntax.php> <file php syntax.php>
-    function render($format, &$renderer, $data) {+    public function render($format, Doku_Renderer $renderer, $data) {
         $class = '';         $class = '';
         // Add section edit infos only in XHTML renderers which are         // Add section edit infos only in XHTML renderers which are
         // sufficiently new         // sufficiently new
         if ($format === 'xhtml' && method_exists($renderer, 'startSectionEdit')) {         if ($format === 'xhtml' && method_exists($renderer, 'startSectionEdit')) {
-            // FIXME: Insert plugin name here as section type +            // Prepare section edit data in a backwards compatible way. 
-            // If this section has a distinguishable name, you may add it to +            // FIXME: Insert plugin name here as 'target' (previously section type) 
-            // the method call as well+            $sectionEditData = ['target' => 'plugin_exampleplugin']; 
 +            if (!defined('SEC_EDIT_PATTERN')) { 
 +                // backwards-compatibility for Frusterick Manners (2017-02-19) 
 +                $sectionEditData = 'plugin_exampleplugin'; 
 +            } 
 + 
 +            /* @var Doku_Renderer_xhtml $renderer */
             $class = $renderer->startSectionEdit($data['bytepos_start'],             $class = $renderer->startSectionEdit($data['bytepos_start'],
-                                                 'plugin_exampleplugin');+                                                 $sectionEditData); 
 +        } 
 +        $renderer->doc .= '<div class="' . $class . '">'; 
 + 
 +        // FIXME: Put your content here 
 + 
 +        $renderer->doc .= '</div>'; 
 +        // Add section edit infos only in XHTML renderers which are 
 +        // sufficiently new 
 +        if ($format === 'xhtml' && 
 +            method_exists($renderer, 'finishSectionEdit')) { 
 +            /* @var Doku_Renderer_xhtml $renderer */ 
 +            $renderer->finishSectionEdit($data['bytepos_end']); 
 +        } 
 +    } 
 +</file> 
 + 
 +If the section of your plugin has a distinguishable name, you may add it to the method call as well. In this case the old and new method signatures are to different to achieve backwards compatibility by just assigning different values to ''$sectionEditData''. It requires two different method calls: 
 + 
 +<file php syntax.php> 
 +    public function render($format, Doku_Renderer $renderer, $data) { 
 +        $class = ''; 
 +        // Add section edit infos only in XHTML renderers which are 
 +        // sufficiently new 
 +        if ($format === 'xhtml' && method_exists($renderer, 'startSectionEdit')) { 
 +            // Call 'startSectionEdit' in two different ways... 
 +            if (defined('SEC_EDIT_PATTERN')) { 
 +                // FIXME: Insert plugin name here as 'target' 
 +                // and section name as 'name' 
 +                $sectionEditData = ['target' => 'plugin_exampleplugin', 
 +                                    'name' => 'section-name']; 
 + 
 +                /* @var Doku_Renderer_xhtml $renderer */ 
 +                $class = $renderer->startSectionEdit($data['bytepos_start'], 
 +                                                     $sectionEditData); 
 +            } else { 
 +                // backwards-compatibility for Frusterick Manners (2017-02-19) 
 +                // FIXME: Insert plugin name here as section type 
 +                // and section name as title 
 +                /* @var Doku_Renderer_xhtml $renderer */ 
 +                $class = $renderer->startSectionEdit($data['bytepos_start'], 
 +                             'plugin_exampleplugin', 'section-name'); 
 +            }
         }         }
         $renderer->doc .= '<div class="' . $class . '">';         $renderer->doc .= '<div class="' . $class . '">';
Line 37: Line 92:
         if ($format === 'xhtml' &&         if ($format === 'xhtml' &&
             method_exists($renderer, 'finishSectionEdit')) {             method_exists($renderer, 'finishSectionEdit')) {
 +            /* @var Doku_Renderer_xhtml $renderer */
             $renderer->finishSectionEdit($data['bytepos_end']);             $renderer->finishSectionEdit($data['bytepos_end']);
         }         }
Line 45: Line 101:
  
 <file php syntax.php> <file php syntax.php>
-    function handle($match, $state, $pos, &$handler) {+    public function handle($match, $state, $pos, Doku_Handler $handler) {
         $data = array();         $data = array();
  
Line 58: Line 114:
  
 <file php action.php> <file php action.php>
-    function register(Doku_Event_Handler $controller) {+    public function register(Doku_Event_Handler $controller) {
         $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');         $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');
     }     }
  
-    function _editbutton(&$event, $param) {+    public function _editbutton(Doku_Event $event, $param) {
         // FIXME: Insert plugin name         // FIXME: Insert plugin name
         if ($event->data['target'] !== 'plugin_exampleplugin') {         if ($event->data['target'] !== 'plugin_exampleplugin') {
Line 94: Line 150:
  
 <file php action.php> <file php action.php>
-    function register(Doku_Event_Handler $controller) {+    public function register(Doku_Event_Handler $controller) {
         $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');         $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');
         $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, '_editform');         $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, '_editform');
     }     }
  
-    function _editform(&$event, $param) {+    public function _editform(Doku_Event $event, $param) {
         global $TEXT;         global $TEXT;
         // FIXME: Insert plugin name         // FIXME: Insert plugin name
Line 128: Line 184:
  
 <file php action.php> <file php action.php>
-    function register(Doku_Event_Handler $controller) {+    public function register(Doku_Event_Handler $controller) {
         $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');         $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_editbutton');
         $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, '_editform');         $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, '_editform');
Line 134: Line 190:
     }     }
  
-    function _handle_edit_post($event) {+    public function _handle_edit_post(Doku_Event $event) {
         // FIXME: Insert the name of a form field you use         // FIXME: Insert the name of a form field you use
         if (!isset($_POST['some_of_the_form_fields_you_use'])) {         if (!isset($_POST['some_of_the_form_fields_you_use'])) {
devel/section_editor.txt · Last modified: 2018-04-06 21:42 by LarsDW223