1<?php
2/**
3 * DokuWiki Plugin filelisting (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Szymon Olewniczak <dokuwiki@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_filelisting_js extends DokuWiki_Action_Plugin {
13
14    /**
15     * Registers a callback function for a given event
16     *
17     * @param Doku_Event_Handler $controller DokuWiki's event controller object
18     * @return void
19     */
20    public function register(Doku_Event_Handler $controller) {
21
22        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_dokuwiki_started');
23
24    }
25
26    /**
27     * Set the JSINFO
28     *
29     * @param Doku_Event $event  event object by reference
30     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
31     *                           handler was registered]
32     * @return void
33     */
34
35    public function handle_dokuwiki_started(Doku_Event &$event, $param) {
36        //load conf
37        $this->jsinfo('defaulttoggle', $this->getConf('defaulttoggle'));
38
39        /** @var helper_plugin_filelisting $filelisting */
40        $filelisting = $this->loadHelper('filelisting');
41
42        $this->jsinfo('dirOpenedIcon', $filelisting->dirOpenedIcon());
43        $this->jsinfo('dirClosedIcon', $filelisting->dirClosedIcon());
44        $this->jsinfo('loadingIcon', $filelisting->loadingIcon());
45        $this->jsinfo('remember_state_per_page', $this->getConf('remember_state_per_page') === 'page');
46    }
47
48    /**
49     * Add a value to JSINFO['plugin'][plugin name]
50     *
51     * @param      $key
52     * @param      $value
53     */
54    protected function jsinfo($key, $value) {
55        global $JSINFO;
56
57        $pname = $this->getPluginName();
58        //using metadata convention
59        if (!isset($JSINFO['plugin'])) $JSINFO['plugin'] = array();
60        if (!isset($JSINFO['plugin'][$pname])) $JSINFO['plugin'][$pname] = array();
61
62        $JSINFO['plugin'][$pname][$key] = $value;
63    }
64}
65
66// vim:ts=4:sw=4:et:
67