dokuwiki-source-plugin – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 1 | <?php |
2 | /** |
||
3 | * Source Plugin: includes a source file using the geshi highlighter |
||
4 | * |
||
5 | * Action plugin component, for cache validity determination |
||
6 | * |
||
7 | * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
||
4 | office | 8 | * @author Christopher Smith <chris@jalakai.co.uk> |
1 | eva | 9 | */ |
4 | office | 10 | if(!defined('DOKU_INC')) die(); // no DokuWiki, no go |
11 | |||
1 | eva | 12 | if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); |
13 | require_once(DOKU_PLUGIN.'action.php'); |
||
4 | office | 14 | |
1 | eva | 15 | /** |
16 | * All DokuWiki plugins to extend the parser/rendering mechanism |
||
17 | * need to inherit from this class |
||
18 | */ |
||
19 | class action_plugin_source extends DokuWiki_Action_Plugin { |
||
4 | office | 20 | |
1 | eva | 21 | /** |
22 | * return some info |
||
23 | */ |
||
24 | function getInfo(){ |
||
25 | return array( |
||
4 | office | 26 | 'author' => 'Christopher Smith', |
27 | 'email' => 'chris@jalakai.co.uk', |
||
28 | 'date' => '2008-08-13', |
||
1 | eva | 29 | 'name' => 'Source Plugin', |
30 | 'desc' => 'Include a remote source file', |
||
4 | office | 31 | 'url' => 'http://www.dokuwiki.org/plugin:source', |
1 | eva | 32 | ); |
33 | } |
||
4 | office | 34 | |
1 | eva | 35 | /** |
4 | office | 36 | * plugin should use this method to register its handlers with the DokuWiki's event controller |
1 | eva | 37 | */ |
3 | office | 38 | function register(Doku_Event_Handler $controller) { |
1 | eva | 39 | $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare'); |
40 | } |
||
4 | office | 41 | |
1 | eva | 42 | /** |
43 | * prepare the cache object for default _useCache action |
||
44 | */ |
||
45 | function _cache_prepare(&$event, $param) { |
||
46 | $cache =& $event->data; |
||
4 | office | 47 | |
1 | eva | 48 | // we're only interested in wiki pages and supported render modes |
49 | if (!isset($cache->page)) return; |
||
50 | if (!isset($cache->mode) || in_array($cache->mode,array('i','metadata'))) return; |
||
4 | office | 51 | |
1 | eva | 52 | $max_age = $this->_cache_maxage($cache->page); |
53 | if (is_null($max_age)) return; |
||
4 | office | 54 | |
1 | eva | 55 | if ($max_age <= 0) { |
56 | // expire the cache |
||
57 | $event->preventDefault(); |
||
58 | $event->stopPropagation(); |
||
59 | $event->result = false; |
||
60 | return; |
||
61 | } |
||
4 | office | 62 | |
1 | eva | 63 | $cache->depends['age'] = !empty($cache->depends['age']) ? min($cache->depends['age'],$max_age): $max_age; |
64 | } |
||
4 | office | 65 | |
1 | eva | 66 | /** |
67 | * determine the max allowable age of the cache |
||
68 | * |
||
69 | * @param string $id wiki page name |
||
70 | * |
||
71 | * @return int max allowable age of the cache |
||
72 | * null means not applicable |
||
73 | */ |
||
74 | function _cache_maxage($id) { |
||
75 | $hasPart = p_get_metadata($id, 'relation haspart'); |
||
76 | if (empty($hasPart) || !is_array($hasPart)) return null; |
||
4 | office | 77 | |
1 | eva | 78 | $location = $this->getConf('location'); |
4 | office | 79 | |
1 | eva | 80 | $age = 0; |
81 | foreach ($hasPart as $file => $data) { |
||
82 | // ensure the metadata entry was created by or for this plugin |
||
83 | if (empty($data['owner']) || $data['owner'] != $this->getPluginName()) continue; |
||
4 | office | 84 | |
1 | eva | 85 | $file = $this->getConf['location'].$file; |
4 | office | 86 | |
1 | eva | 87 | // determine max allowable age for the cache |
88 | // if filemtime can't be determined, either for a non-existent $file or for a $file using |
||
89 | // an unsupported scheme, expire the cache immediately/always |
||
90 | $mtime = @filemtime($file); |
||
91 | if (!$mtime) { return 0; } |
||
4 | office | 92 | |
1 | eva | 93 | $age = max($age,$mtime); |
94 | } |
||
4 | office | 95 | |
1 | eva | 96 | return $age ? time()-$age : null; |
97 | } |
||
4 | office | 98 | |
1 | eva | 99 | } |
4 | office | 100 | |
101 | //Setup VIM: ex: et ts=4 enc=utf-8 : |
||
1 | eva | 102 |