1<?php
2/**
3 * Action module for vkeyboard plugin
4 *
5 * @author Myron Turner <turnermm02@shaw.ca>
6 */
7
8if(!defined('DOKU_INC')) die();
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once DOKU_PLUGIN.'action.php';
11
12class action_plugin_vkeyboard extends DokuWiki_Action_Plugin {
13
14    /**
15     * Register its handlers with the DokuWiki's event controller
16     */
17    function register(Doku_Event_Handler $controller) {
18
19        $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'setVKIcookie');
20
21        if(!isset($_COOKIE['VKB'])) return;
22
23        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this,
24                                   '_hookjs');
25        $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this,
26                                   'vki_start');
27
28
29    }
30
31    /**
32     * Hook js script into page headers.
33     *
34     * @author Myron Turner <turnermm02@shaw.ca>
35     */
36    function _hookjs(&$event, $param) {
37        global $conf;
38        $lang = $conf['lang'];
39        echo '<script type="text/javascript">' . "\n" .
40             'var VKI_KBLAYOUT= "' . $_COOKIE['VKB'] . '";' .
41             "\nvar VKI_locale='$lang';\n</script>\n";
42
43        $event->data['script'][] = array(
44                            'type'    => 'text/javascript',
45                            'charset' => 'utf-8',
46                            '_data'   => '',
47                            'src'     => DOKU_BASE . 'lib/plugins/vkeyboard/vkeyboard.js');
48    }
49
50   function vki_start(&$event, $param) {
51    echo '<script type="text/javascript">
52    if(document.getElementById("wiki__text")) {
53       var myInput = document.getElementById("wiki__text");
54       if (!myInput.VKI_attached) {
55        VKI_attach(myInput);
56      }
57    }
58    </script>';
59
60   }
61  function setVKIcookie(&$event, $param) {
62
63       if(isset($_REQUEST['vkb']) && $_REQUEST['vkb']) {
64          if($matches = preg_match('/(off)-(.*)/',($_REQUEST['vkb']))) {
65            $expire = time()-(60*60*24);
66            setcookie ('VKB',$matches[1], $expire, DOKU_BASE);
67          }
68          else {
69            $expire = null;
70            setcookie ('VKB',$_REQUEST['vkb'], $expire, DOKU_BASE);
71         }
72     }
73  }
74}
75
76