1<?php 2/** 3 * Action Component for the Ad-Hoc Tags Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 * @author Sascha Leib <sascha.leib(at)kolmio.com> 8 */ 9 10class action_plugin_adhoctags extends DokuWiki_Action_Plugin { 11 12 /** 13 * register the eventhandlers 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @author Sascha Leib <sascha.leib(at)kolmio.com> 17 */ 18 function register(Doku_Event_Handler $controller){ 19 $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array ()); 20 } 21 22 function handle_toolbar(Doku_Event $event, $param) { 23 $allowedElements = explode(',',$this->getConf('allowedElements')); 24 25 /* collect the allowed elements here: */ 26 $iconList = array(); 27 28 /* bold */ 29 if (in_array('b', $allowedElements)) { 30 array_push($iconList, array( 31 'type' => 'format', 32 'title' => $this->getLang('b').': <>', 33 'icon' => '../../plugins/adhoctags/images/format-bold.svg', 34 'open' => '<b>', 35 'close' => '</b>', 36 'sample' => 'Bold' 37 )); 38 }; 39 /* italic */ 40 if (in_array('i', $allowedElements)) { 41 array_push($iconList, array( 42 'type' => 'format', 43 'title' => $this->getLang('i').': <>', 44 'icon' => '../../plugins/adhoctags/images/format-italic.svg', 45 'open' => '<i>', 46 'close' => '</i>', 47 'sample' => 'Italic' 48 )); 49 }; 50 /* strikethrough */ 51 if (in_array('s', $allowedElements)) { 52 array_push($iconList, array( 53 'type' => 'format', 54 'title' => $this->getLang('s').': <>', 55 'icon' => '../../plugins/adhoctags/images/format-strikethrough-variant.svg', 56 'open' => '<s>', 57 'close' => '</s>', 58 'sample' => 'Strikethrough' 59 )); 60 }; 61 62 /* underline */ 63 if (in_array('u', $allowedElements)) { 64 array_push($iconList, array( 65 'type' => 'format', 66 'title' => $this->getLang('u').': <>', 67 'icon' => '../../plugins/adhoctags/images/format-underline-wavy.svg', 68 'open' => '<u>', 69 'close' => '</u>', 70 'sample' => 'Underline' 71 )); 72 }; 73 /* small */ 74 if (in_array('small', $allowedElements)) { 75 array_push($iconList, array( 76 'type' => 'format', 77 'title' => $this->getLang('small').': <>', 78 'icon' => '../../plugins/adhoctags/images/format-size.svg', 79 'open' => '<small>', 80 'close' => '</small>', 81 'sample' => 'smaller' 82 )); 83 }; 84 /* quote */ 85 if (in_array('q', $allowedElements)) { 86 array_push($iconList, array( 87 'type' => 'format', 88 'title' => $this->getLang('q').': <>', 89 'icon' => '../../plugins/adhoctags/images/format-quote-open.svg', 90 'open' => '<q>', 91 'close' => '</q>', 92 'sample' => 'Quotation' 93 )); 94 }; 95 /* abbreviation */ 96 if (in_array('abbr', $allowedElements)) { 97 array_push($iconList, array( 98 'type' => 'format', 99 'title' => $this->getLang('abbr').': <>', 100 'icon' => '../../plugins/adhoctags/images/abbr.svg', 101 'open' => '<abbr>', 102 'close' => '</abbr>', 103 'sample' => 'ABBR' 104 )); 105 }; 106 /* definition */ 107 if (in_array('dfn', $allowedElements)) { 108 array_push($iconList, array( 109 'type' => 'format', 110 'title' => $this->getLang('dfn').': <>', 111 'icon' => '../../plugins/adhoctags/images/def.svg', 112 'open' => '<dfn>', 113 'close' => '</dfn>', 114 'sample' => 'Definition' 115 )); 116 }; 117 /* keyboard */ 118 if (in_array('kbd', $allowedElements)) { 119 array_push($iconList, array( 120 'type' => 'format', 121 'title' => $this->getLang('kbd').': <>', 122 'icon' => '../../plugins/adhoctags/images/keyboard-variant.svg', 123 'open' => '<kbd>', 124 'close' => '</kbd>', 125 'sample' => 'Ctrl' 126 )); 127 }; 128 /* sample */ 129 if (in_array('samp', $allowedElements)) { 130 array_push($iconList, array( 131 'type' => 'format', 132 'title' => $this->getLang('samp').': <>', 133 'icon' => '../../plugins/adhoctags/images/export.svg', 134 'open' => '<samp>', 135 'close' => '</samp>', 136 'sample' => 'Output' 137 )); 138 }; 139 /* variable */ 140 if (in_array('var', $allowedElements)) { 141 array_push($iconList, array( 142 'type' => 'format', 143 'title' => $this->getLang('var').': <>', 144 'icon' => '../../plugins/adhoctags/images/variable.svg', 145 'open' => '<var>', 146 'close' => '</var>', 147 'sample' => 'x' 148 )); 149 }; 150 /* marker */ 151 if (in_array('mark', $allowedElements)) { 152 array_push($iconList, array( 153 'type' => 'format', 154 'title' => $this->getLang('mark').': <>', 155 'icon' => '../../plugins/adhoctags/images/format-color-highlight.svg', 156 'open' => '<mark>', 157 'close' => '</mark>', 158 'sample' => 'marked' 159 )); 160 }; 161 /* citation */ 162 if (in_array('cite', $allowedElements)) { 163 array_push($iconList, array( 164 'type' => 'format', 165 'title' => $this->getLang('cite').': <>', 166 'icon' => '../../plugins/adhoctags/images/comment-quote-outline.svg', 167 'open' => '<cite>', 168 'close' => '</cite>', 169 'sample' => 'Citation' 170 )); 171 }; 172 /* date-time */ 173 if (in_array('time', $allowedElements)) { 174 array_push($iconList, array( 175 'type' => 'format', 176 'title' => $this->getLang('time').': <>', 177 'icon' => '../../plugins/adhoctags/images/calendar-clock.svg', 178 'open' => '<time>', 179 'close' => '</time>', 180 'sample' => 'datetime' 181 )); 182 }; 183 /* image */ 184 if (in_array('img', $allowedElements)) { 185 array_push($iconList, array( 186 'type' => 'format', 187 'title' => $this->getLang('img').': <img>', 188 'icon' => '../../plugins/adhoctags/images/image-outline.svg', 189 'open' => '<img [src=', 190 'close' => '] [width=64] [height=64] "alt" />', 191 'sample' => 'imagepath' 192 )); 193 }; 194 /* section */ 195 if (in_array('section', $allowedElements)) { 196 array_push($iconList, array( 197 'type' => 'format', 198 'title' => $this->getLang('section').': <>', 199 'icon' => '../../plugins/adhoctags/images/code-brackets.svg', 200 'open' => '<section>\n', 201 'close' => '\n</section>', 202 'sample' => 'Section' 203 )); 204 }; 205 /* figure + figcaption */ 206 if (in_array('figure', $allowedElements) && in_array('figcaption', $allowedElements)) { 207 array_push($iconList, array( 208 'type' => 'format', 209 'title' => $this->getLang('figure').': <>/<>', 210 'icon' => '../../plugins/adhoctags/images/figure-caption.svg', 211 'open' => '<figure>\n', 212 'close' => '\n<figcaption>Caption</figcaption>\n</figure>', 213 'sample' => 'figure content' 214 )); 215 }; 216 /* aside */ 217 if (in_array('aside', $allowedElements)) { 218 array_push($iconList, array( 219 'type' => 'format', 220 'title' => $this->getLang('aside').': <>', 221 'icon' => '../../plugins/adhoctags/images/aside.svg', 222 'open' => '<aside>\n', 223 'close' => '\n</aside>', 224 'sample' => 'Aside text' 225 )); 226 }; 227 /* article */ 228 if (in_array('article', $allowedElements)) { 229 array_push($iconList, array( 230 'type' => 'format', 231 'title' => $this->getLang('article').': <>', 232 'icon' => '../../plugins/adhoctags/images/subtitles-outline.svg', 233 'open' => '<article>\n', 234 'close' => '\n</article>', 235 'sample' => 'Article text' 236 )); 237 }; 238 /* definition lists */ 239 if (in_array('dl', $allowedElements) && in_array('dt', $allowedElements) && in_array('dd', $allowedElements)) { 240 array_push($iconList, array( 241 'type' => 'format', 242 'title' => $this->getLang('dl').': <>/<>/<>', 243 'icon' => '../../plugins/adhoctags/images/definition-list.svg', 244 'open' => '<dl>\n<dt>', 245 'close' => '</dt>\n<dd>Description</dd>\n</dl>', 246 'sample' => 'Term' 247 )); 248 }; 249 /* unordered lists */ 250 if (in_array('ul', $allowedElements) && in_array('li', $allowedElements)) { 251 array_push($iconList, array( 252 'type' => 'format', 253 'title' => $this->getLang('ul').': <ul>/<li>', 254 'icon' => '../../plugins/adhoctags/images/definition-list.svg', 255 'open' => '<ul>\n<li>', 256 'close' => 'List item</li>\n</ul>', 257 'sample' => 'List item' 258 )); 259 }; 260 /* ordered lists */ 261 if (in_array('ol', $allowedElements) && in_array('li', $allowedElements)) { 262 array_push($iconList, array( 263 'type' => 'format', 264 'title' => $this->getLang('ol').': <ol>/<li>', 265 'icon' => '../../plugins/adhoctags/images/definition-list.svg', 266 'open' => '<ol>\n<li>', 267 'close' => 'List item</li>\n</ol>', 268 'sample' => 'List item' 269 )); 270 }; 271 /* address */ 272 if (in_array('address', $allowedElements)) { 273 array_push($iconList, array( 274 'type' => 'format', 275 'title' => $this->getLang('address').': <>', 276 'icon' => '../../plugins/adhoctags/images/card-account-details-outline.svg', 277 'open' => '<address>\n', 278 'close' => '\n</address>', 279 'sample' => 'Address' 280 )); 281 }; 282 /* details + summary */ 283 if (in_array('details', $allowedElements) && in_array('summary', $allowedElements)) { 284 array_push($iconList, array( 285 'type' => 'format', 286 'title' => $this->getLang('details').': <>/<>', 287 'icon' => '../../plugins/adhoctags/images/details-summary.svg', 288 'open' => '<details><summary>', 289 'close' => '</summary>\nDetails\n</details>', 290 'sample' => 'Summary' 291 )); 292 }; 293 294 /* create the menu */ 295 if (count($iconList) > 0) { 296 $event->data[] = array ( 297 'type' => 'picker', 298 'title' => $this->getLang('picker'), 299 'icon' => '../../plugins/adhoctags/images/code-tags.svg', 300 'id' => 'tbbtn_adhoctagsInline', 301 'list' => $iconList 302 ); 303 } 304 } 305}