This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
68 lines (55 loc) · 2.05 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* DokuWiki Plugin Templatery (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Brend Wanders <b.wanders@utwente.nl>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die('Meh.');
/**
* This plugin takes care of the cache check.
*/
class action_plugin_templatery extends DokuWiki_Action_Plugin {
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, '_check_cache');
}
public function _check_cache(&$event, $param) {
$cache =& $event->data;
// ignore cache requests for things we don't influence
if(!isset($cache->page) || !in_array($cache->mode, array('xhtml','metadata'))) return;
// retrieve metadata on the page we're rendering
$pages = p_get_metadata($cache->page, 'plugin_templatery');
// no metadata -> ignore
if(!is_array($pages)) return;
// check change in actual list
$actual = array();
foreach($pages['all'] as $p) {
if(auth_quickaclcheck($p) >= AUTH_READ) $actual[] = $p;
}
// If list of included pages has changed, purge
if($pages['actual'] != $actual) {
$cache->depends['purge'] = true;
}
// Depend on all actually included pages, so we get updated if the template changes
$cache->depends['files'] = array_merge($cache->depends['files'], array_map('wikiFN',$pages['actual']));
}
}
/**
* Templatery 'pluggable' autoloader. This function is responsible
* for autoloading classes.
*
* @param fullname string the name of the class to load
*/
function plugin_templatery_autoload($fullname) {
static $classes = null;
if(is_null($classes)) $classes = array(
'templatery_handler' => DOKU_PLUGIN.'templatery/lib/templatery_handler.php',
);
if(isset($classes[$fullname])) {
require_once($classes[$fullname]);
return;
}
}
// register autoloader with SPL loader stack
spl_autoload_register('plugin_templatery_autoload');