xref: /dokuwiki/lib/plugins/styling/action.php (revision a087da71ea972d05ca659a1e9406c87aa7ae258b)
1<?php
2/**
3 * DokuWiki Plugin styling (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <andi@splitbrain.org>
7 */
8class action_plugin_styling extends DokuWiki_Action_Plugin {
9
10    /**
11     * Registers a callback functions
12     *
13     * @param Doku_Event_Handler $controller DokuWiki's event controller object
14     * @return void
15     */
16    public function register(Doku_Event_Handler $controller) {
17        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header');
18    }
19
20    /**
21     * Adds the preview parameter to the stylesheet loading in non-js mode
22     *
23     * @param Doku_Event $event  event object by reference
24     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
25     *                           handler was registered]
26     * @return void
27     */
28    public function handle_header(Doku_Event &$event, $param) {
29        global $ACT;
30        global $INPUT;
31        if($ACT != 'admin' || $INPUT->str('page') != 'styling') return;
32        if(!auth_isadmin()) return;
33
34        // set preview
35        $len = count($event->data['link']);
36        for($i = 0; $i < $len; $i++) {
37            if(
38                $event->data['link'][$i]['rel'] == 'stylesheet' &&
39                strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
40            ) {
41                $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time();
42            }
43        }
44    }
45
46}
47
48// vim:ts=4:sw=4:et:
49