Changeset 8009 for trunk/wp-admin/includes/class-wp-filesystem-ftpext.php
- 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-ftpext.php
r7999 r8009 1 1 <?php 2 class WP_Filesystem_FTPext {2 class WP_Filesystem_FTPext extends WP_Filesystem_Base{ 3 3 var $link; 4 4 var $timeout = 5; … … 6 6 var $options = array(); 7 7 8 var $wp_base = '';9 8 var $permission = null; 10 9 … … 25 24 26 25 function WP_Filesystem_FTPext($opt='') { 26 $this->method = 'ftpext'; 27 27 $this->errors = new WP_Error(); 28 28 … … 61 61 } 62 62 63 function connect() {64 if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {63 function connect() { 64 if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) 65 65 $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout); 66 } else {66 else 67 67 $this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout); 68 }69 68 70 69 if ( ! $this->link ) { … … 81 80 } 82 81 83 function setDefaultPermissions($perm) {82 function setDefaultPermissions($perm) { 84 83 $this->permission = $perm; 85 84 } 86 87 function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {88 if (!$path)89 $path = ABSPATH;90 91 //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.92 $path = str_replace('\\','/',$path); //windows: Straighten up the paths..93 if( strpos($path, ':') ){ //Windows, Strip out the driveletter94 if( preg_match("|.{1}\:(.+)|i", $path, $mat) )95 $path = $mat[1];96 }97 85 98 //Set up the base directory (Which unless specified, is the current one) 99 if( empty( $base ) || '.' == $base ) $base = $this->cwd(); 100 $base = trailingslashit($base); 101 102 //Can we see the Current directory as part of the ABSPATH? 103 $location = strpos($path, $base); 104 if( false !== $location ) { 105 $newbase = path_join($base, substr($path, $location + strlen($base))); 106 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 if($echo) printf( __('Changing to %s') . '<br/>', $newbase ); 109 //Check to see if it exists in that folder. 110 if( $this->exists($newbase . 'wp-settings.php') ){ 111 if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' ); 112 return $newbase; 113 } 114 } 115 } 116 117 //Ok, Couldnt do a magic location from that particular folder level 118 119 //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture. 120 $files = $this->dirlist($base); 121 122 $arrPath = explode('/', $path); 123 foreach($arrPath as $key){ 124 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, 125 // If its found, change into it and follow through looking for it. 126 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. 127 // If it reaches the end, and still cant find it, it'll return false for the entire function. 128 if( isset($files[ $key ]) ){ 129 //Lets try that folder: 130 $folder = path_join($base, $key); 131 if($echo) printf( __('Changing to %s') . '<br/>', $folder ); 132 $ret = $this->find_base_dir( $path, $folder, $echo, $loop); 133 if( $ret ) 134 return $ret; 135 } 136 } 137 //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. 138 if(isset( $files[ 'wp-settings.php' ]) ){ 139 if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' ); 140 return $base; 141 } 142 if( $loop ) 143 return false;//Prevent tihs function looping again. 144 //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. 145 return $this->find_base_dir($path, '/', $echo, true); 146 } 147 148 function get_base_dir($path = false, $base = '.', $echo = false){ 149 if( defined('FTP_BASE') ) 150 $this->wp_base = FTP_BASE; 151 if( empty($this->wp_base) ) 152 $this->wp_base = $this->find_base_dir($path, $base, $echo); 153 return $this->wp_base; 154 } 155 function get_contents($file,$type='',$resumepos=0){ 86 function get_contents($file, $type = '', $resumepos = 0 ){ 156 87 if( empty($type) ){ 157 88 $extension = substr(strrchr($file, "."), 1); … … 161 92 if ( ! $temp ) 162 93 return false; 163 if( ! @ftp_fget($this->link, $temp,$file,$type,$resumepos) )94 if( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) ) 164 95 return false; 165 96 fseek($temp, 0); //Skip back to the start of the file being written to … … 171 102 return $contents; 172 103 } 173 function get_contents_array($file) {174 return explode("\n", $this->get_contents($file));175 } 176 function put_contents($file, $contents,$type=''){177 if( empty($type) ) {104 function get_contents_array($file) { 105 return explode("\n", $this->get_contents($file)); 106 } 107 function put_contents($file, $contents, $type = '' ) { 108 if( empty($type) ) { 178 109 $extension = substr(strrchr($file, "."), 1); 179 110 $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; … … 182 113 if ( ! $temp ) 183 114 return false; 184 fwrite($temp, $contents);115 fwrite($temp, $contents); 185 116 fseek($temp, 0); //Skip back to the start of the file being written to 186 $ret = @ftp_fput($this->link, $file,$temp,$type);117 $ret = @ftp_fput($this->link, $file, $temp, $type); 187 118 fclose($temp); 188 119 return $ret; 189 120 } 190 function cwd() {121 function cwd() { 191 122 $cwd = ftp_pwd($this->link); 192 123 if( $cwd ) … … 194 125 return $cwd; 195 126 } 196 function chdir($dir) {127 function chdir($dir) { 197 128 return @ftp_chdir($dir); 198 129 } 199 function chgrp($file, $group,$recursive=false){200 return false; 201 } 202 function chmod($file, $mode=false,$recursive=false){130 function chgrp($file, $group, $recursive = false ) { 131 return false; 132 } 133 function chmod($file, $mode = false, $recursive = false) { 203 134 if( ! $mode ) 204 135 $mode = $this->permission; … … 207 138 if ( ! $this->exists($file) ) 208 139 return false; 209 if ( ! $recursive || ! $this->is_dir($file) ) {210 if ( !function_exists('ftp_chmod'))140 if ( ! $recursive || ! $this->is_dir($file) ) { 141 if ( ! function_exists('ftp_chmod') ) 211 142 return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); 212 return @ftp_chmod($this->link, $mode,$file);143 return @ftp_chmod($this->link, $mode, $file); 213 144 } 214 145 //Is a directory, and we want recursive 215 146 $filelist = $this->dirlist($file); 216 147 foreach($filelist as $filename){ 217 $this->chmod($file .'/'.$filename,$mode,$recursive);218 } 219 return true; 220 } 221 function chown($file, $owner,$recursive=false){222 return false; 223 } 224 function owner($file) {148 $this->chmod($file . '/' . $filename, $mode, $recursive); 149 } 150 return true; 151 } 152 function chown($file, $owner, $recursive = false ) { 153 return false; 154 } 155 function owner($file) { 225 156 $dir = $this->dirlist($file); 226 157 return $dir[$file]['owner']; 227 158 } 228 function getchmod($file) {159 function getchmod($file) { 229 160 $dir = $this->dirlist($file); 230 161 return $dir[$file]['permsn']; 231 162 } 232 function gethchmod($file){ 233 //From the PHP.net page for ...? 234 $perms = $this->getchmod($file); 235 if (($perms & 0xC000) == 0xC000) { 236 // Socket 237 $info = 's'; 238 } elseif (($perms & 0xA000) == 0xA000) { 239 // Symbolic Link 240 $info = 'l'; 241 } elseif (($perms & 0x8000) == 0x8000) { 242 // Regular 243 $info = '-'; 244 } elseif (($perms & 0x6000) == 0x6000) { 245 // Block special 246 $info = 'b'; 247 } elseif (($perms & 0x4000) == 0x4000) { 248 // Directory 249 $info = 'd'; 250 } elseif (($perms & 0x2000) == 0x2000) { 251 // Character special 252 $info = 'c'; 253 } elseif (($perms & 0x1000) == 0x1000) { 254 // FIFO pipe 255 $info = 'p'; 256 } else { 257 // Unknown 258 $info = 'u'; 259 } 260 261 // Owner 262 $info .= (($perms & 0x0100) ? 'r' : '-'); 263 $info .= (($perms & 0x0080) ? 'w' : '-'); 264 $info .= (($perms & 0x0040) ? 265 (($perms & 0x0800) ? 's' : 'x' ) : 266 (($perms & 0x0800) ? 'S' : '-')); 267 268 // Group 269 $info .= (($perms & 0x0020) ? 'r' : '-'); 270 $info .= (($perms & 0x0010) ? 'w' : '-'); 271 $info .= (($perms & 0x0008) ? 272 (($perms & 0x0400) ? 's' : 'x' ) : 273 (($perms & 0x0400) ? 'S' : '-')); 274 275 // World 276 $info .= (($perms & 0x0004) ? 'r' : '-'); 277 $info .= (($perms & 0x0002) ? 'w' : '-'); 278 $info .= (($perms & 0x0001) ? 279 (($perms & 0x0200) ? 't' : 'x' ) : 280 (($perms & 0x0200) ? 'T' : '-')); 281 return $info; 282 } 283 function getnumchmodfromh($mode) { 284 $realmode = ""; 285 $legal = array("","w","r","x","-"); 286 $attarray = preg_split("//",$mode); 287 for($i=0;$i<count($attarray);$i++){ 288 if($key = array_search($attarray[$i],$legal)){ 289 $realmode .= $legal[$key]; 290 } 291 } 292 $mode = str_pad($realmode,9,'-'); 293 $trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1'); 294 $mode = strtr($mode,$trans); 295 $newmode = ''; 296 $newmode .= $mode[0]+$mode[1]+$mode[2]; 297 $newmode .= $mode[3]+$mode[4]+$mode[5]; 298 $newmode .= $mode[6]+$mode[7]+$mode[8]; 299 return $newmode; 300 } 301 function group($file){ 163 function group($file) { 302 164 $dir = $this->dirlist($file); 303 165 return $dir[$file]['group']; 304 166 } 305 function copy($source, $destination,$overwrite=false){167 function copy($source, $destination, $overwrite = false ) { 306 168 if( ! $overwrite && $this->exists($destination) ) 307 169 return false; … … 309 171 if( false === $content) 310 172 return false; 311 return $this->put_contents($destination, $content);312 } 313 function move($source, $destination,$overwrite=false){314 return ftp_rename($this->link, $source,$destination);173 return $this->put_contents($destination, $content); 174 } 175 function move($source, $destination, $overwrite = false) { 176 return ftp_rename($this->link, $source, $destination); 315 177 } 316 178 317 179 function delete($file,$recursive=false) { 318 180 if ( $this->is_file($file) ) 319 return @ftp_delete($this->link, $file);181 return @ftp_delete($this->link, $file); 320 182 if ( !$recursive ) 321 return @ftp_rmdir($this->link, $file);183 return @ftp_rmdir($this->link, $file); 322 184 $filelist = $this->dirlist($file); 323 185 foreach ((array) $filelist as $filename => $fileinfo) { 324 $this->delete($file .'/'.$filename,$recursive);325 } 326 return @ftp_rmdir($this->link, $file);327 } 328 329 function exists($file) {330 $list = ftp_rawlist($this->link, $file,false);186 $this->delete($file . '/' . $filename, $recursive); 187 } 188 return @ftp_rmdir($this->link, $file); 189 } 190 191 function exists($file) { 192 $list = ftp_rawlist($this->link, $file, false); 331 193 if( ! $list ) 332 194 return false; 333 195 return count($list) == 1 ? true : false; 334 196 } 335 function is_file($file) {197 function is_file($file) { 336 198 return $this->is_dir($file) ? false : true; 337 199 } 338 function is_dir($path) {200 function is_dir($path) { 339 201 $cwd = $this->cwd(); 340 202 $result = @ftp_chdir($this->link, $path); 341 if( $result && $path == $this->cwd() || 342 $this->cwd() != $cwd ) { 203 if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 343 204 @ftp_chdir($this->link, $cwd); 344 205 return true; … … 346 207 return false; 347 208 } 348 function is_readable($file) {209 function is_readable($file) { 349 210 //Get dir list, Check if the file is writable by the current user?? 350 211 return true; 351 212 } 352 function is_writable($file) {213 function is_writable($file) { 353 214 //Get dir list, Check if the file is writable by the current user?? 354 215 return true; 355 216 } 356 function atime($file) {357 return false; 358 } 359 function mtime($file) {217 function atime($file) { 218 return false; 219 } 220 function mtime($file) { 360 221 return ftp_mdtm($this->link, $file); 361 222 } 362 function size($file) {223 function size($file) { 363 224 return ftp_size($this->link, $file); 364 225 } 365 function touch($file, $time=0,$atime=0){366 return false; 367 } 368 function mkdir($path, $chmod=false,$chown=false,$chgrp=false){226 function touch($file, $time = 0, $atime = 0) { 227 return false; 228 } 229 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 369 230 if( !@ftp_mkdir($this->link, $path) ) 370 231 return false; … … 377 238 return true; 378 239 } 379 function rmdir($path, $recursive=false){240 function rmdir($path, $recursive = false) { 380 241 if( ! $recursive ) 381 242 return @ftp_rmdir($this->link, $path); … … 389 250 function parselisting($line) { 390 251 $is_windows = ($this->OS_remote == FTP_OS_Windows); 391 if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line,$lucifer)) {252 if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) { 392 253 $b = array(); 393 if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix254 if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix 394 255 $b['isdir'] = ($lucifer[7]=="<DIR>"); 395 256 if ( $b['isdir'] ) … … 449 310 } 450 311 451 function dirlist($path ='.',$incdot=false,$recursive=false){452 if( $this->is_file($path) ) {312 function dirlist($path = '.', $incdot = false, $recursive = false) { 313 if( $this->is_file($path) ) { 453 314 $limitFile = basename($path); 454 315 $path = dirname($path) . '/'; … … 457 318 } 458 319 459 $list = @ftp_rawlist($this->link , '-a ' . $path, false);320 $list = @ftp_rawlist($this->link, '-a ' . $path, false); 460 321 461 322 if ( $list === false ) … … 468 329 continue; 469 330 470 if ( $entry["name"]=="." or $entry["name"]=="..")331 if ( '.' == $entry["name"] || '..' == $entry["name"] ) 471 332 continue; 472 333 473 $dirlist[ $entry['name']] = $entry;334 $dirlist[ $entry['name'] ] = $entry; 474 335 } 475 336 … … 489 350 if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder 490 351 if ($recursive) 491 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);352 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 492 353 } 493 354 } else { //No dots 494 355 if ($recursive) 495 $struc['files'] = $this->dirlist($path .'/'.$struc['name'],$incdot,$recursive);356 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 496 357 } 497 358 }
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)