1<?php
2
3/**
4 * Changes Plugin: List the most recent changes of the wiki
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Andreas Gohr <andi@splitbrain.org>
8 * @author     Mykola Ostrovskyy <spambox03@mail.ru>
9 */
10
11/**
12 * Class action_plugin_changes
13 */
14class action_plugin_changes extends DokuWiki_Action_Plugin
15{
16    /**
17     * Register callbacks
18     * @param Doku_Event_Handler $controller
19     */
20    public function register(Doku_Event_Handler $controller)
21    {
22        $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'beforeParserCacheUse');
23    }
24
25    /**
26     * Handle PARSER_CACHE_USE:BEFORE event
27     * @param Doku_Event $event
28     */
29    public function beforeParserCacheUse($event)
30    {
31        global $ID;
32        $cache = $event->data;
33        if (isset($cache->mode) && ($cache->mode == 'xhtml')) {
34            $depends = p_get_metadata($ID, 'relation depends');
35            if (!empty($depends) && isset($depends['rendering'])) {
36                $this->addDependencies($cache, array_keys($depends['rendering']));
37            }
38        }
39    }
40
41    /**
42     * Add extra dependencies to the cache
43     */
44    protected function addDependencies($cache, $depends)
45    {
46        // Prevent "Warning: in_array() expects parameter 2 to be array, null given"
47        if (!is_array($cache->depends)) {
48            $cache->depends = array();
49        }
50        if (!array_key_exists('files', $cache->depends)) {
51            $cache->depends['files'] = array();
52        }
53
54        foreach ($depends as $file) {
55            if (!in_array($file, $cache->depends['files']) && @file_exists($file)) {
56                $cache->depends['files'][] = $file;
57            }
58        }
59    }
60}
61
62//Setup VIM: ex: et ts=4 enc=utf-8 :
63