- Timestamp:
- 05/29/2008 05:29:32 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php
r7999 r8009 6 6 var $options = array(); 7 7 8 var $wp_base = '';9 8 var $permission = null; 10 9 11 10 var $filetypes = array( 12 'php' =>FTP_ASCII,13 'css' =>FTP_ASCII,14 'txt' =>FTP_ASCII,15 'js' =>FTP_ASCII,16 'html'=> FTP_ASCII,17 'htm' =>FTP_ASCII,18 'xml' =>FTP_ASCII,19 20 'jpg' =>FTP_BINARY,21 'png' =>FTP_BINARY,22 'gif' =>FTP_BINARY,23 'bmp' =>FTP_BINARY11 'php' => FTP_ASCII, 12 'css' => FTP_ASCII, 13 'txt' => FTP_ASCII, 14 'js' => FTP_ASCII, 15 'html'=> FTP_ASCII, 16 'htm' => FTP_ASCII, 17 'xml' => FTP_ASCII, 18 19 'jpg' => FTP_BINARY, 20 'png' => FTP_BINARY, 21 'gif' => FTP_BINARY, 22 'bmp' => FTP_BINARY 24 23 ); 25 24 26 25 function WP_Filesystem_ftpsockets($opt='') { 26 $this->method = 'ftpsockets'; 27 27 $this->errors = new WP_Error(); 28 28 … … 85 85 function setDefaultPermissions($perm) { 86 86 $this->permission = $perm; 87 }88 89 function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {90 if (!$path)91 $path = ABSPATH;92 93 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.94 $path = str_replace('\\','/',$path); //windows: Straighten up the paths..95 if( strpos($path, ':') ){ //Windows, Strip out the driveletter96 if( preg_match("|.{1}\:(.+)|i", $path, $mat) )97 $path = $mat[1];98 }99 100 //Set up the base directory (Which unless specified, is the current one)101 if( empty( $base ) || '.' == $base ) $base = $this->cwd();102 $base = trailingslashit($base);103 104 //Can we see the Current directory as part of the ABSPATH?105 $location = strpos($path, $base);106 if( false !== $location ) {107 $newbase = path_join($base, substr($path, $location + strlen($base)));108 109 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.110 if($echo) printf( __('Changing to %s') . '<br/>', $newbase );111 //Check to see if it exists in that folder.112 if( $this->exists($newbase . 'wp-settings.php') ){113 if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );114 return $newbase;115 }116 }117 }118 119 //Ok, Couldnt do a magic location from that particular folder level120 121 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.122 $files = $this->dirlist($base);123 124 $arrPath = explode('/', $path);125 foreach($arrPath as $key){126 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,127 // If its found, change into it and follow through looking for it.128 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.129 // If it reaches the end, and still cant find it, it'll return false for the entire function.130 if( isset($files[ $key ]) ){131 //Lets try that folder:132 $folder = path_join($base, $key);133 if($echo) printf( __('Changing to %s') . '<br/>', $folder );134 $ret = $this->find_base_dir($path, $folder, $echo, $loop);135 if( $ret )136 return $ret;137 }138 }139 //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.140 if(isset( $files[ 'wp-settings.php' ]) ){141 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );142 return $base;143 }144 if( $loop )145 return false;//Prevent tihs function looping again.146 //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.147 return $this->find_base_dir($path, '/', $echo, true);148 }149 150 function get_base_dir($path = false, $base = '.', $echo = false){151 if( defined('FTP_BASE') )152 $this->wp_base = FTP_BASE;153 if( empty($this->wp_base) )154 $this->wp_base = $this->find_base_dir($path, $base, $echo);155 return $this->wp_base;156 87 } 157 88 … … 332 263 return false; 333 264 334 return $this->put_contents($destination, $content);335 } 336 337 function move($source, $destination,$overwrite=false){338 return $this->ftp->rename($source, $destination);339 } 340 341 function delete($file, $recursive=false) {265 return $this->put_contents($destination, $content); 266 } 267 268 function move($source, $destination, $overwrite = false ) { 269 return $this->ftp->rename($source, $destination); 270 } 271 272 function delete($file, $recursive = false ) { 342 273 if ( $this->is_file($file) ) 343 274 return $this->ftp->delete($file); … … 348 279 } 349 280 350 function exists($file) {281 function exists($file) { 351 282 return $this->ftp->is_exists($file); 352 283 } 353 284 354 function is_file($file) {285 function is_file($file) { 355 286 return $this->is_dir($file) ? false : true; 356 287 } 357 288 358 function is_dir($path) {289 function is_dir($path) { 359 290 $cwd = $this->cwd(); 360 291 if ( $this->chdir($path) ) { … … 365 296 } 366 297 367 function is_readable($file) {298 function is_readable($file) { 368 299 //Get dir list, Check if the file is writable by the current user?? 369 300 return true; 370 301 } 371 302 372 function is_writable($file) {303 function is_writable($file) { 373 304 //Get dir list, Check if the file is writable by the current user?? 374 305 return true; 375 306 } 376 307 377 function atime($file) {378 return false; 379 } 380 381 function mtime($file) {308 function atime($file) { 309 return false; 310 } 311 312 function mtime($file) { 382 313 return $this->ftp->mdtm($file); 383 314 } 384 315 385 function size($file) {316 function size($file) { 386 317 return $this->ftp->filesize($file); 387 318 } 388 319 389 function touch($file, $time=0,$atime=0){390 return false; 391 } 392 393 function mkdir($path, $chmod=false,$chown=false,$chgrp=false){320 function touch($file, $time = 0, $atime = 0 ){ 321 return false; 322 } 323 324 function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { 394 325 if( ! $this->ftp->mkdir($path) ) 395 326 return false; … … 403 334 } 404 335 405 function rmdir($path, $recursive=false){336 function rmdir($path, $recursive = false ) { 406 337 if( ! $recursive ) 407 338 return $this->ftp->rmdir($path); … … 410 341 } 411 342 412 function dirlist($path ='.',$incdot=false,$recursive=false){413 if( $this->is_file($path) ) {343 function dirlist($path = '.', $incdot = false, $recursive = false ) { 344 if( $this->is_file($path) ) { 414 345 $limitFile = basename($path); 415 346 $path = dirname($path) . '/'; … … 434 365 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 435 366 if ($recursive) 436 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);367 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 437 368 } 438 369 } else { //No dots 439 370 if ($recursive) 440 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);371 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 441 372 } 442 373 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)