xref: /dokuwiki/lib/plugins/styling/action.php (revision 71a75f041e8e73a77d75db26da40a770a58dccbe)
1123bc813SAndreas Gohr<?php
2123bc813SAndreas Gohr/**
3123bc813SAndreas Gohr * DokuWiki Plugin styling (Action Component)
4123bc813SAndreas Gohr *
5123bc813SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6123bc813SAndreas Gohr * @author  Andreas Gohr <andi@splitbrain.org>
7123bc813SAndreas Gohr */
8*71a75f04SAndreas Gohrclass action_plugin_styling extends DokuWiki_Action_Plugin
9*71a75f04SAndreas Gohr{
10123bc813SAndreas Gohr
11123bc813SAndreas Gohr    /**
12123bc813SAndreas Gohr     * Registers a callback functions
13123bc813SAndreas Gohr     *
14123bc813SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
15123bc813SAndreas Gohr     * @return void
16123bc813SAndreas Gohr     */
17*71a75f04SAndreas Gohr    public function register(Doku_Event_Handler $controller)
18*71a75f04SAndreas Gohr    {
19*71a75f04SAndreas Gohr        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader');
20123bc813SAndreas Gohr    }
21123bc813SAndreas Gohr
22123bc813SAndreas Gohr    /**
23123bc813SAndreas Gohr     * Adds the preview parameter to the stylesheet loading in non-js mode
24123bc813SAndreas Gohr     *
25123bc813SAndreas Gohr     * @param Doku_Event $event  event object by reference
26123bc813SAndreas Gohr     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
27123bc813SAndreas Gohr     *                           handler was registered]
28123bc813SAndreas Gohr     * @return void
29123bc813SAndreas Gohr     */
30*71a75f04SAndreas Gohr    public function handleHeader(Doku_Event &$event, $param)
31*71a75f04SAndreas Gohr    {
32123bc813SAndreas Gohr        global $ACT;
33123bc813SAndreas Gohr        global $INPUT;
34123bc813SAndreas Gohr        if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return;
35123bc813SAndreas Gohr        if (!auth_isadmin()) return;
36123bc813SAndreas Gohr
37123bc813SAndreas Gohr        // set preview
38123bc813SAndreas Gohr        $len = count($event->data['link']);
39123bc813SAndreas Gohr        for ($i = 0; $i < $len; $i++) {
40*71a75f04SAndreas Gohr            if ($event->data['link'][$i]['rel'] == 'stylesheet' &&
41123bc813SAndreas Gohr                strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
42123bc813SAndreas Gohr            ) {
43123bc813SAndreas Gohr                $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time();
44123bc813SAndreas Gohr            }
45123bc813SAndreas Gohr        }
46123bc813SAndreas Gohr    }
47123bc813SAndreas Gohr}
48123bc813SAndreas Gohr
49123bc813SAndreas Gohr// vim:ts=4:sw=4:et:
50