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
10
11require_once(__DIR__ . '/../vendor/autoload.php');
12
13
14class action_plugin_combo_toolbar extends DokuWiki_Action_Plugin
15{
16
17    /**
18     * register the event handlers
19     *
20     * @author Nicolas GERARD
21     */
22    function register(Doku_Event_Handler $controller)
23    {
24        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array());
25    }
26
27    function handle_toolbar(&$event, $param): bool
28    {
29
30        /**
31         * Relative path against
32         * DOKUBASE/lib/images/toolbar/
33         */
34        $imageBase = '../../plugins/combo/resources/images';
35
36        $unit = array(
37            'type' => 'format',
38            'title' => 'Insert an unit test',
39            'icon' => $imageBase . '/unit-doc-block.png',
40            'open' => '<unit name="default">\n<file lang path>\n</file>\n\t<code lang>',
41            'close' => '\n\t</code>\n\t<console>\n\t</console></unit>\n',
42            // 'key'    => $unitShortcutKey
43        );
44
45        /**
46         * This is called from the js.php with a get HTTP
47         * There is no knowledge of which page is modified
48         */
49
50        $frontmatterInsert = <<<EOF
51---json
52{
53    "name":"short name",
54    "canonical":"unique:name",
55    "title":"A title for template iteration and search page engine",
56    "description":"A description for template iteration and search page engine"
57}
58---
59EOF;
60        // https://www.dokuwiki.org/devel:event:toolbar_define
61        $frontmatter = array(
62            'type' => 'insert',
63            'title' => 'Insert a frontmatter',
64            'icon' => $imageBase . '/table-of-contents.svg',
65            'insert' => $frontmatterInsert,
66            'block' => true
67        );
68
69
70        $blockquote = array(
71            'type' => 'format',
72            'title' => 'blockquote',
73            'icon' => $imageBase . '/blockquote-icon.png',
74            'open' => '<blockquote>',
75            'close' => '</blockquote>',
76
77        );
78
79        $webcode = array(
80            'type' => 'format',
81            'title' => 'webcode',
82            'icon' => $imageBase . '/code-square.svg',
83            'open' => '<webcode>\n',
84            'close' => '\n</webcode>\n'
85            //'key' => $webCodeShortcutKey
86        );
87
88        $twitter = array(
89            'type' => 'format',
90            'title' => 'twitter',
91            'icon' => $imageBase . '/twitter.svg',
92            'open' => '<blockquote>\n<cite>[[',
93            'close' => ']]</cite>\n</blockquote>\n'
94            //'key' => $webCodeShortcutKey
95        );
96
97        $event->data[] = array(
98            'type' => 'picker',
99            'title' => "Choose comboStrap component",
100            'icon' => $imageBase . '/logo.svg',
101            'list' => array($frontmatter, $blockquote, $webcode, $twitter, $unit)
102        );
103
104
105
106
107        return true;
108
109
110    }
111
112}
113
114