1*f576111dSAndreas Gohr<?php 2*f576111dSAndreas Gohr/** 3*f576111dSAndreas Gohr * DokuWiki Plugin publish (Helper Component) 4*f576111dSAndreas Gohr * 5*f576111dSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*f576111dSAndreas Gohr * @author Jarrod Lowe <dokuwiki@rrod.net> 7*f576111dSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 8*f576111dSAndreas Gohr */ 9*f576111dSAndreas Gohr 10*f576111dSAndreas Gohr// must be run within Dokuwiki 11*f576111dSAndreas Gohrif (!defined('DOKU_INC')) die(); 12*f576111dSAndreas Gohr 13*f576111dSAndreas Gohrclass helper_plugin_publish extends DokuWiki_Plugin { 14*f576111dSAndreas Gohr 15*f576111dSAndreas Gohr // FIXME find out what this is supposed to do and how it can be done better 16*f576111dSAndreas Gohr function in_namespace($valid, $check) { 17*f576111dSAndreas Gohr // PHP apparantly does not have closures - 18*f576111dSAndreas Gohr // so we will parse $valid ourselves. Wasteful. 19*f576111dSAndreas Gohr $valid = preg_split('/\s+/', $valid); 20*f576111dSAndreas Gohr //if(count($valid) == 0) { return true; }//whole wiki matches 21*f576111dSAndreas Gohr if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches 22*f576111dSAndreas Gohr $check = trim($check, ':'); 23*f576111dSAndreas Gohr $check = explode(':', $check); 24*f576111dSAndreas Gohr 25*f576111dSAndreas Gohr // Check against all possible namespaces 26*f576111dSAndreas Gohr foreach($valid as $v) { 27*f576111dSAndreas Gohr $v = explode(':', $v); 28*f576111dSAndreas Gohr $n = 0; 29*f576111dSAndreas Gohr $c = count($v); 30*f576111dSAndreas Gohr $matching = 1; 31*f576111dSAndreas Gohr 32*f576111dSAndreas Gohr // Check each element, untill all elements of $v satisfied 33*f576111dSAndreas Gohr while($n < $c) { 34*f576111dSAndreas Gohr if($v[$n] != $check[$n]) { 35*f576111dSAndreas Gohr // not a match 36*f576111dSAndreas Gohr $matching = 0; 37*f576111dSAndreas Gohr break; 38*f576111dSAndreas Gohr } 39*f576111dSAndreas Gohr $n += 1; 40*f576111dSAndreas Gohr } 41*f576111dSAndreas Gohr if($matching == 1) { return true; } // a match 42*f576111dSAndreas Gohr } 43*f576111dSAndreas Gohr return false; 44*f576111dSAndreas Gohr } 45*f576111dSAndreas Gohr 46*f576111dSAndreas Gohr // FIXME find out what this is supposed to do and how it can be done better 47*f576111dSAndreas Gohr function in_sub_namespace($valid, $check) { 48*f576111dSAndreas Gohr // is check a dir which contains any valid? 49*f576111dSAndreas Gohr // PHP apparantly does not have closures - 50*f576111dSAndreas Gohr // so we will parse $valid ourselves. Wasteful. 51*f576111dSAndreas Gohr $valid = preg_split('/\s+/', $valid); 52*f576111dSAndreas Gohr //if(count($valid) == 0) { return true; }//whole wiki matches 53*f576111dSAndreas Gohr if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches 54*f576111dSAndreas Gohr $check = trim($check, ':'); 55*f576111dSAndreas Gohr $check = explode(':', $check); 56*f576111dSAndreas Gohr 57*f576111dSAndreas Gohr // Check against all possible namespaces 58*f576111dSAndreas Gohr foreach($valid as $v) { 59*f576111dSAndreas Gohr $v = explode(':', $v); 60*f576111dSAndreas Gohr $n = 0; 61*f576111dSAndreas Gohr $c = count($check); //this is what is different from above! 62*f576111dSAndreas Gohr $matching = 1; 63*f576111dSAndreas Gohr 64*f576111dSAndreas Gohr // Check each element, untill all elements of $v satisfied 65*f576111dSAndreas Gohr while($n < $c) { 66*f576111dSAndreas Gohr if($v[$n] != $check[$n]) { 67*f576111dSAndreas Gohr // not a match 68*f576111dSAndreas Gohr $matching = 0; 69*f576111dSAndreas Gohr break; 70*f576111dSAndreas Gohr } 71*f576111dSAndreas Gohr $n += 1; 72*f576111dSAndreas Gohr } 73*f576111dSAndreas Gohr if($matching == 1) { return true; } // a match 74*f576111dSAndreas Gohr } 75*f576111dSAndreas Gohr return false; 76*f576111dSAndreas Gohr } 77*f576111dSAndreas Gohr 78*f576111dSAndreas Gohr} 79