summaryrefslogtreecommitdiff
path: root/inc/init.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2007-09-30 20:42:50 +0200
committerAndreas Gohr <andi@splitbrain.org>2007-09-30 20:42:50 +0200
commit009768124df70258806ec3120189432d1b2bb912 (patch)
treecc66e19004645686d0bf84e71fa54f490e0ff4a7 /inc/init.php
parent0b30864498cfa9af2398991188109da991e4613f (diff)
downloadrpg-009768124df70258806ec3120189432d1b2bb912.tar.gz
rpg-009768124df70258806ec3120189432d1b2bb912.tar.bz2
don't use realpath() anymore (FS#1261 and others)
The use of realpath() to clean up relative file names caused some trouble in certain setups relying on symlinks or having restricitve file structure setups. This patch replaces all realpath() calls with a PHP only replacement which should solve those problems. darcs-hash:20070930184250-7ad00-512ff04c95f57fc9eaf104f80372237a3c94286f.gz
Diffstat (limited to 'inc/init.php')
-rw-r--r--inc/init.php46
1 files changed, 43 insertions, 3 deletions
diff --git a/inc/init.php b/inc/init.php
index 416b117eb..f96997f21 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -11,7 +11,7 @@
define('DOKU_START_TIME', delta_time());
// define the include path
- if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
+ if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
// define config path (packagers may want to change this to /etc/dokuwiki/)
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
@@ -201,9 +201,9 @@ function init_files(){
*/
function init_path($path){
// check existance
- $p = realpath($path);
+ $p = fullpath($path);
if(!@file_exists($p)){
- $p = realpath(DOKU_INC.$path);
+ $p = fullpath(DOKU_INC.$path);
if(!@file_exists($p)){
return '';
}
@@ -400,4 +400,44 @@ EOT;
}
+/**
+ * A realpath() replacement
+ *
+ * This function behaves similar to PHP's realpath() but does not resolve
+ * symlinks or accesses upper directories
+ *
+ * @author <richpageau at yahoo dot co dot uk>
+ * @link http://de3.php.net/manual/en/function.realpath.php#75992
+ */
+function fullpath($path){
+
+ // check if path begins with "/" ie. is absolute
+ // if it isnt concat with script path
+ if (strpos($path,"/") !== 0) {
+ $base=dirname($_SERVER['SCRIPT_FILENAME']);
+ $path=$base."/".$path;
+ }
+
+ // canonicalize
+ $path=explode('/', $path);
+ $newpath=array();
+ for ($i=0; $i<sizeof($path); $i++) {
+ if ($path[$i]==='' || $path[$i]==='.') continue;
+ if ($path[$i]==='..') {
+ array_pop($newpath);
+ continue;
+ }
+ array_push($newpath, $path[$i]);
+ }
+ $finalpath="/".implode('/', $newpath);
+
+ // check then return valid path or filename
+ if (file_exists($finalpath)) {
+ return ($finalpath);
+ }
+ else return false;
+}
+
+
+
//Setup VIM: ex: et ts=2 enc=utf-8 :