xref: /template/strap/action/toolbar.php (revision 32b85071e019dd3646a67c17fac4051338e495eb)
1007225e5Sgerardnico<?php
2007225e5Sgerardnico/**
3007225e5Sgerardnico * Action Component
4007225e5Sgerardnico * Add a button in the edit toolbar
5007225e5Sgerardnico *
6007225e5Sgerardnico * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7007225e5Sgerardnico * @author     Nicolas GERARD
8007225e5Sgerardnico */
9007225e5Sgerardnico
10007225e5Sgerardnicouse ComboStrap\PluginUtility;
11*32b85071SNickeauuse ComboStrap\Resources;
12007225e5Sgerardnico
13007225e5Sgerardnicoif (!defined('DOKU_INC')) die();
14007225e5Sgerardnicorequire_once(__DIR__ . '/../class/PluginUtility.php');
15007225e5Sgerardnico
16007225e5Sgerardnico
175f891b7eSNickeauclass action_plugin_combo_toolbar extends DokuWiki_Action_Plugin
185f891b7eSNickeau{
19007225e5Sgerardnico
20007225e5Sgerardnico    /**
21007225e5Sgerardnico     * register the event handlers
22007225e5Sgerardnico     *
23007225e5Sgerardnico     * @author Nicolas GERARD
24007225e5Sgerardnico     */
255f891b7eSNickeau    function register(Doku_Event_Handler $controller)
265f891b7eSNickeau    {
27007225e5Sgerardnico        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array());
28007225e5Sgerardnico    }
29007225e5Sgerardnico
305f891b7eSNickeau    function handle_toolbar(&$event, $param)
315f891b7eSNickeau    {
32007225e5Sgerardnico
332128d419Sgerardnico
34*32b85071SNickeau        $imageBase = '../../plugins/' . Resources::getRelativeImagesDirectory();
35*32b85071SNickeau
362128d419Sgerardnico        $unit = array(
37007225e5Sgerardnico            'type' => 'format',
382128d419Sgerardnico            'title' => 'Insert an unit test',
39*32b85071SNickeau            'icon' => $imageBase . '/unit-doc-block.png',
40007225e5Sgerardnico            'open' => '<unit name="default">\n<file lang path>\n</file>\n\t<code lang>',
415f891b7eSNickeau            'close' => '\n\t</code>\n\t<console>\n\t</console></unit>\n',
422128d419Sgerardnico            // 'key'    => $unitShortcutKey
43007225e5Sgerardnico        );
44007225e5Sgerardnico
452128d419Sgerardnico        /**
462128d419Sgerardnico         * This is called from the js.php with a get HTTP
472128d419Sgerardnico         * There is no knowledge of which page is modified
482128d419Sgerardnico         */
492128d419Sgerardnico
50*32b85071SNickeau        $frontmatterInsert = <<<EOF
512128d419Sgerardnico---json
522128d419Sgerardnico{
532128d419Sgerardnico    "canonical":"unique:name",
542128d419Sgerardnico    "title":"A title for the search page result engine",
552128d419Sgerardnico     "description":"A description for the search page result engine"
562128d419Sgerardnico}
572128d419Sgerardnico---
582128d419SgerardnicoEOF;
592128d419Sgerardnico        // https://www.dokuwiki.org/devel:event:toolbar_define
602128d419Sgerardnico        $frontmatter = array(
612128d419Sgerardnico            'type' => 'insert',
622128d419Sgerardnico            'title' => 'Insert a frontmatter',
63*32b85071SNickeau            'icon' => $imageBase . '/table-of-contents.svg',
64*32b85071SNickeau            'insert' => $frontmatterInsert,
652128d419Sgerardnico            'block' => true
662128d419Sgerardnico        );
672128d419Sgerardnico
682128d419Sgerardnico
692128d419Sgerardnico        $blockquote = array(
702128d419Sgerardnico            'type' => 'format',
712128d419Sgerardnico            'title' => 'blockquote',
72*32b85071SNickeau            'icon' => $imageBase . '/blockquote-icon.png',
732128d419Sgerardnico            'open' => '<blockquote>',
742128d419Sgerardnico            'close' => '</blockquote>',
752128d419Sgerardnico
762128d419Sgerardnico        );
772128d419Sgerardnico
78*32b85071SNickeau        $webcode = array(
795f891b7eSNickeau            'type' => 'format',
805f891b7eSNickeau            'title' => 'webcode',
81*32b85071SNickeau            'icon' => $imageBase . '/webcode.png',
825f891b7eSNickeau            'open' => '<webcode name="Default" frameborder="0">\n',
835f891b7eSNickeau            'close' => '\n</webcode>\n'
845f891b7eSNickeau            //'key' => $webCodeShortcutKey
855f891b7eSNickeau        );
865f891b7eSNickeau
87*32b85071SNickeau        $event->data[] = array(
88*32b85071SNickeau            'type' => 'picker',
89*32b85071SNickeau            'title' => "Choose comboStrap component",
90*32b85071SNickeau            'icon' => $imageBase . '/logo.svg',
91*32b85071SNickeau            'list' => array($frontmatter, $blockquote, $unit, $webcode)
92*32b85071SNickeau        );
93*32b85071SNickeau
94*32b85071SNickeau
952128d419Sgerardnico        return true;
962128d419Sgerardnico
97007225e5Sgerardnico
98007225e5Sgerardnico    }
99007225e5Sgerardnico
100007225e5Sgerardnico}
101007225e5Sgerardnico
102