1<?php
2/**
3 * DokuWiki Plugin nosecedit (Syntax Component)
4 *
5 *
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author  lisps
8 * @author  einhirn
9 */
10
11use dokuwiki\Extension\SyntaxPlugin;
12
13/*
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_nosecedit extends DokuWiki_Syntax_Plugin
18{
19
20    /*
21     * enable sectionedit by default
22     */
23    public function __construct()
24    {
25        global $ID;
26
27        if ($ID != "") {
28            p_set_metadata($ID,array("sectionedit"=>"on"),FALSE,TRUE);
29        }
30    }
31
32    /*
33     * What kind of syntax are we?
34     */
35    public function getType()
36    {
37        return 'substition';
38    }
39
40    /*
41     * Where to sort in?
42     */
43    public function getSort()
44    {
45        return 155;
46    }
47
48    /*
49     * Paragraph Type
50     */
51    public function getPType()
52    {
53        return 'normal';
54    }
55
56    /*
57     * Connect pattern to lexer
58     */
59    public function connectTo($mode)
60    {
61        $this->Lexer->addSpecialPattern("~~NOSECTIONEDIT~~",$mode,'plugin_nosecedit');
62    }
63
64
65    /*
66     * Handle the matches
67     */
68    public function handle($match, $state, $pos, Doku_Handler $handler)
69    {
70        global $ID;
71        return (array($ID=>TRUE));
72    }
73
74    /*
75     * Create output
76     */
77    public function render($mode, Doku_Renderer $renderer, $opt)
78    {
79        global $ID;
80
81        //save flags to metadata
82        //if($mode == 'metadata')
83        {
84            if (isset($opt[$ID])==TRUE) {
85                p_set_metadata($ID,array("sectionedit"=>"off"),TRUE,TRUE);
86            }
87            else {
88                p_set_metadata($ID,array("sectionedit"=>"on"),FALSE,TRUE);
89            }
90        }
91        return (TRUE);
92    }
93}
94//Setup VIM: ex: et ts=4 enc=utf-8 :
95