1<?php 2/** 3 * Action Component for the Wrap Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9class action_plugin_wrap extends DokuWiki_Action_Plugin { 10 11 /** 12 * register the eventhandlers 13 * 14 * @author Andreas Gohr <andi@splitbrain.org> 15 */ 16 function register(Doku_Event_Handler $controller){ 17 $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array ()); 18 $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'handle_secedit_button'); 19 } 20 21 function handle_toolbar(Doku_Event $event, $param) { 22 $syntaxDiv = $this->getConf('syntaxDiv'); 23 $syntaxSpan = $this->getConf('syntaxSpan'); 24 25 $event->data[] = array ( 26 'type' => 'picker', 27 'title' => $this->getLang('picker'), 28 'icon' => '../../plugins/wrap/images/toolbar/picker.png', 29 'list' => array( 30 array( 31 'type' => 'format', 32 'title' => $this->getLang('column'), 33 'icon' => '../../plugins/wrap/images/toolbar/column.png', 34 'open' => '<'.$syntaxDiv.' group>\n<'.$syntaxDiv.' half column>\n', 35 'close' => '\n</'.$syntaxDiv.'>\n\n<'.$syntaxDiv.' half column>\n\n</'.$syntaxDiv.'>\n</'.$syntaxDiv.'>\n', 36 ), 37 array( 38 'type' => 'format', 39 'title' => $this->getLang('box'), 40 'icon' => '../../plugins/wrap/images/toolbar/box.png', 41 'open' => '<'.$syntaxDiv.' center round box 60%>\n', 42 'close' => '\n</'.$syntaxDiv.'>\n', 43 ), 44 array( 45 'type' => 'format', 46 'title' => $this->getLang('info'), 47 'icon' => '../../plugins/wrap/images/note/16/info.png', 48 'open' => '<'.$syntaxDiv.' center round info 60%>\n', 49 'close' => '\n</'.$syntaxDiv.'>\n', 50 ), 51 array( 52 'type' => 'format', 53 'title' => $this->getLang('tip'), 54 'icon' => '../../plugins/wrap/images/note/16/tip.png', 55 'open' => '<'.$syntaxDiv.' center round tip 60%>\n', 56 'close' => '\n</'.$syntaxDiv.'>\n', 57 ), 58 array( 59 'type' => 'format', 60 'title' => $this->getLang('important'), 61 'icon' => '../../plugins/wrap/images/note/16/important.png', 62 'open' => '<'.$syntaxDiv.' center round important 60%>\n', 63 'close' => '\n</'.$syntaxDiv.'>\n', 64 ), 65 array( 66 'type' => 'format', 67 'title' => $this->getLang('alert'), 68 'icon' => '../../plugins/wrap/images/note/16/alert.png', 69 'open' => '<'.$syntaxDiv.' center round alert 60%>\n', 70 'close' => '\n</'.$syntaxDiv.'>\n', 71 ), 72 array( 73 'type' => 'format', 74 'title' => $this->getLang('help'), 75 'icon' => '../../plugins/wrap/images/note/16/help.png', 76 'open' => '<'.$syntaxDiv.' center round help 60%>\n', 77 'close' => '\n</'.$syntaxDiv.'>\n', 78 ), 79 array( 80 'type' => 'format', 81 'title' => $this->getLang('download'), 82 'icon' => '../../plugins/wrap/images/note/16/download.png', 83 'open' => '<'.$syntaxDiv.' center round download 60%>\n', 84 'close' => '\n</'.$syntaxDiv.'>\n', 85 ), 86 array( 87 'type' => 'format', 88 'title' => $this->getLang('todo'), 89 'icon' => '../../plugins/wrap/images/note/16/todo.png', 90 'open' => '<'.$syntaxDiv.' center round todo 60%>\n', 91 'close' => '\n</'.$syntaxDiv.'>\n', 92 ), 93 array( 94 'type' => 'insert', 95 'title' => $this->getLang('clear'), 96 'icon' => '../../plugins/wrap/images/toolbar/clear.png', 97 'insert' => '<'.$syntaxDiv.' clear/>\n', 98 ), 99 array( 100 'type' => 'format', 101 'title' => $this->getLang('em'), 102 'icon' => '../../plugins/wrap/images/toolbar/em.png', 103 'open' => '<'.$syntaxSpan.' em>', 104 'close' => '</'.$syntaxSpan.'>', 105 ), 106 array( 107 'type' => 'format', 108 'title' => $this->getLang('hi'), 109 'icon' => '../../plugins/wrap/images/toolbar/hi.png', 110 'open' => '<'.$syntaxSpan.' hi>', 111 'close' => '</'.$syntaxSpan.'>', 112 ), 113 array( 114 'type' => 'format', 115 'title' => $this->getLang('lo'), 116 'icon' => '../../plugins/wrap/images/toolbar/lo.png', 117 'open' => '<'.$syntaxSpan.' lo>', 118 'close' => '</'.$syntaxSpan.'>', 119 ), 120 ) 121 ); 122 } 123 124 /** 125 * Handle section edit buttons, prevents section buttons inside the wrap plugin from being rendered 126 * 127 * @param Doku_Event $event The event object 128 * @param array $param Parameters for the event 129 */ 130 public function handle_secedit_button(Doku_Event $event, $param) { 131 // counter of the number of currently opened wraps 132 static $wraps = 0; 133 $data = $event->data; 134 135 if ($data['target'] == 'plugin_wrap_start') { 136 ++$wraps; 137 } elseif ($data['target'] == 'plugin_wrap_end') { 138 --$wraps; 139 } elseif ($wraps > 0 && $data['target'] == 'section') { 140 $event->preventDefault(); 141 $event->stopPropagation(); 142 $event->result = ''; 143 } 144 } 145} 146 147