Failed Conditions
Push — psr2 ( e79ce3...5aa905 )
by Andreas
05:02
created

action_plugin_styling::handle_header()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 11
nc 5
nop 2
dl 0
loc 17
rs 8.2222
c 0
b 0
f 0
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 <[email protected]>
7
 */
8
class action_plugin_styling extends DokuWiki_Action_Plugin
9
{
10
11
    /**
12
     * Registers a callback functions
13
     *
14
     * @param Doku_Event_Handler $controller DokuWiki's event controller object
15
     * @return void
16
     */
17
    public function register(Doku_Event_Handler $controller)
18
    {
19
        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader');
20
    }
21
22
    /**
23
     * Adds the preview parameter to the stylesheet loading in non-js mode
24
     *
25
     * @param Doku_Event $event  event object by reference
26
     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
27
     *                           handler was registered]
28
     * @return void
29
     */
30
    public function handleHeader(Doku_Event &$event, $param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        global $ACT;
33
        global $INPUT;
34
        if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return;
35
        if (!auth_isadmin()) return;
36
37
        // set preview
38
        $len = count($event->data['link']);
39
        for ($i = 0; $i < $len; $i++) {
40
            if ($event->data['link'][$i]['rel'] == 'stylesheet' &&
41
                strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
42
            ) {
43
                $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time();
44
            }
45
        }
46
    }
47
}
48
49
// vim:ts=4:sw=4:et:
50