xref: /dokuwiki/inc/toolbar.php (revision 20d062ca5220daf6606e2b1bcdd73d84eebafa45)
1*20d062caSAndreas Gohr<?php
2*20d062caSAndreas Gohr/**
3*20d062caSAndreas Gohr * Editing toolbar functions
4*20d062caSAndreas Gohr *
5*20d062caSAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6*20d062caSAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
7*20d062caSAndreas Gohr */
8*20d062caSAndreas Gohr
9*20d062caSAndreas Gohr  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10*20d062caSAndreas Gohr
11*20d062caSAndreas Gohrrequire_once(DOKU_INC.'inc/JSON.php');
12*20d062caSAndreas Gohr
13*20d062caSAndreas Gohr
14*20d062caSAndreas Gohr/**
15*20d062caSAndreas Gohr * Prepares and prints an JavaScript array with all toolbar buttons
16*20d062caSAndreas Gohr *
17*20d062caSAndreas Gohr * @todo add toolbar plugins
18*20d062caSAndreas Gohr * @param  string $varname Name of the JS variable to fill
19*20d062caSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
20*20d062caSAndreas Gohr */
21*20d062caSAndreas Gohrfunction toolbar_JSdefines($varname){
22*20d062caSAndreas Gohr    global $ID;
23*20d062caSAndreas Gohr    global $conf;
24*20d062caSAndreas Gohr    global $lang;
25*20d062caSAndreas Gohr
26*20d062caSAndreas Gohr    // build button array
27*20d062caSAndreas Gohr    $menu = array(
28*20d062caSAndreas Gohr       array(
29*20d062caSAndreas Gohr            'type'   => 'format',
30*20d062caSAndreas Gohr            'title'  => $lang['qb_bold'],
31*20d062caSAndreas Gohr            'icon'   => 'bold.png',
32*20d062caSAndreas Gohr            'key'    => 'b',
33*20d062caSAndreas Gohr            'open'   => '**',
34*20d062caSAndreas Gohr            'close'  => '**',
35*20d062caSAndreas Gohr            ),
36*20d062caSAndreas Gohr       array(
37*20d062caSAndreas Gohr            'type'   => 'format',
38*20d062caSAndreas Gohr            'title'  => $lang['qb_italic'],
39*20d062caSAndreas Gohr            'icon'   => 'italic.png',
40*20d062caSAndreas Gohr            'key'    => 'i',
41*20d062caSAndreas Gohr            'open'   => '//',
42*20d062caSAndreas Gohr            'close'  => '//',
43*20d062caSAndreas Gohr            ),
44*20d062caSAndreas Gohr       array(
45*20d062caSAndreas Gohr            'type'   => 'format',
46*20d062caSAndreas Gohr            'title'  => $lang['qb_underl'],
47*20d062caSAndreas Gohr            'icon'   => 'underline.png',
48*20d062caSAndreas Gohr            'key'    => 'u',
49*20d062caSAndreas Gohr            'open'   => '__',
50*20d062caSAndreas Gohr            'close'  => '__',
51*20d062caSAndreas Gohr            ),
52*20d062caSAndreas Gohr       array(
53*20d062caSAndreas Gohr            'type'   => 'format',
54*20d062caSAndreas Gohr            'title'  => $lang['qb_code'],
55*20d062caSAndreas Gohr            'icon'   => 'mono.png',
56*20d062caSAndreas Gohr            'key'    => 'c',
57*20d062caSAndreas Gohr            'open'   => "''",
58*20d062caSAndreas Gohr            'close'  => "''",
59*20d062caSAndreas Gohr            ),
60*20d062caSAndreas Gohr       array(
61*20d062caSAndreas Gohr            'type'   => 'format',
62*20d062caSAndreas Gohr            'title'  => $lang['qb_strike'],
63*20d062caSAndreas Gohr            'icon'   => 'strike.png',
64*20d062caSAndreas Gohr            'key'    => 'd',
65*20d062caSAndreas Gohr            'open'  => '<del>',
66*20d062caSAndreas Gohr            'close'   => '<del>',
67*20d062caSAndreas Gohr            ),
68*20d062caSAndreas Gohr       array(
69*20d062caSAndreas Gohr            'type'   => 'format',
70*20d062caSAndreas Gohr            'title'  => $lang['qb_h1'],
71*20d062caSAndreas Gohr            'icon'   => 'h1.png',
72*20d062caSAndreas Gohr            'key'    => '1',
73*20d062caSAndreas Gohr            'open'   => '====== ',
74*20d062caSAndreas Gohr            'close'  => '======\n',
75*20d062caSAndreas Gohr            ),
76*20d062caSAndreas Gohr       array(
77*20d062caSAndreas Gohr            'type'   => 'format',
78*20d062caSAndreas Gohr            'title'  => $lang['qb_h2'],
79*20d062caSAndreas Gohr            'icon'   => 'h2.png',
80*20d062caSAndreas Gohr            'key'    => '2',
81*20d062caSAndreas Gohr            'open'   => '===== ',
82*20d062caSAndreas Gohr            'close'  => '=====\n',
83*20d062caSAndreas Gohr            ),
84*20d062caSAndreas Gohr       array(
85*20d062caSAndreas Gohr            'type'   => 'format',
86*20d062caSAndreas Gohr            'title'  => $lang['qb_h3'],
87*20d062caSAndreas Gohr            'icon'   => 'h3.png',
88*20d062caSAndreas Gohr            'key'    => '3',
89*20d062caSAndreas Gohr            'open'   => '==== ',
90*20d062caSAndreas Gohr            'close'  => '====\n',
91*20d062caSAndreas Gohr            ),
92*20d062caSAndreas Gohr       array(
93*20d062caSAndreas Gohr            'type'   => 'format',
94*20d062caSAndreas Gohr            'title'  => $lang['qb_h4'],
95*20d062caSAndreas Gohr            'icon'   => 'h4.png',
96*20d062caSAndreas Gohr            'key'    => '4',
97*20d062caSAndreas Gohr            'open'   => '=== ',
98*20d062caSAndreas Gohr            'close'  => '===\n',
99*20d062caSAndreas Gohr            ),
100*20d062caSAndreas Gohr       array(
101*20d062caSAndreas Gohr            'type'   => 'format',
102*20d062caSAndreas Gohr            'title'  => $lang['qb_h5'],
103*20d062caSAndreas Gohr            'icon'   => 'h5.png',
104*20d062caSAndreas Gohr            'key'    => '5',
105*20d062caSAndreas Gohr            'open'   => '== ',
106*20d062caSAndreas Gohr            'close'  => '==\n',
107*20d062caSAndreas Gohr            ),
108*20d062caSAndreas Gohr       array(
109*20d062caSAndreas Gohr            'type'   => 'format',
110*20d062caSAndreas Gohr            'title'  => $lang['qb_link'],
111*20d062caSAndreas Gohr            'icon'   => 'link.png',
112*20d062caSAndreas Gohr            'key'    => 'l',
113*20d062caSAndreas Gohr            'open'   => '[[',
114*20d062caSAndreas Gohr            'close'  => ']]',
115*20d062caSAndreas Gohr            ),
116*20d062caSAndreas Gohr       array(
117*20d062caSAndreas Gohr            'type'   => 'format',
118*20d062caSAndreas Gohr            'title'  => $lang['qb_extlink'],
119*20d062caSAndreas Gohr            'icon'   => 'linkextern.png',
120*20d062caSAndreas Gohr            'open'   => '[[',
121*20d062caSAndreas Gohr            'close'  => ']]',
122*20d062caSAndreas Gohr            'sample' => 'http://example.com|'.$lang['qb_extlink'],
123*20d062caSAndreas Gohr            ),
124*20d062caSAndreas Gohr       array(
125*20d062caSAndreas Gohr            'type'   => 'format',
126*20d062caSAndreas Gohr            'title'  => $lang['qb_ol'],
127*20d062caSAndreas Gohr            'icon'   => 'ol.png',
128*20d062caSAndreas Gohr            'open'   => '  - ',
129*20d062caSAndreas Gohr            'close'  => '\n',
130*20d062caSAndreas Gohr            ),
131*20d062caSAndreas Gohr       array(
132*20d062caSAndreas Gohr            'type'   => 'format',
133*20d062caSAndreas Gohr            'title'  => $lang['qb_ul'],
134*20d062caSAndreas Gohr            'icon'   => 'ul.png',
135*20d062caSAndreas Gohr            'open'   => '  * ',
136*20d062caSAndreas Gohr            'close'  => '\n',
137*20d062caSAndreas Gohr            ),
138*20d062caSAndreas Gohr       array(
139*20d062caSAndreas Gohr            'type'   => 'insert',
140*20d062caSAndreas Gohr            'title'  => $lang['qb_hr'],
141*20d062caSAndreas Gohr            'icon'   => 'hr.png',
142*20d062caSAndreas Gohr            'insert' => '----\n',
143*20d062caSAndreas Gohr            ),
144*20d062caSAndreas Gohr       array(
145*20d062caSAndreas Gohr            'type'   => 'popup',
146*20d062caSAndreas Gohr            'title'  => $lang['qb_media'],
147*20d062caSAndreas Gohr            'icon'   => 'image.png',
148*20d062caSAndreas Gohr            'url'    => DOKU_BASE.'lib/exe/media.php?ns='.getNS($ID),
149*20d062caSAndreas Gohr            'name'   => 'mediaselect',
150*20d062caSAndreas Gohr            'options'=> 'width=600,height=320,left=70,top=50,scrollbars=yes,resizable=yes',
151*20d062caSAndreas Gohr            ),
152*20d062caSAndreas Gohr      array(
153*20d062caSAndreas Gohr            'type'   => 'picker',
154*20d062caSAndreas Gohr            'title'  => $lang['qb_smileys'],
155*20d062caSAndreas Gohr            'icon'   => 'smiley.png',
156*20d062caSAndreas Gohr            'list'   => getSmileys(),
157*20d062caSAndreas Gohr            'icobase'=> 'smileys',
158*20d062caSAndreas Gohr           ),
159*20d062caSAndreas Gohr      array(
160*20d062caSAndreas Gohr            'type'   => 'picker',
161*20d062caSAndreas Gohr            'title'  => $lang['qb_chars'],
162*20d062caSAndreas Gohr            'icon'   => 'chars.png',
163*20d062caSAndreas Gohr            'list'   => explode(' ','À à Á á Â â Ã ã Ä ä Ǎ ǎ Ă ă Å å Ā ā Ą ą Æ æ Ć ć Ç ç Č č Ĉ ĉ Ċ ċ Ð đ ð Ď ď È è É é Ê ê Ë ë Ě ě Ē ē Ė ė Ę ę Ģ ģ Ĝ ĝ Ğ ğ Ġ ġ Ĥ ĥ Ì ì Í í Î î Ï ï Ǐ ǐ Ī ī İ ı Į į Ĵ ĵ Ķ ķ Ĺ ĺ Ļ ļ Ľ ľ Ł ł Ŀ ŀ Ń ń Ñ ñ Ņ ņ Ň ň Ò ò Ó ó Ô ô Õ õ Ö ö Ǒ ǒ Ō ō Ő ő Ø ø Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ş ş Š š Ŝ ŝ Ţ ţ Ť ť Ù ù Ú ú Û û Ü ü Ǔ ǔ Ŭ ŭ Ū ū Ů ů ǖ ǘ ǚ ǜ Ų ų Ű ű Ŵ ŵ Ý ý Ÿ ÿ Ŷ ŷ Ź ź Ž ž Ż ż Þ þ ß Ħ ħ ¿ ¡ ¢ £ ¤ ¥ € ¦ § ª ¬ ¯ ° ± ÷ ‰ ¼ ½ ¾ ¹ ² ³ µ ¶ † ‡ · • º ∀ ∂ ∃ Ə ə ∅ ∇ ∈ ∉ ∋ ∏ ∑ ‾ − ∗ √ ∝ ∞ ∠ ∧ ∨ ∩ ∪ ∫ ∴ ∼ ≅ ≈ ≠ ≡ ≤ ≥ ⊂ ⊃ ⊄ ⊆ ⊇ ⊕ ⊗ ⊥ ⋅ ◊ ℘ ℑ ℜ ℵ ♠ ♣ ♥ ♦'),
164*20d062caSAndreas Gohr           ),
165*20d062caSAndreas Gohr    );
166*20d062caSAndreas Gohr
167*20d062caSAndreas Gohr    // if logged in add sig button
168*20d062caSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
169*20d062caSAndreas Gohr        $menu[] = array(
170*20d062caSAndreas Gohr            'type'   => 'insert',
171*20d062caSAndreas Gohr            'title'  => $lang['qb_sig'],
172*20d062caSAndreas Gohr            'icon'   => 'sig.png',
173*20d062caSAndreas Gohr            'key'    => 'y',
174*20d062caSAndreas Gohr            'insert' => toolbar_signature(),
175*20d062caSAndreas Gohr            );
176*20d062caSAndreas Gohr    }
177*20d062caSAndreas Gohr
178*20d062caSAndreas Gohr    // use JSON to build the JavaScript array
179*20d062caSAndreas Gohr    $json = new JSON();
180*20d062caSAndreas Gohr    print "var $varname = ".$json->encode($menu).";\n";
181*20d062caSAndreas Gohr}
182*20d062caSAndreas Gohr
183*20d062caSAndreas Gohr/**
184*20d062caSAndreas Gohr * prepares the signature string as configured in the config
185*20d062caSAndreas Gohr *
186*20d062caSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
187*20d062caSAndreas Gohr */
188*20d062caSAndreas Gohrfunction toolbar_signature(){
189*20d062caSAndreas Gohr  global $conf;
190*20d062caSAndreas Gohr  global $INFO;
191*20d062caSAndreas Gohr
192*20d062caSAndreas Gohr  $sig = $conf['signature'];
193*20d062caSAndreas Gohr  $sig = strftime($sig);
194*20d062caSAndreas Gohr  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
195*20d062caSAndreas Gohr  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
196*20d062caSAndreas Gohr  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
197*20d062caSAndreas Gohr  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
198*20d062caSAndreas Gohr  return $sig;
199*20d062caSAndreas Gohr}
200*20d062caSAndreas Gohr
201*20d062caSAndreas Gohr
202*20d062caSAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
203