1<?php 2 3/** 4 * Editing toolbar functions 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Andreas Gohr <andi@splitbrain.org> 8 */ 9 10use dokuwiki\Extension\Event; 11 12/** 13 * Prepares and prints an JavaScript array with all toolbar buttons 14 * 15 * @emits TOOLBAR_DEFINE 16 * @param string $varname Name of the JS variable to fill 17 * @author Andreas Gohr <andi@splitbrain.org> 18 */ 19function toolbar_JSdefines($varname) 20{ 21 global $lang; 22 23 $menu = []; 24 25 $evt = new Event('TOOLBAR_DEFINE', $menu); 26 if ($evt->advise_before()) { 27 // build button array 28 $menu = array_merge($menu, [ 29 [ 30 'type' => 'format', 31 'title' => $lang['qb_bold'], 32 'icon' => 'bold.png', 33 'key' => 'b', 34 'open' => '**', 35 'close' => '**', 36 'block' => false 37 ], 38 [ 39 'type' => 'format', 40 'title' => $lang['qb_italic'], 41 'icon' => 'italic.png', 42 'key' => 'i', 43 'open' => '//', 44 'close' => '//', 45 'block' => false 46 ], 47 [ 48 'type' => 'format', 49 'title' => $lang['qb_underl'], 50 'icon' => 'underline.png', 51 'key' => 'u', 52 'open' => '__', 53 'close' => '__', 54 'block' => false 55 ], 56 [ 57 'type' => 'format', 58 'title' => $lang['qb_code'], 59 'icon' => 'mono.png', 60 'key' => 'm', 61 'open' => "''", 62 'close' => "''", 63 'block' => false 64 ], 65 [ 66 'type' => 'format', 67 'title' => $lang['qb_strike'], 68 'icon' => 'strike.png', 69 'key' => 'd', 70 'open' => '<del>', 71 'close' => '</del>', 72 'block' => false 73 ], 74 [ 75 'type' => 'autohead', 76 'title' => $lang['qb_hequal'], 77 'icon' => 'hequal.png', 78 'key' => '8', 79 'text' => $lang['qb_h'], 80 'mod' => 0, 81 'block' => true 82 ], 83 [ 84 'type' => 'autohead', 85 'title' => $lang['qb_hminus'], 86 'icon' => 'hminus.png', 87 'key' => '9', 88 'text' => $lang['qb_h'], 89 'mod' => 1, 90 'block' => true 91 ], 92 [ 93 'type' => 'autohead', 94 'title' => $lang['qb_hplus'], 95 'icon' => 'hplus.png', 96 'key' => '0', 97 'text' => $lang['qb_h'], 98 'mod' => -1, 99 'block' => true 100 ], 101 [ 102 'type' => 'picker', 103 'title' => $lang['qb_hs'], 104 'icon' => 'h.png', 105 'class' => 'pk_hl', 106 'list' => [ 107 [ 108 'type' => 'format', 109 'title' => $lang['qb_h1'], 110 'icon' => 'h1.png', 111 'key' => '1', 112 'open' => '====== ', 113 'close' => ' ======\n' 114 ], 115 [ 116 'type' => 'format', 117 'title' => $lang['qb_h2'], 118 'icon' => 'h2.png', 119 'key' => '2', 120 'open' => '===== ', 121 'close' => ' =====\n' 122 ], 123 [ 124 'type' => 'format', 125 'title' => $lang['qb_h3'], 126 'icon' => 'h3.png', 127 'key' => '3', 128 'open' => '==== ', 129 'close' => ' ====\n' 130 ], 131 [ 132 'type' => 'format', 133 'title' => $lang['qb_h4'], 134 'icon' => 'h4.png', 135 'key' => '4', 136 'open' => '=== ', 137 'close' => ' ===\n' 138 ], 139 [ 140 'type' => 'format', 141 'title' => $lang['qb_h5'], 142 'icon' => 'h5.png', 143 'key' => '5', 144 'open' => '== ', 145 'close' => ' ==\n' 146 ] 147 ], 148 'block' => true 149 ], 150 [ 151 'type' => 'linkwiz', 152 'title' => $lang['qb_link'], 153 'icon' => 'link.png', 154 'key' => 'l', 155 'open' => '[[', 156 'close' => ']]', 157 'block' => false 158 ], 159 [ 160 'type' => 'format', 161 'title' => $lang['qb_extlink'], 162 'icon' => 'linkextern.png', 163 'open' => '[[', 164 'close' => ']]', 165 'sample' => 'http://example.com|' . $lang['qb_extlink'], 166 'block' => false 167 ], 168 [ 169 'type' => 'formatln', 170 'title' => $lang['qb_ol'], 171 'icon' => 'ol.png', 172 'open' => ' - ', 173 'close' => '', 174 'key' => '-', 175 'block' => true 176 ], 177 [ 178 'type' => 'formatln', 179 'title' => $lang['qb_ul'], 180 'icon' => 'ul.png', 181 'open' => ' * ', 182 'close' => '', 183 'key' => '.', 184 'block' => true 185 ], 186 [ 187 'type' => 'insert', 188 'title' => $lang['qb_hr'], 189 'icon' => 'hr.png', 190 'insert' => '\n----\n', 191 'block' => true 192 ], 193 [ 194 'type' => 'mediapopup', 195 'title' => $lang['qb_media'], 196 'icon' => 'image.png', 197 'url' => 'lib/exe/mediamanager.php?ns=', 198 'name' => 'mediaselect', 199 'options' => 'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes', 200 'block' => false 201 ], 202 [ 203 'type' => 'picker', 204 'title' => $lang['qb_smileys'], 205 'icon' => 'smiley.png', 206 'list' => getSmileys(), 207 'icobase' => 'smileys', 208 'block' => false 209 ], 210 [ 211 'type' => 'picker', 212 'title' => $lang['qb_chars'], 213 'icon' => 'chars.png', 214 'list' => [ 215 'À', 'à', 'Á', 'á', 'Â', 'â', 'Ã', 'ã', 'Ä', 'ä', 'Ǎ', 'ǎ', 'Ă', 'ă', 'Å', 'å', 216 'Ā', 'ā', 'Ą', 'ą', 'Æ', 'æ', 'Ć', 'ć', 'Ç', 'ç', 'Č', 'č', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 217 'Ð', 'đ', 'ð', 'Ď', 'ď', 'È', 'è', 'É', 'é', 'Ê', 'ê', 'Ë', 'ë', 'Ě', 'ě', 'Ē', 218 'ē', 'Ė', 'ė', 'Ę', 'ę', 'Ģ', 'ģ', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ĥ', 'ĥ', 'Ì', 219 'ì', 'Í', 'í', 'Î', 'î', 'Ï', 'ï', 'Ǐ', 'ǐ', 'Ī', 'ī', 'İ', 'ı', 'Į', 'į', 'Ĵ', 220 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ł', 'ł', 'Ŀ', 'ŀ', 'Ń', 'ń', 'Ñ', 221 'ñ', 'Ņ', 'ņ', 'Ň', 'ň', 'Ò', 'ò', 'Ó', 'ó', 'Ô', 'ô', 'Õ', 'õ', 'Ö', 'ö', 'Ǒ', 222 'ǒ', 'Ō', 'ō', 'Ő', 'ő', 'Œ', 'œ', 'Ø', 'ø', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 223 'ś', 'Ş', 'ş', 'Š', 'š', 'Ŝ', 'ŝ', 'Ţ', 'ţ', 'Ť', 'ť', 'Ù', 'ù', 'Ú', 'ú', 'Û', 224 'û', 'Ü', 'ü', 'Ǔ', 'ǔ', 'Ŭ', 'ŭ', 'Ū', 'ū', 'Ů', 'ů', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'Ų', 225 'ų', 'Ű', 'ű', 'Ŵ', 'ŵ', 'Ý', 'ý', 'Ÿ', 'ÿ', 'Ŷ', 'ŷ', 'Ź', 'ź', 'Ž', 'ž', 'Ż', 226 'ż', 'Þ', 'þ', 'ß', 'Ħ', 'ħ', '¿', '¡', '¢', '£', '¤', '¥', '€', '¦', '§', 'ª', 227 '¬', '¯', '°', '±', '÷', '‰', '¼', '½', '¾', '¹', '²', '³', 'µ', '¶', '†', '‡', 228 '·', '•', 'º', '∀', '∂', '∃', 'Ə', 'ə', '∅', '∇', '∈', '∉', '∋', '∏', '∑', '‾', 229 '−', '∗', '×', '⁄', '√', '∝', '∞', '∠', '∧', '∨', '∩', '∪', '∫', '∴', '∼', '≅', 230 '≈', '≠', '≡', '≤', '≥', '⊂', '⊃', '⊄', '⊆', '⊇', '⊕', '⊗', '⊥', '⋅', '◊', '℘', 231 'ℑ', 'ℜ', 'ℵ', '♠', '♣', '♥', '♦', 'α', 'β', 'Γ', 'γ', 'Δ', 'δ', 'ε', 'ζ', 'η', 232 'Θ', 'θ', 'ι', 'κ', 'Λ', 'λ', 'μ', 'Ξ', 'ξ', 'Π', 'π', 'ρ', 'Σ', 'σ', 'Τ', 'τ', 233 'υ', 'Φ', 'φ', 'χ', 'Ψ', 'ψ', 'Ω', 'ω', '★', '☆', '☎', '☚', '☛', '☜', '☝', '☞', 234 '☟', '☹', '☺', '✔', '✘', '„', '“', '”', '‚', '‘', '’', '«', '»', '‹', '›', '—', 235 '–', '…', '←', '↑', '→', '↓', '↔', '⇐', '⇑', '⇒', '⇓', '⇔', '©', '™', '®', '′', 236 '″', '[', ']', '{', '}', '~', '(', ')', '%', '§', '$', '#', '|', '@' 237 ], 238 'block' => false 239 ], 240 [ 241 'type' => 'signature', 242 'title' => $lang['qb_sig'], 243 'icon' => 'sig.png', 244 'key' => 'y', 245 'block' => false 246 ] 247 ]); 248 } // end event TOOLBAR_DEFINE default action 249 $evt->advise_after(); 250 unset($evt); 251 252 // use JSON to build the JavaScript array 253 echo "var $varname = " . json_encode($menu, JSON_THROW_ON_ERROR) . ";\n"; 254} 255 256/** 257 * prepares the signature string as configured in the config 258 * 259 * @author Andreas Gohr <andi@splitbrain.org> 260 */ 261function toolbar_signature() 262{ 263 global $conf; 264 global $INFO; 265 /** @var Input $INPUT */ 266 global $INPUT; 267 268 $sig = $conf['signature']; 269 $sig = dformat(null, $sig); 270 $sig = str_replace('@USER@', $INPUT->server->str('REMOTE_USER'), $sig); 271 if (is_null($INFO)) { 272 $sig = str_replace(['@NAME@', '@MAIL@'], '', $sig); 273 } else { 274 $sig = str_replace('@NAME@', $INFO['userinfo']['name'] ?? "", $sig); 275 $sig = str_replace('@MAIL@', $INFO['userinfo']['mail'] ?? "", $sig); 276 } 277 $sig = str_replace('@DATE@', dformat(), $sig); 278 $sig = str_replace('\\\\n', '\\n', $sig); 279 return json_encode($sig, JSON_THROW_ON_ERROR); 280} 281 282//Setup VIM: ex: et ts=4 : 283