xref: /dokuwiki/lib/plugins/styling/action.php (revision 920904359a7088e3cf3885a96c03c453aa9e4095)
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 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Class action_plugin_styling
14 *
15 * This handles all the save actions and loading the interface
16 *
17 * All this usually would be done within an admin plugin, but we want to have this available outside
18 * the admin interface using our floating dialog.
19 */
20class action_plugin_styling extends DokuWiki_Action_Plugin {
21
22    /**
23     * Registers a callback functions
24     *
25     * @param Doku_Event_Handler $controller DokuWiki's event controller object
26     * @return void
27     */
28    public function register(Doku_Event_Handler $controller) {
29        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header');
30    }
31
32    /**
33     * Adds the preview parameter to the stylesheet loading in non-js mode
34     *
35     * @param Doku_Event $event  event object by reference
36     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
37     *                           handler was registered]
38     * @return void
39     */
40    public function handle_header(Doku_Event &$event, $param) {
41        global $ACT;
42        global $INPUT;
43        if($ACT != 'admin' || $INPUT->str('page') != 'styling') return;
44        if(!auth_isadmin()) return;
45
46        // set preview
47        $len = count($event->data['link']);
48        for($i = 0; $i < $len; $i++) {
49            if(
50                $event->data['link'][$i]['rel'] == 'stylesheet' &&
51                strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
52            ) {
53                $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time();
54            }
55        }
56    }
57
58}
59
60// vim:ts=4:sw=4:et:
61