From c8e3d31e9b937809d9cdb09bc2dca741ad4a664f Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Wed, 26 Jul 2017 15:36:31 +0200 Subject: [PATCH] reintroduce getScriptRoot() because dirname(__FILE__) does not work when using libifm.php --- build/libifm.php | 16 ++++++++++------ ifm.php | 16 ++++++++++------ src/main.php | 16 ++++++++++------ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/build/libifm.php b/build/libifm.php index 8f911f6..b0521ba 100644 --- a/build/libifm.php +++ b/build/libifm.php @@ -2198,7 +2198,7 @@ function IFM( params ) { if( $handle = opendir( "." ) ) { while( false !== ( $result = readdir( $handle ) ) ) { - if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && dirname( __FILE__ ) == getcwd() ) { } + if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && $this->getScriptRoot() == getcwd() ) { } elseif( ( $result == ".htaccess" || $result==".htpasswd" ) && $this->config['showhtdocs'] != 1 ) {} elseif( $result == "." ) {} elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {} @@ -2262,7 +2262,7 @@ function IFM( params ) { private function getConfig() { $ret = $this->config; $ret['inline'] = ( $this->mode == "inline" ) ? true : false; - $ret['isDocroot'] = ( $this->getRootDir() == dirname( __FILE__ ) ) ? "true" : "false"; + $ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? "true" : "false"; echo json_encode( $ret ); } @@ -2598,7 +2598,7 @@ function IFM( params ) { try { IFMArchive::createZip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) ); if( $d['filename'] == "." ) { - if( getcwd() == dirname( __FILE__ ) ) + if( getcwd() == $this->getScriptRoot() ) $d['filename'] = "root"; else $d['filename'] = basename( getcwd() ); @@ -2774,11 +2774,15 @@ function IFM( params ) { private function getRootDir() { if( $this->config['root_dir'] == "" ) - return realpath( dirname( __FILE__ ) ); + return realpath( $this->getScriptRoot() ); elseif( $this->isAbsolutePath( $this->config['root_dir'] ) ) return realpath( $this->config['root_dir'] ); else - return realpath( $this->pathCombine( dirname( __FILE__ ), $this->config['root_dir'] ) ); + return realpath( $this->pathCombine( $this->getScriptRoot(), $this->config['root_dir'] ) ); + } + + private function getScriptRoot() { + return ( defined( 'IFM_FILENAME' ) ? dirname( realpath( IFM_FILENAME ) ) : dirname( __FILE__ ) ); } private function getValidDir( $dir ) { @@ -2825,7 +2829,7 @@ function IFM( params ) { } private function chDirIfNecessary($d) { - if( substr( getcwd(), strlen( dirname( __FILE__ ) ) ) != $this->getValidDir($d) ) { + if( substr( getcwd(), strlen( $this->getScriptRoot() ) ) != $this->getValidDir($d) ) { chdir( $d ); } } diff --git a/ifm.php b/ifm.php index fce8074..38e563a 100644 --- a/ifm.php +++ b/ifm.php @@ -2198,7 +2198,7 @@ function IFM( params ) { if( $handle = opendir( "." ) ) { while( false !== ( $result = readdir( $handle ) ) ) { - if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && dirname( __FILE__ ) == getcwd() ) { } + if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && $this->getScriptRoot() == getcwd() ) { } elseif( ( $result == ".htaccess" || $result==".htpasswd" ) && $this->config['showhtdocs'] != 1 ) {} elseif( $result == "." ) {} elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {} @@ -2262,7 +2262,7 @@ function IFM( params ) { private function getConfig() { $ret = $this->config; $ret['inline'] = ( $this->mode == "inline" ) ? true : false; - $ret['isDocroot'] = ( $this->getRootDir() == dirname( __FILE__ ) ) ? "true" : "false"; + $ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? "true" : "false"; echo json_encode( $ret ); } @@ -2598,7 +2598,7 @@ function IFM( params ) { try { IFMArchive::createZip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) ); if( $d['filename'] == "." ) { - if( getcwd() == dirname( __FILE__ ) ) + if( getcwd() == $this->getScriptRoot() ) $d['filename'] = "root"; else $d['filename'] = basename( getcwd() ); @@ -2774,11 +2774,15 @@ function IFM( params ) { private function getRootDir() { if( $this->config['root_dir'] == "" ) - return realpath( dirname( __FILE__ ) ); + return realpath( $this->getScriptRoot() ); elseif( $this->isAbsolutePath( $this->config['root_dir'] ) ) return realpath( $this->config['root_dir'] ); else - return realpath( $this->pathCombine( dirname( __FILE__ ), $this->config['root_dir'] ) ); + return realpath( $this->pathCombine( $this->getScriptRoot(), $this->config['root_dir'] ) ); + } + + private function getScriptRoot() { + return ( defined( 'IFM_FILENAME' ) ? dirname( realpath( IFM_FILENAME ) ) : dirname( __FILE__ ) ); } private function getValidDir( $dir ) { @@ -2825,7 +2829,7 @@ function IFM( params ) { } private function chDirIfNecessary($d) { - if( substr( getcwd(), strlen( dirname( __FILE__ ) ) ) != $this->getValidDir($d) ) { + if( substr( getcwd(), strlen( $this->getScriptRoot() ) ) != $this->getValidDir($d) ) { chdir( $d ); } } diff --git a/src/main.php b/src/main.php index b1e0a59..bcff9cd 100644 --- a/src/main.php +++ b/src/main.php @@ -250,7 +250,7 @@ f00bar; if( $handle = opendir( "." ) ) { while( false !== ( $result = readdir( $handle ) ) ) { - if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && dirname( __FILE__ ) == getcwd() ) { } + if( $result == basename( $_SERVER['SCRIPT_NAME'] ) && $this->getScriptRoot() == getcwd() ) { } elseif( ( $result == ".htaccess" || $result==".htpasswd" ) && $this->config['showhtdocs'] != 1 ) {} elseif( $result == "." ) {} elseif( $result != ".." && substr( $result, 0, 1 ) == "." && $this->config['showhiddenfiles'] != 1 ) {} @@ -314,7 +314,7 @@ f00bar; private function getConfig() { $ret = $this->config; $ret['inline'] = ( $this->mode == "inline" ) ? true : false; - $ret['isDocroot'] = ( $this->getRootDir() == dirname( __FILE__ ) ) ? "true" : "false"; + $ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? "true" : "false"; echo json_encode( $ret ); } @@ -650,7 +650,7 @@ f00bar; try { IFMArchive::createZip( realpath( $d['filename'] ), $dfile, ( $d['filename'] == "." ) ); if( $d['filename'] == "." ) { - if( getcwd() == dirname( __FILE__ ) ) + if( getcwd() == $this->getScriptRoot() ) $d['filename'] = "root"; else $d['filename'] = basename( getcwd() ); @@ -826,11 +826,15 @@ f00bar; private function getRootDir() { if( $this->config['root_dir'] == "" ) - return realpath( dirname( __FILE__ ) ); + return realpath( $this->getScriptRoot() ); elseif( $this->isAbsolutePath( $this->config['root_dir'] ) ) return realpath( $this->config['root_dir'] ); else - return realpath( $this->pathCombine( dirname( __FILE__ ), $this->config['root_dir'] ) ); + return realpath( $this->pathCombine( $this->getScriptRoot(), $this->config['root_dir'] ) ); + } + + private function getScriptRoot() { + return ( defined( 'IFM_FILENAME' ) ? dirname( realpath( IFM_FILENAME ) ) : dirname( __FILE__ ) ); } private function getValidDir( $dir ) { @@ -877,7 +881,7 @@ f00bar; } private function chDirIfNecessary($d) { - if( substr( getcwd(), strlen( dirname( __FILE__ ) ) ) != $this->getValidDir($d) ) { + if( substr( getcwd(), strlen( $this->getScriptRoot() ) ) != $this->getValidDir($d) ) { chdir( $d ); } }