1<?php
2/**
3 * DokuWiki Plugin sectiontag (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  i-net software <tools@inetsoftware.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_tagsections_editbutton extends DokuWiki_Action_Plugin {
13
14    private $inited = null;
15
16    /**
17     * Registers a callback function for a given event
18     *
19     * @param Doku_Event_Handler $controller DokuWiki's event controller object
20     * @return void
21     */
22    public function register(Doku_Event_Handler $controller) {
23       $controller->register_hook('HTML_SECEDIT_BUTTON', 'AFTER', $this, 'handle_html_secedit_button');
24    }
25
26    /**
27     * [Custom event handler which performs action]
28     *
29     * @param Doku_Event $event  event object by reference
30     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
31     *                           handler was registered]
32     * @return void
33     */
34
35    public function handle_html_secedit_button(Doku_Event &$event, $param) {
36
37        // Check if already inited
38        if ( !$this->init() ) {
39            return;
40        }
41
42        // Check for correct section
43        if ( $event->data['target'] != 'section' ) {
44            return;
45        }
46
47        // Add form for tags
48        $form = new Doku_Form(array('class' => 'sectiontag__form btn_secedit'));
49        $form->addElement(form_makeButton('submit', 'sectiontag', 'add tag', array( 'range' => $event->data['range'], 'class' => 'sectiontag_button' ) ));
50        $event->result .= '<div class="sectiontag secedit editbutton_'.$event->data['secid'].'">' . $form->getForm() . '</div>';
51    }
52
53    private function init() {
54
55        if ( is_null( $inited ) ) {
56            $this->inited = (plugin_load('action', 'tag' ) != null);
57        }
58
59        return $this->inited;
60    }
61}
62
63// vim:ts=4:sw=4:et:
64