1<?php
2/**
3 * ODT Plugin: extends the dependencies of the cache with ODT related files
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Aurelien Bompard <aurelien@bompard.org>
7 * @author       Florian Lamml <info@florian-lamml.de>
8 */
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Add the template as a page dependency for the caching system
14 *
15 * @package DokuWiki\Action\Cache
16 */
17class action_plugin_odt_cache extends DokuWiki_Action_Plugin {
18    protected $config = null;
19
20    /**
21     * Register the event
22     *
23     * @param Doku_Event_Handler $controller
24     */
25    public function register(Doku_Event_Handler $controller) {
26        $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_cache_prepare');
27    }
28
29    /**
30     * Add dependencies to cache
31     *
32     * @param Doku_Event $event
33     */
34    public function handle_cache_prepare(Doku_Event $event) {
35        // Load config helper if not done yet
36        if ( $this->config == NULL ) {
37            $this->config = plugin_load('helper', 'odt_config');
38            $this->config->load($warning);
39        }
40
41        $cache =& $event->data;
42        // only the ODT rendering mode needs caching tweaks
43        if($cache->mode != "odt") return;
44
45        $template_name = $this->config->getParam('odt_template');
46        if(!$template_name) {
47            return;
48        }
49        $template_path = $this->config->getParam('mediadir') . '/' . $this->config->getParam('tpl_dir') . "/" . $template_name;
50        if(file_exists($template_path)) {
51            $cache->depends['files'][] = $template_path;
52        }
53    }
54
55}
56