xref: /dokuwiki/lib/plugins/styling/action.php (revision 5c48379643fe73c0682a2770d0abc793c9bd1513)
1123bc813SAndreas Gohr<?php
2d4f83172SAndreas Gohr
38553d24dSAndreas Gohruse dokuwiki\Extension\ActionPlugin;
48553d24dSAndreas Gohruse dokuwiki\Extension\EventHandler;
58553d24dSAndreas Gohruse dokuwiki\Extension\Event;
6d4f83172SAndreas Gohr
7123bc813SAndreas Gohr/**
8123bc813SAndreas Gohr * DokuWiki Plugin styling (Action Component)
9123bc813SAndreas Gohr *
10123bc813SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
11123bc813SAndreas Gohr * @author  Andreas Gohr <andi@splitbrain.org>
12123bc813SAndreas Gohr */
138553d24dSAndreas Gohrclass action_plugin_styling extends ActionPlugin
1471a75f04SAndreas Gohr{
15123bc813SAndreas Gohr    /**
16123bc813SAndreas Gohr     * Registers a callback functions
17123bc813SAndreas Gohr     *
18*5c483796SAndreas Gohr     * @param EventHandler $controller DokuWiki's event controller object
19123bc813SAndreas Gohr     * @return void
20123bc813SAndreas Gohr     */
218553d24dSAndreas Gohr    public function register(EventHandler $controller)
2271a75f04SAndreas Gohr    {
2371a75f04SAndreas Gohr        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader');
24123bc813SAndreas Gohr    }
25123bc813SAndreas Gohr
26123bc813SAndreas Gohr    /**
27123bc813SAndreas Gohr     * Adds the preview parameter to the stylesheet loading in non-js mode
28123bc813SAndreas Gohr     *
29*5c483796SAndreas Gohr     * @param Event $event event object by reference
30123bc813SAndreas Gohr     * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
31123bc813SAndreas Gohr     *                      handler was registered]
32123bc813SAndreas Gohr     * @return void
33123bc813SAndreas Gohr     */
348553d24dSAndreas Gohr    public function handleHeader(Event &$event, $param)
3571a75f04SAndreas Gohr    {
36123bc813SAndreas Gohr        global $ACT;
37123bc813SAndreas Gohr        global $INPUT;
38123bc813SAndreas Gohr        if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return;
39dda9db03SAndreas Gohr        /** @var admin_plugin_styling $admin */
40dda9db03SAndreas Gohr        $admin = plugin_load('admin', 'styling');
41dda9db03SAndreas Gohr        if (!$admin->isAccessibleByCurrentUser()) return;
42123bc813SAndreas Gohr
43123bc813SAndreas Gohr        // set preview
44123bc813SAndreas Gohr        $len = count($event->data['link']);
45123bc813SAndreas Gohr        for ($i = 0; $i < $len; $i++) {
467d34963bSAndreas Gohr            if (
477d34963bSAndreas Gohr                $event->data['link'][$i]['rel'] == 'stylesheet' &&
48123bc813SAndreas Gohr                strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
49123bc813SAndreas Gohr            ) {
50123bc813SAndreas Gohr                $event->data['link'][$i]['href'] .= '&preview=1&tseed=' . time();
51123bc813SAndreas Gohr            }
52123bc813SAndreas Gohr        }
53123bc813SAndreas Gohr    }
54123bc813SAndreas Gohr}
55123bc813SAndreas Gohr
56123bc813SAndreas Gohr// vim:ts=4:sw=4:et:
57