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 * Relative path against 34 * DOKUBASE/lib/images/toolbar/ 35 */ 36 $imageBase = '../../plugins/combo/resources/images'; 37 38 $unit = array( 39 'type' => 'format', 40 'title' => 'Insert an unit test', 41 'icon' => $imageBase . '/unit-doc-block.png', 42 'open' => '<unit name="default">\n<file lang path>\n</file>\n\t<code lang>', 43 'close' => '\n\t</code>\n\t<console>\n\t</console></unit>\n', 44 // 'key' => $unitShortcutKey 45 ); 46 47 /** 48 * This is called from the js.php with a get HTTP 49 * There is no knowledge of which page is modified 50 */ 51 52 $frontmatterInsert = <<<EOF 53---json 54{ 55 "name":"short name", 56 "canonical":"unique:name", 57 "title":"A title for template iteration and search page engine", 58 "description":"A description for template iteration and search page engine" 59} 60--- 61EOF; 62 // https://www.dokuwiki.org/devel:event:toolbar_define 63 $frontmatter = array( 64 'type' => 'insert', 65 'title' => 'Insert a frontmatter', 66 'icon' => $imageBase . '/table-of-contents.svg', 67 'insert' => $frontmatterInsert, 68 'block' => true 69 ); 70 71 72 $blockquote = array( 73 'type' => 'format', 74 'title' => 'blockquote', 75 'icon' => $imageBase . '/blockquote-icon.png', 76 'open' => '<blockquote>', 77 'close' => '</blockquote>', 78 79 ); 80 81 $webcode = array( 82 'type' => 'format', 83 'title' => 'webcode', 84 'icon' => $imageBase . '/code-square.svg', 85 'open' => '<webcode name="Default" frameborder="0">\n', 86 'close' => '\n</webcode>\n' 87 //'key' => $webCodeShortcutKey 88 ); 89 90 $twitter = array( 91 'type' => 'format', 92 'title' => 'twitter', 93 'icon' => $imageBase . '/twitter.svg', 94 'open' => '<blockquote>\n<cite>[[', 95 'close' => ']]</cite>\n</blockquote>\n' 96 //'key' => $webCodeShortcutKey 97 ); 98 99 $event->data[] = array( 100 'type' => 'picker', 101 'title' => "Choose comboStrap component", 102 'icon' => $imageBase . '/logo.svg', 103 'list' => array($frontmatter, $blockquote, $webcode, $twitter, $unit) 104 ); 105 106 107 108 109 return true; 110 111 112 } 113 114} 115 116