xref: /plugin/combo/action/toolbar.php (revision ccd34c918651826262d92d844f21c1430ba21c66)
1<?php
2/**
3 * Action Component
4 * Add a button in the edit toolbar
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Nicolas GERARD
8 */
9
10use ComboStrap\Resources;
11
12if (!defined('DOKU_INC')) die();
13require_once(__DIR__ . '/../class/PluginUtility.php');
14
15
16class action_plugin_combo_toolbar extends DokuWiki_Action_Plugin
17{
18
19    /**
20     * register the event handlers
21     *
22     * @author Nicolas GERARD
23     */
24    function register(Doku_Event_Handler $controller)
25    {
26        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array());
27    }
28
29    function handle_toolbar(&$event, $param)
30    {
31
32
33        $imageBase = '../../plugins/' . Resources::getRelativeImagesDirectory();
34
35        $unit = array(
36            'type' => 'format',
37            'title' => 'Insert an unit test',
38            'icon' => $imageBase . '/unit-doc-block.png',
39            'open' => '<unit name="default">\n<file lang path>\n</file>\n\t<code lang>',
40            'close' => '\n\t</code>\n\t<console>\n\t</console></unit>\n',
41            // 'key'    => $unitShortcutKey
42        );
43
44        /**
45         * This is called from the js.php with a get HTTP
46         * There is no knowledge of which page is modified
47         */
48
49        $frontmatterInsert = <<<EOF
50---json
51{
52    "canonical":"unique:name",
53    "title":"A title for the search page result engine",
54     "description":"A description for the search page result engine"
55}
56---
57EOF;
58        // https://www.dokuwiki.org/devel:event:toolbar_define
59        $frontmatter = array(
60            'type' => 'insert',
61            'title' => 'Insert a frontmatter',
62            'icon' => $imageBase . '/table-of-contents.svg',
63            'insert' => $frontmatterInsert,
64            'block' => true
65        );
66
67
68        $blockquote = array(
69            'type' => 'format',
70            'title' => 'blockquote',
71            'icon' => $imageBase . '/blockquote-icon.png',
72            'open' => '<blockquote>',
73            'close' => '</blockquote>',
74
75        );
76
77        $webcode = array(
78            'type' => 'format',
79            'title' => 'webcode',
80            'icon' => $imageBase . '/code-square.svg',
81            'open' => '<webcode name="Default" frameborder="0">\n',
82            'close' => '\n</webcode>\n'
83            //'key' => $webCodeShortcutKey
84        );
85
86        $twitter = array(
87            'type' => 'format',
88            'title' => 'twitter',
89            'icon' => $imageBase . '/twitter.svg',
90            'open' => '<blockquote>\n<cite>[[',
91            'close' => ']]</cite>\n</webcode>\n'
92            //'key' => $webCodeShortcutKey
93        );
94
95        $event->data[] = array(
96            'type' => 'picker',
97            'title' => "Choose comboStrap component",
98            'icon' => $imageBase . '/logo.svg',
99            'list' => array($frontmatter, $blockquote, $webcode, $twitter, $unit)
100        );
101
102
103
104
105        return true;
106
107
108    }
109
110}
111
112