Allow wp-content to exist outside of webroot. Props sambauers. see #6938

git-svn-id: https://develop.svn.wordpress.org/trunk@7999 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-05-27 17:55:24 +00:00
parent f213f87d59
commit 6cc11cbf1e
23 changed files with 140 additions and 112 deletions

View File

@@ -86,12 +86,15 @@ class WP_Filesystem_ftpsockets{
$this->permission = $perm;
}
function find_base_dir($base = '.',$echo = false, $loop = false) {
function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
if (!$path)
$path = ABSPATH;
//Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
$abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths..
if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter
if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) )
$abspath = $mat[1];
$path = str_replace('\\','/',$path); //windows: Straighten up the paths..
if( strpos($path, ':') ){ //Windows, Strip out the driveletter
if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
$path = $mat[1];
}
//Set up the base directory (Which unless specified, is the current one)
@@ -99,9 +102,9 @@ class WP_Filesystem_ftpsockets{
$base = trailingslashit($base);
//Can we see the Current directory as part of the ABSPATH?
$location = strpos($abspath, $base);
$location = strpos($path, $base);
if( false !== $location ) {
$newbase = path_join($base, substr($abspath, $location + strlen($base)));
$newbase = path_join($base, substr($path, $location + strlen($base)));
if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
@@ -118,7 +121,7 @@ class WP_Filesystem_ftpsockets{
//Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
$files = $this->dirlist($base);
$arrPath = explode('/', $abspath);
$arrPath = explode('/', $path);
foreach($arrPath as $key){
//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
// If its found, change into it and follow through looking for it.
@@ -128,7 +131,7 @@ class WP_Filesystem_ftpsockets{
//Lets try that folder:
$folder = path_join($base, $key);
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
$ret = $this->find_base_dir( $folder, $echo, $loop);
$ret = $this->find_base_dir($path, $folder, $echo, $loop);
if( $ret )
return $ret;
}
@@ -141,14 +144,14 @@ class WP_Filesystem_ftpsockets{
if( $loop )
return false;//Prevent tihs function looping again.
//As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
return $this->find_base_dir('/', $echo, true);
return $this->find_base_dir($path, '/', $echo, true);
}
function get_base_dir($base = '.', $echo = false){
function get_base_dir($path = false, $base = '.', $echo = false){
if( defined('FTP_BASE') )
$this->wp_base = FTP_BASE;
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($base, $echo);
$this->wp_base = $this->find_base_dir($path, $base, $echo);
return $this->wp_base;
}