Changeset 7328
- Timestamp:
- 03/16/08 09:50:35 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
r7327 r7328 85 85 } 86 86 87 function find_base_dir($base = '.',$echo = false){ 87 function find_base_dir($base = '.',$echo = false) { 88 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output. 88 89 $abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths.. 89 90 if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter … … 92 93 } 93 94 95 //Set up the base directory (Which unless specified, is the current one) 94 96 if( empty( $base ) || '.' == $base ) $base = $this->cwd(); 95 if( empty( $base ) ) $base = '/'; 96 if( '/' != substr($base, -1) ) $base .= '/'; 97 98 if($echo) printf( __('Changing to %s') . '<br/>', $base ); 99 if( false === $this->chdir($base) ) 100 return false; 101 102 if( $this->exists($base . 'wp-settings.php') ){ 103 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' ); 104 $this->wp_base = $base; 105 return $this->wp_base; 106 } 107 108 if( strpos($abspath, $base) > 0) 109 $arrPath = split('/',substr($abspath,strpos($abspath, $base))); 110 else 111 $arrPath = split('/',$abspath); 112 113 for($i = 0; $i <= count($arrPath); $i++) 114 if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] ); 115 116 foreach($arrPath as $key=>$folder){ 117 if( $this->is_dir($base . $folder) ){ 118 if($echo) echo sprintf( __('Found %s'), $folder ) . ' ' . sprintf( __('Changing to %s') . '<br/>', $base . $folder . '/' ); 119 return $this->find_base_dir($base . $folder . '/',$echo); 97 $base = trailingslashit($base); 98 99 //Can we see the Current directory as part of the ABSPATH? 100 $location = strpos($abspath, $base); 101 if( false !== $location ){ 102 $newbase = path_join($base, substr($abspath, $location + strlen($base))); 103 104 if($echo) printf( __('Changing to %s') . '<br/>', $newbase ); 105 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. 106 $base = $newbase; 107 //Check to see if it exists in that folder. 108 if( $wp_filesystem->exists($base . 'wp-settings.php') ){ 109 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' ); 110 $this->wp_base = $base; 111 return $this->wp_base; 112 } 120 113 } 121 114 } 122 123 if( $base == '/' ) 124 return false; 125 //If we get this far, somethings gone wrong, change to / and restart the process. 126 return $this->find_base_dir('/',$echo); 127 } 128 function get_base_dir($base = '.', $echo=false){ 115 116 //Ok, Couldnt do a magic location from that particular folder level 117 118 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture. 119 $files = $this->dirlist($base); 120 121 $arrPath = explode('/', $abspath); 122 foreach($arrPath as $key){ 123 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, 124 // If its found, change into it and follow through looking for it. 125 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. 126 // If it reaches the end, and still cant find it, it'll return false for the entire function. 127 if( isset($files[ $key ]) ){ 128 //Lets try that folder: 129 $folder = path_join($base, $key); 130 if($echo) printf( __('Changing to %s') . '<br/>', $folder ); 131 $ret = $this->find_base_dir( $folder, $echo); 132 if( $ret ) 133 return $ret; 134 } 135 } 136 return false; 137 } 138 139 function get_base_dir($base = '.', $echo = false){ 140 if( defined('FTP_BASE') ) 141 $this->wp_base = FTP_BASE; 129 142 if( empty($this->wp_base) ) 130 143 $this->wp_base = $this->find_base_dir($base,$echo); trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r7327 r7328 88 88 89 89 function find_base_dir($base = '.',$echo = false) { 90 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output. 90 91 $abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths.. 91 92 if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter … … 94 95 } 95 96 97 //Set up the base directory (Which unless specified, is the current one) 96 98 if( empty( $base ) || '.' == $base ) $base = $this->cwd(); 97 if( empty( $base ) ) $base = '/'; 98 if( '/' != substr($base, -1) ) $base .= '/'; 99 100 if($echo) printf( __('Changing to %s') . '<br/>', $base ); 101 if( false === $this->chdir($base) ) 102 return false; 103 104 if( $this->exists($base . 'wp-settings.php') ){ 105 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' ); 106 $this->wp_base = $base; 107 return $this->wp_base; 108 } 109 110 if( strpos($abspath, $base) > 0) 111 $arrPath = split('/',substr($abspath,strpos($abspath, $base))); 112 else 113 $arrPath = split('/',$abspath); 114 115 for($i = 0; $i <= count($arrPath); $i++) 116 if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] ); 117 118 foreach($arrPath as $key=>$folder){ 119 if( $this->is_dir($base . $folder) ){ 120 if($echo) echo sprintf( __('Found %s'), $folder ) . ' ' . sprintf( __('Changing to %s') . '<br/>', $base . $folder . '/' ); 121 return $this->find_base_dir($base . $folder . '/',$echo); 99 $base = trailingslashit($base); 100 101 //Can we see the Current directory as part of the ABSPATH? 102 $location = strpos($abspath, $base); 103 if( false !== $location ){ 104 $newbase = path_join($base, substr($abspath, $location + strlen($base))); 105 106 if($echo) printf( __('Changing to %s') . '<br/>', $newbase ); 107 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. 108 $base = $newbase; 109 //Check to see if it exists in that folder. 110 if( $wp_filesystem->exists($base . 'wp-settings.php') ){ 111 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' ); 112 $this->wp_base = $base; 113 return $this->wp_base; 114 } 122 115 } 123 116 } 124 125 if( $base == '/' ) 126 return false; 127 //If we get this far, somethings gone wrong, change to / and restart the process. 128 return $this->find_base_dir('/',$echo); 117 118 //Ok, Couldnt do a magic location from that particular folder level 119 120 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture. 121 $files = $this->dirlist($base); 122 123 $arrPath = explode('/', $abspath); 124 foreach($arrPath as $key){ 125 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, 126 // If its found, change into it and follow through looking for it. 127 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. 128 // If it reaches the end, and still cant find it, it'll return false for the entire function. 129 if( isset($files[ $key ]) ){ 130 //Lets try that folder: 131 $folder = path_join($base, $key); 132 if($echo) printf( __('Changing to %s') . '<br/>', $folder ); 133 $ret = $this->find_base_dir( $folder, $echo); 134 if( $ret ) 135 return $ret; 136 } 137 } 138 return false; 129 139 } 130 140 131 141 function get_base_dir($base = '.', $echo = false){ 142 if( defined('FTP_BASE') ) 143 $this->wp_base = FTP_BASE; 132 144 if( empty($this->wp_base) ) 133 145 $this->wp_base = $this->find_base_dir($base, $echo);
