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 public function matchPagePattern($pattern, $page, $pns = null) 21 { 22 if (trim($pattern, ':') == '**') { 23 return true; 24 } // match all 25 26 // regex patterns 27 if ($pattern[0] == '/') { 28 return (bool) preg_match($pattern, ":$page"); 29 } 30 31 if (is_null($pns)) { 32 $pns = ':' . getNS($page) . ':'; 33 } 34 35 $ans = ':' . cleanID($pattern) . ':'; 36 if (substr($pattern, -2) == '**') { 37 // upper namespaces match 38 if (strpos($pns, $ans) === 0) { 39 return true; 40 } 41 } elseif (substr($pattern, -1) == '*') { 42 // namespaces match exact 43 if ($ans == $pns) { 44 return true; 45 } 46 } else { 47 // exact match 48 if (cleanID($pattern) == $page) { 49 return true; 50 } 51 } 52 53 return false; 54 } 55} 56