1<?php 2/** 3 * DokuWiki Plugin notification (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Szymon Olewniczak <it@rid.pl> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14class action_plugin_notification_cache extends DokuWiki_Action_Plugin 15{ 16 17 /** 18 * Registers a callback function for a given event 19 * 20 * @param Doku_Event_Handler $controller DokuWiki's event controller object 21 * 22 * @return void 23 */ 24 public function register(Doku_Event_Handler $controller) 25 { 26 $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_parser_cache_use'); 27 } 28 29 /** 30 * 31 * @param Doku_Event $event event object by reference 32 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 33 * handler was registered] 34 * 35 * @return void 36 */ 37 public function handle_parser_cache_use(Doku_Event $event, $param) 38 { 39 /** @var cache_renderer $cache */ 40 $cache = $event->data; 41 42 if(!$cache->page) return; 43 //purge only xhtml cache 44 if($cache->mode != 'xhtml') return; 45 46 //Check if it is plugins 47 $notification = p_get_metadata($cache->page, 'plugin notification'); 48 if(!$notification) return; 49 50 if ($notification['dynamic user']) { 51 $cache->_nocache = true; 52 return; 53 } 54 55 $data = [ 56 'plugins' => $notification['plugins'], 57 'dependencies' => [], 58 '_nocache' => false 59 ]; 60 trigger_event('PLUGIN_NOTIFICATION_CACHE_DEPENDENCIES', $data); 61 62 //add a media directories to dependencies 63 $cache->depends['files'] = array_merge($cache->depends['files'], $data['dependencies']); 64 $cache->_nocache = $data['_nocache']; 65 } 66} 67