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