diff options
Diffstat (limited to 'inc/pageutils.php')
-rw-r--r-- | inc/pageutils.php | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/inc/pageutils.php b/inc/pageutils.php index 151fa5987..55cc081a1 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -19,9 +19,10 @@ * @author Andreas Gohr <andi@splitbrain.org> */ function getID($param='id',$clean=true){ + global $INPUT; global $conf; - $id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null; + $id = $INPUT->str($param); //construct page id from request URI if(empty($id) && $conf['userewrite'] == 2){ @@ -34,7 +35,7 @@ function getID($param='id',$clean=true){ if($param != 'id') { $relpath = 'lib/exe/'; } - $script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']); + $script = $conf['basedir'].$relpath.utf8_basename($_SERVER['SCRIPT_FILENAME']); }elseif($_SERVER['PATH_INFO']){ $request = $_SERVER['PATH_INFO']; @@ -198,7 +199,8 @@ function noNSorNS($id) { * Creates a XHTML valid linkid from a given headline title * * @param string $title The headline title - * @param array $check Existing IDs (title => number) + * @param array|bool $check Existing IDs (title => number) + * @return string the title * @author Andreas Gohr <andi@splitbrain.org> */ function sectionID($title,&$check) { @@ -213,9 +215,9 @@ function sectionID($title,&$check) { if(is_array($check)){ // make sure tiles are unique if (!array_key_exists ($title,$check)) { - $check[$title] = 0; + $check[$title] = 0; } else { - $title .= ++ $check[$title]; + $title .= ++ $check[$title]; } } @@ -347,27 +349,29 @@ function mediaFN($id, $rev=''){ if(empty($rev)){ $fn = $conf['mediadir'].'/'.utf8_encodeFN($id); }else{ - $ext = mimetype($id); - $name = substr($id,0, -1*strlen($ext[0])-1); + $ext = mimetype($id); + $name = substr($id,0, -1*strlen($ext[0])-1); $fn = $conf['mediaolddir'].'/'.utf8_encodeFN($name .'.'.( (int) $rev ).'.'.$ext[0]); } return $fn; } /** - * Returns the full filepath to a localized textfile if local + * Returns the full filepath to a localized file if local * version isn't found the english one is returned * + * @param string $id The id of the local file + * @param string $ext The file extension (usually txt) * @author Andreas Gohr <andi@splitbrain.org> */ -function localeFN($id){ +function localeFN($id,$ext='txt'){ global $conf; - $file = DOKU_CONF.'/lang/'.$conf['lang'].'/'.$id.'.txt'; + $file = DOKU_CONF.'/lang/'.$conf['lang'].'/'.$id.'.'.$ext; if(!@file_exists($file)){ - $file = DOKU_INC.'inc/lang/'.$conf['lang'].'/'.$id.'.txt'; + $file = DOKU_INC.'inc/lang/'.$conf['lang'].'/'.$id.'.'.$ext; if(!@file_exists($file)){ //fall back to english - $file = DOKU_INC.'inc/lang/en/'.$id.'.txt'; + $file = DOKU_INC.'inc/lang/en/'.$id.'.'.$ext; } } return $file; @@ -620,3 +624,27 @@ function utf8_decodeFN($file){ return urldecode($file); } +/** + * Find a page in the current namespace (determined from $ID) or any + * higher namespace + * + * Used for sidebars, but can be used other stuff as well + * + * @todo add event hook + * @param string $page the pagename you're looking for + * @return string|false the full page id of the found page, false if any + */ +function page_findnearest($page){ + global $ID; + + $ns = $ID; + do { + $ns = getNS($ns); + $pageid = ltrim("$ns:$page",':'); + if(page_exists($pageid)){ + return $pageid; + } + } while($ns); + + return false; +} |