1<?php 2 3// must be run within Dokuwiki 4if (!defined('DOKU_INC')) die(); 5class helper_plugin_approve extends DokuWiki_Plugin { 6 7 /** 8 * Check if we should use approve in page 9 * 10 * @param string $id 11 * 12 * @return bool 13 */ 14 function use_approve_here($id) { 15 $apr_namespaces = $this->getConf('apr_namespaces'); 16 $no_apr_namespaces = $this->getConf('no_apr_namespaces'); 17 18 if ($this->in_namespace($no_apr_namespaces, $id)) { 19 return false; 20 //use apr_namespaces 21 } elseif (trim($apr_namespaces) != '') { 22 if ($this->in_namespace($apr_namespaces, $id)) { 23 return true; 24 } 25 return false; 26 } 27 28 return true; 29 } 30 /** 31 * checks if an id is within one of the namespaces in $namespace_list 32 * 33 * @param string $namespace_list 34 * @param string $id 35 * 36 * @return bool 37 */ 38 function in_namespace($namespace_list, $id) { 39 // PHP apparantly does not have closures - 40 // so we will parse $valid ourselves. Wasteful. 41 $namespace_list = preg_split('/\s+/', $namespace_list); 42 43 //if(count($valid) == 0) { return true; }//whole wiki matches 44 if(count($namespace_list) == 1 && $namespace_list[0] == "") { return false; }//whole wiki matches 45 46 $id = trim($id, ':'); 47 $id = explode(':', $id); 48 49 // Check against all possible namespaces 50 foreach($namespace_list as $namespace) { 51 $namespace = explode(':', $namespace); 52 $current_ns_depth = 0; 53 $total_ns_depth = count($namespace); 54 $matching = true; 55 56 // Check each element, untill all elements of $v satisfied 57 while($current_ns_depth < $total_ns_depth) { 58 if($namespace[$current_ns_depth] != $id[$current_ns_depth]) { 59 // not a match 60 $matching = false; 61 break; 62 } 63 $current_ns_depth += 1; 64 } 65 if($matching) { return true; } // a match 66 } 67 return false; 68 } 69 70 function page_sum($ID, $REV) { 71 $m = p_get_metadata($ID); 72 $changelog = new PageChangeLog($ID); 73 74 //sprawdź status aktualnej strony 75 if ($REV != 0) { 76 $ch = $changelog->getRevisionInfo($REV); 77 $sum = $ch['sum']; 78 } else { 79 $sum = $m['last_change']['sum']; 80 } 81 return $sum; 82 } 83} 84