1<?php 2 3/** 4 5 * DokuWiki Plugin footer (Action Component) 6 7 * 8 9 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 10 11 * 12 13 * Original: from Plugin headerfooter, author Li Zheng <lzpublic@qq.com> 14 15 * Modified by Juergen H-J-Schuemmer@Web.de 16 17 * Only the footer component is supported in this plugin because the header functionality breaks the section edit mode 18 19 */ 20 21 22// must be run within Dokuwiki 23 24if(!defined('DOKU_INC')) die(); 25 26 27class action_plugin_footerv2 extends DokuWiki_Action_Plugin { 28 29 public function register(Doku_Event_Handler $controller) { 30 31 32 $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'AFTER', $this, 'handle_parser_wikitext_preprocess'); 33 34 // aus Seite "https://github.com/MrBertie/pagequery/commit/6cae014dc7cc779c0be8d0a660af42407b414806": 35 36 $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, '_purgecache'); 37 38 } 39 40 public function handle_parser_wikitext_preprocess(Doku_Event &$event, $param) { 41 42 global $INFO; 43 44 global $ID; 45 46 global $conf; 47 48 //what does this mean??? 49 50 if ($INFO['id'] != '') return; // Jede Seite wird zweimal ausgeführt. Wenn die ID leer ist, ist es der echte Text, andernfalls ist es das Menü. 51 52 53 //helper array needed for parsePageTemplate 54 55 //so that replacement like shown here is possible: https://www.dokuwiki.org/namespace_templates#replacement_patterns 56 57 $data = array( 58 59 'id' => $ID, // the id of the page to be created 60 61 'tpl' => '', // the text used as template 62 63 ); 64 65 66 // Auslesen der Konfiguration für das Präfix der Vorlage-Dateien: 67 68 $pre_nsp = $this->getConf('prefix_namespace'); 69 70 if ($pre_nsp != '') { 71 72 $pre_nsp = '/'.$pre_nsp.'_'; 73 74 } else { 75 76 $pre_nsp = '/_'; // Defaultwert 1 Unterstrich für Namespace 77 78 }; 79 80 $pre_sub = $this->getConf('prefix_subnamespace'); 81 82 if ($pre_sub != '') { 83 84 $pre_sub = '/'.$pre_sub.'_'; 85 86 } else { 87 88 $pre_sub = '/__'; // Defaultwert 2 Unterstriche für Sub-Namespace 89 90 }; 91 92 93 $footerpath = ''; 94 95 $templatename = 'footer.txt'; // Name der Vorlage 96 97 $path = dirname(wikiFN($ID)); 98 99 if (@file_exists($path.$pre_nsp.$templatename)) { 100 101 $footerpath = $path.$pre_nsp.$templatename; 102 103 } else { 104 105 // search upper namespaces for templates 106 107 $len = strlen(rtrim($conf['datadir'], '/')); 108 109 while (strlen($path) >= $len) { 110 111 if (@file_exists($path.$pre_sub.$templatename)) { 112 113 $footerpath = $path.$pre_sub.$templatename; 114 115 break; 116 117 } 118 119 $path = substr($path, 0, strrpos($path, '/')); 120 121 } 122 123 } 124 125 126 if (!empty($footerpath)) { 127 128 $content = $event->data; 129 130 if(strpos($content,"~~NOFOOTER~~") == false) { 131 132 // Prüfung. ob der Befehl "~~NOFOOTER~~" im Quelltext enthalten ist 133 134 $footer = file_get_contents($footerpath); 135 136 if ($footer !== false) { 137 138 $data['tpl'] = cleanText($footer); 139 140 $footer = parsePageTemplate($data); 141 142 if ($this->getConf('separation') == 'paragraph') { 143 144 // Wenn Absätze zum Teilen verwendet werden 145 146 $footer = rtrim($footer, " \r\n\\") . "\n\n"; 147 148 } 149 150 $event->data .= $footer; 151 152 } 153 154 /* 155 156 // Code übernommen von Seite "https://www.dokuwiki.org/devel:event_handlers_code#caching": 157 158 $event->preventDefault(); // stop dokuwiki carrying out its own checks 159 160 $event->stopPropagation(); // avoid other handlers of this event, changing our decision here 161 162 $event->result = false; // don't use the cached version 163 164 */ 165 166 } else { 167 168 $event->data = str_replace('~~NOFOOTER~~','',$content); 169 170 // Befehl "~~NOFOOTER~~" soll nicht angezeigt werden 171 172 } 173 174 } 175 176 } 177 178 179 // Codeschnipsel aus Seite "https://github.com/MrBertie/pagequery/commit/6cae014dc7cc779c0be8d0a660af42407b414806": 180 181 /** 182 183 * Check for pages changes and eventually purge cache. 184 185 * 186 187 * @author Samuele Tognini <samuele@samuele.netsons.org> 188 189 * 190 191 * @param Doku_Event $event 192 193 * @param mixed $param not defined 194 195 */ 196 197 function _purgecache(&$event, $param) { 198 199 global $ID; 200 201 global $conf; 202 203 /** @var cache_parser $cache */ 204 205 $cache = &$event->data; 206 207 208 if(!isset($cache->page)) return; 209 210 //purge only xhtml cache 211 212 if($cache->mode != "xhtml") return; 213 214 //Check if it is an pagequery page 215 216 if(!p_get_metadata($ID, 'pagequery')) return; 217 218 $aclcache = $this->getConf('aclcache'); 219 220 if($conf['useacl']) { 221 222 $newkey = false; 223 224 if($aclcache == 'user') { 225 226 //Cache per user 227 228 if($_SERVER['REMOTE_USER']) $newkey = $_SERVER['REMOTE_USER']; 229 230 } else if($aclcache == 'groups') { 231 232 //Cache per groups 233 234 global $INFO; 235 236 if($INFO['userinfo']['grps']) $newkey = implode('#', $INFO['userinfo']['grps']); 237 238 } 239 240 if($newkey) { 241 242 $cache->key .= "#".$newkey; 243 244 $cache->cache = getCacheName($cache->key, $cache->ext); 245 246 } 247 248 } 249 250 //Check if a page is more recent than purgefile. 251 252 if(@filemtime($cache->cache) < @filemtime($conf['cachedir'].'/purgefile')) { 253 254 $event->preventDefault(); 255 256 $event->stopPropagation(); 257 258 $event->result = false; 259 260 } 261 } 262}