From 6de3759a1b7a74492845c76e1f0bd1078e2220c7 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 14 Aug 2005 12:18:34 +0200 Subject: URL rewriting for media files This patch adds nicer URLs for media files (for fetch.php and detail.php) !IMPORTANT! Users of rewrite mode 1 need to adjust their .htaccess See .htaccess.dist for an example darcs-hash:20050814101834-7ad00-37ef1dea00affc9d808d9ee1289fa7454199cd24.gz --- inc/common.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index b0d7c4c10..891601357 100644 --- a/inc/common.php +++ b/inc/common.php @@ -238,7 +238,11 @@ function idfilter($id,$ue=true){ */ function wl($id='',$more='',$abs=false){ global $conf; - $more = str_replace(',','&',$more); + if(is_array($more)){ + $more = buildURLparams($more); + }else{ + $more = str_replace(',','&',$more); + } $id = idfilter($id); if($abs){ @@ -261,6 +265,68 @@ function wl($id='',$more='',$abs=false){ return $xlink; } +/** + * Build a link to a media file + * + * Will return a link to the detail page if $direct is false + */ +function ml($id='',$more='',$direct=true){ + global $conf; + if(is_array($more)){ + $more = buildURLparams($more); + }else{ + $more = str_replace(',','&',$more); + } + + $xlink = DOKU_BASE; + + // external URLs are always direct without rewriting + if(preg_match('#^(https?|ftp)://#i',$id)){ + $xlink .= 'lib/exe/fetch.php'; + if($more){ + $xlink .= '?'.$more; + $xlink .= '&media='.$id; + }else{ + $xlink .= '?media='.$id; + } + return $xlink; + } + + $id = idfilter($id); + + // decide on scriptname + if($direct){ + if($conf['userewrite'] == 1){ + $script = '_media'; + }else{ + $script = 'lib/exe/fetch.php'; + } + }else{ + if($conf['userewrite'] == 1){ + $script = '_detail'; + }else{ + $script = 'lib/exe/detail.php'; + } + } + + // build URL based on rewrite mode + if($conf['userewrite']){ + $xlink .= $script.'/'.$id; + if($more) $xlink .= '?'.$more; + }else{ + if($more){ + $xlink .= '?'.$more; + $xlink .= '&media='.$id; + }else{ + $xlink .= '?media='.$id; + } + } + + return $xlink; +} + + + /** * Just builds a link to a script * -- cgit v1.2.3