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 * Check if the given pattern matches the given page 14 * @author Andreas Gohr 15 * 16 * @param string $pattern the pattern to check against 17 * @param string $page the cleaned pageid to check 18 * @param string|null $pns optimization, the colon wrapped namespace of the page, set null for automatic 19 * @return bool 20 */ 21 public function matchPagePattern($pattern, $page, $pns = null) 22 { 23 if (trim($pattern, ':') == '**') return true; // match all 24 25 // regex patterns 26 if ($pattern[0] == '/') { 27 return (bool)preg_match($pattern, ":$page"); 28 } 29 30 if (is_null($pns)) { 31 $pns = ':' . getNS($page) . ':'; 32 } 33 34 $ans = ':' . cleanID($pattern) . ':'; 35 if (substr($pattern, -2) == '**') { 36 // upper namespaces match 37 if (strpos($pns, $ans) === 0) { 38 return true; 39 } 40 } elseif (substr($pattern, -1) == '*') { 41 // namespaces match exact 42 if ($ans == $pns) { 43 return true; 44 } 45 } else { 46 // exact match 47 if (cleanID($pattern) == $page) { 48 return true; 49 } 50 } 51 52 return false; 53 } 54} 55