1<?php
2/**
3 * DokuWiki Plugin ghissues (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Zach Smith <zsmith12@umd.edu>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_ghissues_cacheHandler 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('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_parser_cache_use');
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_parser_cache_use(Doku_Event &$event, $param) {
36		$pageCache =& $event->data;
37
38		//dbglog("ghissues: In handle_parser_cache_use");
39
40		// We only do anything if it is rendering xhtml
41		if( !isset($pageCache->page) ) return;
42		if( !isset($pageCache->mode) || $pageCache->mode != 'xhtml' ) return;
43
44		$apiRequests = p_get_metadata($pageCache->page, 'plugin_ghissues_apicalls');
45		if ( !is_array($apiRequests) ) return; // No ghissues api calls
46
47		$loadFromCache = $this->loadHelper('ghissues_apiCacheInterface');
48		//dbglog('ghissues: handleParser '.var_export($apiRequests, TRUE));
49		foreach($apiRequests as $apiURL => $apiHash) {
50			$pageCache->depends['files'][]= $loadFromCache->checkIssuesCache($apiURL);
51			//dbglog('ghissues: '.$loadFromCache->checkIssuesCache($apiURL));
52		}
53    	return;
54    }
55
56}
57
58// vim:ts=4:sw=4:et:
59