1<?php
2/**
3 * Bootstrap Wrapper Action Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @copyright  (C) 2015-2020, Giuseppe Di Terlizzi
8 */
9
10
11/**
12 * Bootstrap Wrapper Action Plugin
13 *
14 * Add external CSS file to DokuWiki
15 */
16class action_plugin_bootswrapper extends DokuWiki_Action_Plugin
17{
18
19    /**
20     * Syntax with section edit
21     *
22     * @var array
23     */
24    private $section_edit_buttons = array(
25        'plugin_bootswrapper_pane',
26        'plugin_bootswrapper_panel',
27    );
28
29    /**
30     * Register events
31     *
32     * @param  Doku_Event_Handler  $controller
33     */
34    public function register(Doku_Event_Handler $controller)
35    {
36        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, '_insert_button');
37        $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, '_secedit_button');
38        $controller->register_hook('HTML_EDIT_FORMSELECTION', 'BEFORE', $this, '_editform'); // deprecated
39        $controller->register_hook('EDIT_FORM_ADDTEXTAREA', 'BEFORE', $this, '_editform'); // replacement
40    }
41
42    /**
43     * Edit Form
44     *
45     * @param  Doku_Event  &$event
46     */
47    public function _editform(Doku_Event $event)
48    {
49        if (!in_array($event->data['target'], $this->section_edit_buttons)) {
50            return;
51        }
52
53        $event->data['target'] = 'section';
54        return;
55    }
56
57    /**
58     * Set Section Edit button
59     *
60     * @param  Doku_Event  &$event
61     */
62    public function _secedit_button(Doku_Event $event)
63    {
64        global $lang;
65
66        if (!in_array($event->data['target'], $this->section_edit_buttons)) {
67            return;
68        }
69
70        $event->data['name'] = $lang['btn_secedit'] . ' - ' . ucfirst(str_replace('plugin_bootswrapper_', '', $event->data['target']));
71    }
72
73    /**
74     * Set toolbar button in edit mode
75     *
76     * @param  Doku_Event  &$event
77     */
78    public function _insert_button(Doku_Event $event, $param)
79    {
80        $event->data[] = array(
81            'type'    => 'mediapopup',
82            'title'   => 'Bootstrap Wrapper',
83            'icon'    => '../../plugins/bootswrapper/images/bootstrap.png',
84            'url'     => 'lib/plugins/bootswrapper/exe/popup.php?ns=',
85            'name'    => 'bootstrap-wrapper',
86            'options' => 'width=800,height=600,left=20,top=20,toolbar=no,menubar=no,scrollbars=yes,resizable=yes',
87            'block'   => false,
88        );
89    }
90}
91