1<?php
2/**
3 * DokuWiki Plugin mediacacheconfig (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <grosse@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_mediacacheconfig extends DokuWiki_Action_Plugin {
13
14    /**
15     * Registers a callback function for a given event
16     *
17     * @param Doku_Event_Handler $controller DokuWiki's event controller object
18     * @return void
19     */
20    public function register(Doku_Event_Handler $controller) {
21
22       $controller->register_hook('FETCH_MEDIA_STATUS', 'AFTER', $this, 'handle_fetch_media_status');
23
24    }
25
26    /**
27     * [Custom event handler which performs action]
28     *
29     * @param Doku_Event $event  event object by reference
30     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
31     *                           handler was registered]
32     * @return void
33     */
34
35    public function handle_fetch_media_status(Doku_Event $event, $param) {
36        global $INPUT;
37
38        if ($INPUT->has('cache')) {
39            // do nothing if cache behavior has been explicitly defined
40            return;
41        }
42
43        if ($this->getConf('always-validate') === '1') {
44            $event->data['cache'] = 0;
45        }
46    }
47
48}
49
50// vim:ts=4:sw=4:et:
51