1<?php
2/**
3 *
4 * @license   GPL 2 (http://www.gnu.org/licenses/gpl.html)
5 * @author    Tom N Harris <tnharris@whoopdedo.org>
6 */
7
8// must be run within DokuWiki
9if(!defined('DOKU_INC')) die();
10
11class action_plugin_formatplus2 extends DokuWiki_Action_Plugin {
12
13  /**
14   * register the eventhandlers
15   */
16  function register(Doku_Event_Handler $contr){
17    $contr->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'toolbar_event', array());
18  }
19
20  /**
21   *
22   * @author  Tom N Harris    <tnharris@whoopdedo.org>
23   */
24  function toolbar_event(Doku_Event $event, $param){
25    $disabled = explode(',',$this->getConf('disable_syntax'));
26    $disabled = array_map('trim',$disabled);
27    $buttons = array();
28    if (!in_array('smallcaps', $disabled))
29      $buttons[] = array(
30          'type'  => 'format',
31          'title' => $this->getLang('smallcaps'),
32          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/caps.png',
33          'open'  => '!!',
34          'close' => '!!',
35          'block' => false
36          );
37    if (!in_array('sample', $disabled))
38      $buttons[] = array(
39          'type'  => 'format',
40          'title' => $this->getLang('sample'),
41          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/samp.png',
42          'open'  => '$$',
43          'close' => '$$',
44          'block' => false
45          );
46    if (!in_array('variable', $disabled))
47      $buttons[] = array(
48          'type'  => 'format',
49          'title' => $this->getLang('variable'),
50          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/var.png',
51          'open'  => '??',
52          'close' => '??',
53          'block' => false
54          );
55    if (!in_array('keyboard', $disabled))
56      $buttons[] = array(
57          'type'  => 'format',
58          'title' => $this->getLang('keyboard'),
59          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/kbd.png',
60          'open'  => '``',
61          'close' => '``',
62          'block' => false
63          );
64    if (!in_array('definition', $disabled))
65      $buttons[] = array(
66          'type'  => 'format',
67          'title' => $this->getLang('definition'),
68          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/dfn.png',
69          'open'  => '@@',
70          'close' => '@@',
71          'block' => false
72          );
73    if (!in_array('citation', $disabled))
74      $buttons[] = array(
75          'type'  => 'format',
76          'title' => $this->getLang('citation'),
77          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/cite.png',
78          'open'  => '&&',
79          'close' => '&&',
80          'block' => false
81          );
82    if (!in_array('inverse', $disabled))
83      $buttons[] = array(
84          'type'  => 'format',
85          'title' => $this->getLang('inverse'),
86          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/inv.png',
87          'open'  => '/!',
88          'close' => '!/',
89          'block' => false
90          );
91    if (!in_array('quote', $disabled)) {
92      $buttons[] = array(
93          'type'  => 'format',
94          'title' => $this->getLang('quote'),
95          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/q.png',
96          'open'  => '""',
97          'close' => '""',
98          'block' => false
99          );
100    }
101    $buttons2 = array();
102    if (!in_array('blockquote', $disabled))
103      $buttons2[] = array(
104          'type'  => 'format',
105          'title' => $this->getLang('blockquote'),
106          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/quote.png',
107          'open'  => '<quote >',
108          'close' => '</quote>',
109          'block' => true
110          );
111    if (!in_array('ins_del', $disabled)) {
112      $buttons2[] = array(
113          'type'  => 'format',
114          'title' => $this->getLang('insert'),
115          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/ins.png',
116          'open'  => '/+',
117          'close' => '+/',
118          'block' => false
119          );
120      $buttons2[] = array(
121          'type'  => 'format',
122          'title' => $this->getLang('blockinsert'),
123          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/insert.png',
124          'open'  => '<ins >',
125          'close' => '</ins>',
126          'block' => true
127          );
128      $buttons2[] = array(
129          'type'  => 'format',
130          'title' => $this->getLang('delete'),
131          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/del.png',
132          'open'  => '/-',
133          'close' => '-/',
134          'block' => false
135          );
136      $buttons2[] = array(
137          'type'  => 'format',
138          'title' => $this->getLang('blockdelete'),
139          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/delete.png',
140          'open'  => '<del >',
141          'close' => '</del>',
142          'block' => true
143          );
144    }
145    if (!in_array('super_sub', $disabled)) {
146      $buttons2[] = array(
147          'type'  => 'format',
148          'title' => $this->getLang('sub'),
149          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/sub.png',
150          'open'  => '/,',
151          'close' => ',/',
152          'block' => false
153          );
154      $buttons2[] = array(
155          'type'  => 'format',
156          'title' => $this->getLang('super'),
157          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/super.png',
158          'open'  => '/^',
159          'close' => '^/',
160          'block' => false
161          );
162    }
163    $menu =& $event->data;
164    if ($this->getConf('toplevel')) {
165      $menu = array_merge($menu, $buttons);
166      $menu[] = array(
167          'type'  => 'picker',
168          'title' => $this->getLang('title'),
169          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/formatplus.png',
170          'list'  => $buttons2,
171          'block' => true
172          );
173    } else {
174      $menu[] = array(
175          'type'  => 'picker',
176          'title' => $this->getLang('title'),
177          'icon'  => DOKU_BASE.'lib/plugins/formatplus2/images/formatplus.png',
178          'list'  => array_merge($buttons, $buttons2),
179          'block' => true
180          );
181    }
182  }
183
184}
185