Ticket #32774: 32774.diff
File 32774.diff, 19.5 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/class-ftp.php
class ftp_base { 138 138 $this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support")); 139 139 $this->_connected=FALSE; 140 140 $this->_ready=FALSE; 141 141 $this->_can_restore=FALSE; 142 142 $this->_code=0; 143 143 $this->_message=""; 144 144 $this->_ftp_buff_size=4096; 145 145 $this->_curtype=NULL; 146 146 $this->SetUmask(0022); 147 147 $this->SetType(FTP_AUTOASCII); 148 148 $this->SetTimeout(30); 149 149 $this->Passive(!$this->_port_available); 150 150 $this->_login="anonymous"; 151 151 $this->_password="anon@ftp.com"; 152 152 $this->_features=array(); 153 153 $this->OS_local=FTP_OS_Unix; 154 154 $this->OS_remote=FTP_OS_Unix; 155 155 $this->features=array(); 156 156 if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows; 157 157 elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac; 158 158 } 159 159 160 160 // <!-- --------------------------------------------------------------------------------------- --> 161 161 // <!-- Public functions --> 162 162 // <!-- --------------------------------------------------------------------------------------- --> 163 163 164 164 function parselisting($line) { 165 165 $is_windows = ($this->OS_remote == FTP_OS_Windows); 166 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)) {166 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) ) { 167 167 $b = array(); 168 if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix 169 $b['isdir'] = ($lucifer[7]=="<DIR>"); 168 if ( $lucifer[3] < 70 ) 169 $lucifer[3] +=2000; 170 else 171 $lucifer[3] += 1900; // 4digit year fix 172 $b['isdir'] = ( $lucifer[7] == '<DIR>'); 170 173 if ( $b['isdir'] ) 171 174 $b['type'] = 'd'; 172 175 else 173 176 $b['type'] = 'f'; 174 $b['size'] = $lucifer[7]; 175 $b['month'] = $lucifer[1]; 176 $b['day'] = $lucifer[2]; 177 $b['year'] = $lucifer[3]; 178 $b['hour'] = $lucifer[4]; 179 $b['minute'] = $lucifer[5]; 180 $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]); 181 $b['am/pm'] = $lucifer[6]; 177 $b['size'] = $b['isdir'] ? false : (int) $lucifer[7]; 178 $b['time'] = @mktime($lucifer[4] + ($lucifer[6] === "PM" ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]); 182 179 $b['name'] = $lucifer[8]; 183 } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) { 184 //echo $line."\n"; 185 $lcount=count($lucifer); 186 if ($lcount<8) return ''; 180 // Unknown on Windows: 181 $b['perms'] = $b['islink'] = $b['owner'] = $b['group'] = false; 182 } elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) { 183 $lcount = count($lucifer); 184 if ( $lcount < 8 ) 185 return ''; 187 186 $b = array(); 188 $b['isdir'] = $lucifer[0]{0} === "d";189 $b['islink'] = $lucifer[0]{0} === "l";187 $b['isdir'] = $lucifer[0]{0} === 'd'; 188 $b['islink'] = $lucifer[0]{0} === 'l'; 190 189 if ( $b['isdir'] ) 191 190 $b['type'] = 'd'; 192 191 elseif ( $b['islink'] ) 193 192 $b['type'] = 'l'; 194 193 else 195 194 $b['type'] = 'f'; 196 195 $b['perms'] = $lucifer[0]; 197 $b['number'] = $lucifer[1];198 196 $b['owner'] = $lucifer[2]; 199 197 $b['group'] = $lucifer[3]; 200 $b['size'] = $ lucifer[4];201 if ( $lcount==8) {202 sscanf($lucifer[5], "%d-%d-%d",$b['year'],$b['month'],$b['day']);203 sscanf($lucifer[6], "%d:%d",$b['hour'],$b['minute']);204 $b['time'] = @mktime($b['hour'], $b['minute'],0,$b['month'],$b['day'],$b['year']);198 $b['size'] = $b['isdir'] && ! $b['islink'] ? (int)$lucifer[4] : false; 199 if ( $lcount == 8 ) { 200 sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']); 201 sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']); 202 $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']); 205 203 $b['name'] = $lucifer[7]; 206 204 } else { 207 205 $b['month'] = $lucifer[5]; 208 206 $b['day'] = $lucifer[6]; 209 if ( preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {207 if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) { 210 208 $b['year'] = date("Y"); 211 209 $b['hour'] = $l2[1]; 212 210 $b['minute'] = $l2[2]; 213 211 } else { 214 212 $b['year'] = $lucifer[7]; 215 213 $b['hour'] = 0; 216 214 $b['minute'] = 0; 217 215 } 218 $b['time'] = strtotime( sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));216 $b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) ); 219 217 $b['name'] = $lucifer[8]; 220 218 } 219 unset( $b['year'], $b['month'], $b['day'], $b['hour'], $b['minute'] ); 221 220 } 221 unset( $b['isdir'], $b['islink'] ); 222 222 223 223 return $b; 224 224 } 225 225 226 226 function SendMSG($message = "", $crlf=true) { 227 227 if ($this->Verbose) { 228 228 echo $message.($crlf?CRLF:""); 229 229 flush(); 230 230 } 231 231 return TRUE; 232 232 } 233 233 234 234 function SetType($mode=FTP_AUTOASCII) { 235 235 if(!in_array($mode, $this->AuthorizedTransferMode)) { 236 236 $this->SendMSG("Wrong type"); -
src/wp-admin/includes/class-wp-filesystem-base.php
class WP_Filesystem_Base { 749 749 * @since 2.5.0 750 750 * @abstract 751 751 * 752 752 * @param string $path Path to directory or file. 753 753 * @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files. 754 754 * Default true. 755 755 * @param bool $recursive Optional. Whether to recursively include file details in nested directories. 756 756 * Default false. 757 757 * @return array|bool { 758 758 * Array of files. False if unable to list directory contents. 759 759 * 760 760 * @type string $name Name of the file/directory. 761 761 * @type string $perms *nix representation of permissions. 762 762 * @type int $permsn Octal representation of permissions. 763 763 * @type string $owner Owner name or ID. 764 * @type string $group Group name or ID. 764 765 * @type int $size Size of file in bytes. 765 * @type int $lastmodunix Last modified unix timestamp. 766 * @type mixed $lastmod Last modified month (3 letter) and day (without leading 0). 767 * @type int $time Last modified time. 766 * @type int $time Last modified unix timestamp. 768 767 * @type string $type Type of resource. 'f' for file, 'd' for directory. 769 768 * @type mixed $files If a directory and $recursive is true, contains another array of files. 770 769 * } 771 770 */ 772 771 public function dirlist( $path, $include_hidden = true, $recursive = false ) { 773 772 return false; 774 773 } 775 774 776 775 } // WP_Filesystem_Base -
src/wp-admin/includes/class-wp-filesystem-direct.php
class WP_Filesystem_Direct extends WP_Fi 300 300 * @param string $file 301 301 * @return bool 302 302 */ 303 303 public function is_file($file) { 304 304 return @is_file($file); 305 305 } 306 306 /** 307 307 * @param string $path 308 308 * @return bool 309 309 */ 310 310 public function is_dir($path) { 311 311 return @is_dir($path); 312 312 } 313 313 314 314 /** 315 * @param string $path 316 * @return bool 317 */ 318 private function is_link( $path ) { 319 // Internal use only 320 return @is_link( $path ); 321 } 322 323 /** 315 324 * @param string $file 316 325 * @return bool 317 326 */ 318 327 public function is_readable($file) { 319 328 return @is_readable($file); 320 329 } 321 330 322 331 /** 323 332 * @param string $file 324 333 * @return bool 325 334 */ 326 335 public function is_writable($file) { 327 336 return @is_writable($file); 328 337 } 329 338 … … class WP_Filesystem_Direct extends WP_Fi 424 433 $ret = array(); 425 434 426 435 while (false !== ($entry = $dir->read()) ) { 427 436 $struc = array(); 428 437 $struc['name'] = $entry; 429 438 430 439 if ( '.' == $struc['name'] || '..' == $struc['name'] ) 431 440 continue; 432 441 433 442 if ( ! $include_hidden && '.' == $struc['name'][0] ) 434 443 continue; 435 444 436 445 if ( $limit_file && $struc['name'] != $limit_file) 437 446 continue; 438 447 448 if ( $this->is_link( $path . '/' . $entry ) ) { 449 $struc['type'] = 'l'; 450 } elseif ( $this->is_dir( $path . '/' . $entry) ) { 451 $struc['type'] = 'd'; 452 } else { 453 $struc['type'] = 'f'; 454 } 455 439 456 $struc['perms'] = $this->gethchmod($path.'/'.$entry); 440 457 $struc['permsn'] = $this->getnumchmodfromh($struc['perms']); 441 $struc['number'] = false;442 458 $struc['owner'] = $this->owner($path.'/'.$entry); 443 $struc['group'] = $this->group($path.'/'.$entry); 444 $struc['size'] = $this->size($path.'/'.$entry); 445 $struc['lastmodunix']= $this->mtime($path.'/'.$entry); 446 $struc['lastmod'] = date('M j',$struc['lastmodunix']); 447 $struc['time'] = date('h:i:s',$struc['lastmodunix']); 448 $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; 459 $struc['group'] = $this->group($path.'/'.$entry); 460 $struc['size'] = $struc['type'] == 'f' ? $this->size( $path . '/' . $entry) : false; 461 $struc['time'] = $this->mtime($path.'/'.$entry); 462 463 if ( 'u' === $struc['perms']{0} ) { 464 $struc['perms'][0] = ( 'f' === $struc['type'] ? '-' : $struc['type'] ); 465 } 449 466 450 467 if ( 'd' == $struc['type'] ) { 451 468 if ( $recursive ) 452 469 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); 453 470 else 454 471 $struc['files'] = array(); 455 472 } 456 473 457 474 $ret[ $struc['name'] ] = $struc; 458 475 } 459 476 $dir->close(); 460 477 unset($dir); 461 478 return $ret; 462 479 } 463 480 } -
src/wp-admin/includes/class-wp-filesystem-ftpext.php
class WP_Filesystem_FTPext extends WP_Fi 390 390 static $is_windows = null; 391 391 if ( is_null($is_windows) ) 392 392 $is_windows = stripos( ftp_systype($this->link), 'win') !== false; 393 393 394 394 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) ) { 395 395 $b = array(); 396 396 if ( $lucifer[3] < 70 ) 397 397 $lucifer[3] +=2000; 398 398 else 399 399 $lucifer[3] += 1900; // 4digit year fix 400 400 $b['isdir'] = ( $lucifer[7] == '<DIR>'); 401 401 if ( $b['isdir'] ) 402 402 $b['type'] = 'd'; 403 403 else 404 404 $b['type'] = 'f'; 405 $b['size'] = $lucifer[7]; 406 $b['month'] = $lucifer[1]; 407 $b['day'] = $lucifer[2]; 408 $b['year'] = $lucifer[3]; 409 $b['hour'] = $lucifer[4]; 410 $b['minute'] = $lucifer[5]; 411 $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]); 412 $b['am/pm'] = $lucifer[6]; 405 $b['size'] = $b['isdir'] ? false : (int) $lucifer[7]; 406 $b['time'] = @mktime($lucifer[4] + ($lucifer[6] === "PM" ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]); 413 407 $b['name'] = $lucifer[8]; 408 // Unknown on Windows: 409 $b['perms'] = $b['permsn'] = $b['owner'] = $b['group'] = false; 414 410 } elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) { 415 //echo $line."\n";416 411 $lcount = count($lucifer); 417 412 if ( $lcount < 8 ) 418 413 return ''; 419 414 $b = array(); 420 415 $b['isdir'] = $lucifer[0]{0} === 'd'; 421 416 $b['islink'] = $lucifer[0]{0} === 'l'; 422 417 if ( $b['isdir'] ) 423 418 $b['type'] = 'd'; 424 419 elseif ( $b['islink'] ) 425 420 $b['type'] = 'l'; 426 421 else 427 422 $b['type'] = 'f'; 428 423 $b['perms'] = $lucifer[0]; 429 424 $b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); 430 $b['number'] = $lucifer[1];431 425 $b['owner'] = $lucifer[2]; 432 426 $b['group'] = $lucifer[3]; 433 $b['size'] = $lucifer[4];427 $b['size'] = ! $b['isdir'] && ! $b['islink'] ? (int)$lucifer[4] : false; 434 428 if ( $lcount == 8 ) { 435 429 sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']); 436 430 sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']); 437 431 $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']); 438 432 $b['name'] = $lucifer[7]; 439 433 } else { 440 434 $b['month'] = $lucifer[5]; 441 435 $b['day'] = $lucifer[6]; 442 436 if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) { 443 437 $b['year'] = date("Y"); 444 438 $b['hour'] = $l2[1]; 445 439 $b['minute'] = $l2[2]; 446 440 } else { 447 441 $b['year'] = $lucifer[7]; 448 442 $b['hour'] = 0; 449 443 $b['minute'] = 0; 450 444 } 451 445 $b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) ); 452 446 $b['name'] = $lucifer[8]; 453 447 } 448 unset( $b['year'], $b['month'], $b['day'], $b['hour'], $b['minute'] ); 454 449 } 450 unset( $b['isdir'], $b['islink'] ); 455 451 456 452 // Replace symlinks formatted as "source -> target" with just the source name 457 if ( $b['islink'] )453 if ( 'l' === $b['type'] ) { 458 454 $b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] ); 455 } 459 456 460 457 return $b; 461 458 } 462 459 463 460 /** 464 461 * @param string $path 465 462 * @param bool $include_hidden 466 463 * @param bool $recursive 467 464 * @return bool|array 468 465 */ 469 466 public function dirlist($path = '.', $include_hidden = true, $recursive = false) { 470 467 if ( $this->is_file($path) ) { 471 468 $limit_file = basename($path); 472 469 $path = dirname($path) . '/'; 473 470 } else { -
src/wp-admin/includes/class-wp-filesystem-ftpsockets.php
class WP_Filesystem_ftpsockets extends W 434 434 435 435 if ( ! $include_hidden && '.' == $struc['name'][0] ) 436 436 continue; 437 437 438 438 if ( $limit_file && $struc['name'] != $limit_file ) 439 439 continue; 440 440 441 441 if ( 'd' == $struc['type'] ) { 442 442 if ( $recursive ) 443 443 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); 444 444 else 445 445 $struc['files'] = array(); 446 446 } 447 447 448 448 // Replace symlinks formatted as "source -> target" with just the source name 449 if ( $struc['islink'] )449 if ( 'l' === $struc['type'] ) { 450 450 $struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] ); 451 } 451 452 452 453 // Add the Octal representation of the file permissions 453 $struc['permsn'] = $ this->getnumchmodfromh( $struc['perms'] );454 $struc['permsn'] = $struc['perms'] ? $this->getnumchmodfromh( $struc['perms'] ) : false 454 455 455 456 $ret[ $struc['name'] ] = $struc; 456 457 } 457 458 458 459 reset_mbstring_encoding(); 459 460 460 461 return $ret; 461 462 } 462 463 463 464 /** 464 465 * @access public 465 466 */ 466 467 public function __destruct() { 467 468 $this->ftp->quit(); 468 469 } -
src/wp-admin/includes/class-wp-filesystem-ssh2.php
class WP_Filesystem_SSH2 extends WP_File 359 359 * @return bool 360 360 */ 361 361 public function is_file($file) { 362 362 $file = ltrim($file, '/'); 363 363 return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 364 364 } 365 365 /** 366 366 * @param string $path 367 367 * @return bool 368 368 */ 369 369 public function is_dir($path) { 370 370 $path = ltrim($path, '/'); 371 371 return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path); 372 372 } 373 373 /** 374 * @param string $path 375 * @return bool 376 */ 377 private function is_link( $path ) { 378 // Internal use only 379 return @is_link('ssh2.sftp://' . $this->sftp_link . '/' . $path); 380 } 381 /** 374 382 * @param string $file 375 383 * @return bool 376 384 */ 377 385 public function is_readable($file) { 378 386 $file = ltrim($file, '/'); 379 387 return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 380 388 } 381 389 /** 382 390 * @param string $file 383 391 * @return bool 384 392 */ 385 393 public function is_writable($file) { 386 394 $file = ltrim($file, '/'); 387 395 return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 388 396 } … … class WP_Filesystem_SSH2 extends WP_File 470 478 471 479 if ( ! $this->is_dir($path) ) 472 480 return false; 473 481 474 482 $ret = array(); 475 483 $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') ); 476 484 477 485 if ( ! $dir ) 478 486 return false; 479 487 480 488 while (false !== ($entry = $dir->read()) ) { 481 489 $struc = array(); 482 490 $struc['name'] = $entry; 483 491 484 492 if ( '.' == $struc['name'] || '..' == $struc['name'] ) 485 continue; //Do not care about these folders.493 continue; 486 494 487 495 if ( ! $include_hidden && '.' == $struc['name'][0] ) 488 496 continue; 489 497 490 498 if ( $limit_file && $struc['name'] != $limit_file ) 491 499 continue; 492 500 501 if ( $this->is_link( $path . '/' . $entry ) ) { 502 $struc['type'] = 'l'; 503 } elseif ( $this->is_dir( $path . '/' . $entry) ) { 504 $struc['type'] = 'd'; 505 } else { 506 $struc['type'] = 'f'; 507 } 508 493 509 $struc['perms'] = $this->gethchmod($path.'/'.$entry); 494 510 $struc['permsn'] = $this->getnumchmodfromh($struc['perms']); 495 $struc['number'] = false;496 511 $struc['owner'] = $this->owner($path.'/'.$entry); 497 512 $struc['group'] = $this->group($path.'/'.$entry); 498 $struc['size'] = $this->size($path.'/'.$entry); 499 $struc['lastmodunix']= $this->mtime($path.'/'.$entry); 500 $struc['lastmod'] = date('M j',$struc['lastmodunix']); 501 $struc['time'] = date('h:i:s',$struc['lastmodunix']); 502 $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; 513 $struc['size'] = $struc['type'] == 'f' ? $this->size($path . '/' . $entry) : false; 514 $struc['time'] = $this->mtime($path.'/'.$entry); 515 516 if ( 'u' === $struc['perms']{0} ) { 517 $struc['perms'][0] = ( 'f' === $struc['type'] ? '-' : $struc['type'] ); 518 } 503 519 504 520 if ( 'd' == $struc['type'] ) { 505 521 if ( $recursive ) 506 522 $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); 507 523 else 508 524 $struc['files'] = array(); 509 525 } 510 526 511 527 $ret[ $struc['name'] ] = $struc; 512 528 } 513 529 $dir->close(); 514 530 unset($dir); 515 531 return $ret; 516 532 } 517 533 } -
src/wp-admin/includes/class-wp-upgrader.php
class WP_Upgrader { 252 252 * @param string $package Full path to the package file. 253 253 * @param bool $delete_package Optional. Whether to delete the package file after attempting 254 254 * to unpack it. Default true. 255 255 * @return string|WP_Error The path to the unpacked contents, or a {@see WP_Error} on failure. 256 256 */ 257 257 public function unpack_package( $package, $delete_package = true ) { 258 258 global $wp_filesystem; 259 259 260 260 $this->skin->feedback('unpack_package'); 261 261 262 262 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; 263 263 264 264 //Clean up contents of upgrade directory beforehand. 265 265 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder); 266 266 if ( !empty($upgrade_files) ) { 267 foreach ( $upgrade_files as $file ) 268 $wp_filesystem->delete($upgrade_folder . $file['name'], true); 267 foreach ( $upgrade_files as $file ) { 268 $wp_filesystem->delete( $upgrade_folder . $file['name'], true, $file['type'] ); 269 } 269 270 } 270 271 271 272 // We need a working directory - Strip off any .tmp or .zip suffixes 272 273 $working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' ); 273 274 274 275 // Clean up working directory 275 276 if ( $wp_filesystem->is_dir($working_dir) ) 276 277 $wp_filesystem->delete($working_dir, true); 277 278 278 279 // Unzip package to working directory 279 280 $result = unzip_file( $package, $working_dir ); 280 281 281 282 // Once extracted, delete the package if required. 282 283 if ( $delete_package ) 283 284 unlink($package);