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__ . '/../ComboStrap/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    "name":"short name",
53    "canonical":"unique:name",
54    "title":"A title for template iteration and search page engine",
55    "description":"A description for template iteration and search page engine"
56}
57---
58EOF;
59        // https://www.dokuwiki.org/devel:event:toolbar_define
60        $frontmatter = array(
61            'type' => 'insert',
62            'title' => 'Insert a frontmatter',
63            'icon' => $imageBase . '/table-of-contents.svg',
64            'insert' => $frontmatterInsert,
65            'block' => true
66        );
67
68
69        $blockquote = array(
70            'type' => 'format',
71            'title' => 'blockquote',
72            'icon' => $imageBase . '/blockquote-icon.png',
73            'open' => '<blockquote>',
74            'close' => '</blockquote>',
75
76        );
77
78        $webcode = array(
79            'type' => 'format',
80            'title' => 'webcode',
81            'icon' => $imageBase . '/code-square.svg',
82            'open' => '<webcode name="Default" frameborder="0">\n',
83            'close' => '\n</webcode>\n'
84            //'key' => $webCodeShortcutKey
85        );
86
87        $twitter = array(
88            'type' => 'format',
89            'title' => 'twitter',
90            'icon' => $imageBase . '/twitter.svg',
91            'open' => '<blockquote>\n<cite>[[',
92            'close' => ']]</cite>\n</blockquote>\n'
93            //'key' => $webCodeShortcutKey
94        );
95
96        $event->data[] = array(
97            'type' => 'picker',
98            'title' => "Choose comboStrap component",
99            'icon' => $imageBase . '/logo.svg',
100            'list' => array($frontmatter, $blockquote, $webcode, $twitter, $unit)
101        );
102
103
104
105
106        return true;
107
108
109    }
110
111}
112
113