summaryrefslogtreecommitdiffstats
path: root/wp-admin/includes/class-wp-filesystem-ftpsockets.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-04-04 16:44:15 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-04-04 16:44:15 +0000
commit7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc (patch)
treec6fd23b598f3994eddb18cb1c0f2e8d95ff054fa /wp-admin/includes/class-wp-filesystem-ftpsockets.php
parentf650f48c048bfbbb2ae702b6425d87e39358d748 (diff)
downloadwordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.tar.gz
wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.tar.xz
wordpress-mu-7740e89de3e1bc0cc636120e3ca8ab9e97e4d3cc.zip
Merged with WordPress 2.5, unstable, only for testing
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1218 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/includes/class-wp-filesystem-ftpsockets.php')
-rw-r--r--wp-admin/includes/class-wp-filesystem-ftpsockets.php90
1 files changed, 57 insertions, 33 deletions
diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php
index 15ab390..5365623 100644
--- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php
+++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php
@@ -86,49 +86,67 @@ class WP_Filesystem_ftpsockets{
$this->permission = $perm;
}
- function find_base_dir($base = '.',$echo = false) {
+ function find_base_dir($base = '.',$echo = false, $loop = false) {
+ //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];
}
+ //Set up the base directory (Which unless specified, is the current one)
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
- if( empty( $base ) ) $base = '/';
- if( '/' != substr($base, -1) ) $base .= '/';
-
- if($echo) echo __('Changing to ') . $base .'<br>';
- if( false === $this->chdir($base) )
- return false;
-
- if( $this->exists($base . 'wp-settings.php') ){
- if($echo) echo __('Found ') . $base . 'wp-settings.php<br>';
- $this->wp_base = $base;
- return $this->wp_base;
+ $base = trailingslashit($base);
+
+ //Can we see the Current directory as part of the ABSPATH?
+ $location = strpos($abspath, $base);
+ if( false !== $location ) {
+ $newbase = path_join($base, substr($abspath, $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 );
+ //Check to see if it exists in that folder.
+ if( $this->exists($newbase . 'wp-settings.php') ){
+ if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
+ return $newbase;
+ }
+ }
}
-
- if( strpos($abspath, $base) > 0)
- $arrPath = split('/',substr($abspath,strpos($abspath, $base)));
- else
- $arrPath = split('/',$abspath);
-
- for($i = 0; $i <= count($arrPath); $i++)
- if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] );
-
- foreach($arrPath as $key=>$folder){
- if( $this->is_dir($base . $folder) ){
- if($echo) echo __('Found ') . $folder . ' ' . __('Changing to') . ' ' . $base . $folder . '/<br>';
- return $this->find_base_dir($base . $folder . '/',$echo);
+
+ //Ok, Couldnt do a magic location from that particular folder level
+
+ //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);
+ 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.
+ // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
+ // If it reaches the end, and still cant find it, it'll return false for the entire function.
+ if( isset($files[ $key ]) ){
+ //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);
+ if( $ret )
+ return $ret;
}
}
-
- if( $base == '/' )
- return false;
- //If we get this far, somethings gone wrong, change to / and restart the process.
- return $this->find_base_dir('/',$echo);
+ //Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
+ if(isset( $files[ 'wp-settings.php' ]) ){
+ if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
+ return $base;
+ }
+ 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);
}
function get_base_dir($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);
return $this->wp_base;
@@ -144,6 +162,8 @@ class WP_Filesystem_ftpsockets{
}
$this->ftp->SetType($type);
$temp = tmpfile();
+ if ( ! $temp )
+ return false;
if ( ! $this->ftp->fget($temp, $file) ) {
fclose($temp);
return ''; //Blank document, File does exist, Its just blank.
@@ -168,6 +188,8 @@ class WP_Filesystem_ftpsockets{
$this->ftp->SetType($type);
$temp = tmpfile();
+ if ( ! $temp )
+ return false;
fwrite($temp,$contents);
fseek($temp, 0); //Skip back to the start of the file being written to
$ret = $this->ftp->fput($file, $temp);
@@ -176,7 +198,10 @@ class WP_Filesystem_ftpsockets{
}
function cwd(){
- return $this->ftp->pwd();
+ $cwd = $this->ftp->pwd();
+ if( $cwd )
+ $cwd = trailingslashit($cwd);
+ return $cwd;
}
function chdir($file){
@@ -388,8 +413,7 @@ class WP_Filesystem_ftpsockets{
} else {
$limitFile = false;
}
- //if( ! $this->is_dir($path) )
- // return false;
+
$list = $this->ftp->dirlist($path);
if( ! $list )
return false;