1<?php 2 3/** 4 * DokuWiki Plugin structpublish (Helper Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Anna Dabrowska <dokuwiki@cosmocode.de> 8 */ 9 10class helper_plugin_structpublish_assignments extends DokuWiki_Plugin 11{ 12 13 /** 14 * @param $pattern 15 * @param $src 16 * @param $config 17 * @return array 18 */ 19 public function generateRules($pattern = null, $src = null, $config = null) 20 { 21 $rules = []; 22 // ns pattern 23 $pattern = 'testpage'; 24 $src = [ 25 'page' => [ 26 'status' => [ 27 'publish' => [ 28 'user' => ['@admin'] 29 ] 30 ] 31 ], 32 'test' => [ 33 'status' => [ 34 'publish' => [ 35 'user' => ['@admin'] 36 ] 37 ] 38 ], 39 'testpage' => [ 40 'status' => [ 41 'publish' => [ 42 'user' => ['@admin'] 43 ] 44 ] 45 ], 46 'testpage1' => [ 47 'status' => [ 48 'publish' => [ 49 'user' => ['@admin'] 50 ] 51 ] 52 ], 53 ]; 54 55 // Expected return pattern: 56 57 $rules = [ 58 59 ]; 60 61 return $rules; 62 } 63 /** 64 * Check if the given pattern matches the given page 65 * @author Andreas Gohr 66 * 67 * @param string $pattern the pattern to check against 68 * @param string $page the cleaned pageid to check 69 * @param string|null $pns optimization, the colon wrapped namespace of the page, set null for automatic 70 * @return bool 71 */ 72 public function matchPagePattern($pattern, $page, $pns = null) 73 { 74 if (trim($pattern, ':') == '**') return true; // match all 75 76 // regex patterns 77 if ($pattern[0] == '/') { 78 return (bool)preg_match($pattern, ":$page"); 79 } 80 81 if (is_null($pns)) { 82 $pns = ':' . getNS($page) . ':'; 83 } 84 85 $ans = ':' . cleanID($pattern) . ':'; 86 if (substr($pattern, -2) == '**') { 87 // upper namespaces match 88 if (strpos($pns, $ans) === 0) { 89 return true; 90 } 91 } elseif (substr($pattern, -1) == '*') { 92 // namespaces match exact 93 if ($ans == $pns) { 94 return true; 95 } 96 } else { 97 // exact match 98 if (cleanID($pattern) == $page) { 99 return true; 100 } 101 } 102 103 return false; 104 } 105} 106