1<?php 2/** 3 * DokuWiki Plugin outdated (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Böhler <dev@aboehler.at> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12class helper_plugin_outdated extends DokuWiki_Plugin { 13 14 /** 15 * checks if an id is within one of the namespaces in $namespace_list 16 * taken from the publish plugin 17 * 18 * @param string $namespace_list 19 * @param string $id 20 * 21 * @return bool 22 */ 23 function in_namespace($namespace_list, $id) { 24 // PHP apparantly does not have closures - 25 // so we will parse $valid ourselves. Wasteful. 26 $namespace_list = preg_split('/\s+/', $namespace_list); 27 //if(count($valid) == 0) { return true; }//whole wiki matches 28 if((count($namespace_list)==1) and ($namespace_list[0]=="")) { return true; }//whole wiki matches 29 $id = trim($id, ':'); 30 $id = explode(':', $id); 31 32 // Check against all possible namespaces 33 foreach($namespace_list as $namespace) { 34 $namespace = explode(':', $namespace); 35 $current_ns_depth = 0; 36 $total_ns_depth = count($namespace); 37 $matching = true; 38 39 // Check each element, untill all elements of $v satisfied 40 while($current_ns_depth < $total_ns_depth) { 41 if( 42 !isset($id[$current_ns_depth]) || 43 !isset($namespace[$current_ns_depth]) || 44 $namespace[$current_ns_depth] != $id[$current_ns_depth] 45 ) { 46 // not a match 47 $matching = false; 48 break; 49 } 50 $current_ns_depth += 1; 51 } 52 if($matching) { return true; } // a match 53 } 54 return false; 55 } 56 57 function getLatestRevision() { 58 global $INFO; 59 return $INFO['meta']['date']['modified']; 60 } 61 62 function isActive($id = null) { 63 if ($id == null) { 64 global $ID; 65 $id = $ID; 66 } 67 if (!$this->in_namespace($this->getConf('outdated_namespaces'), $id)) { 68 return false; 69 } 70 71 return true; 72 } 73 74 function getOutdatedMessageForCurrentPage() { 75 global $INFO; 76 if(isset($INFO['meta']['plugin_outdated'])) { 77 return $INFO['meta']['plugin_outdated']['message']; 78 } else { 79 return $this->getConf('outdated_message'); 80 } 81 } 82 83 function getTimedeltaForCurrentPage() { 84 global $INFO; 85 if(isset($INFO['meta']['plugin_outdated'])) { 86 return $INFO['meta']['plugin_outdated']['timedelta']; 87 } else { 88 return $this->getConf('outdated_timedelta'); 89 } 90 } 91 92 function isCurrentRevisionOutdated() { 93 $ts = $this->getLatestRevision(); 94 $now = time(); 95 $delta = $this->getTimedeltaForCurrentPage(); 96 if($now - $ts > $delta) { 97 return true; 98 } 99 return false; 100 } 101 102 103} 104 105