Changeset 8880
- Timestamp:
- 09/13/2008 06:06:20 PM (17 years ago)
- Location:
- trunk/wp-admin/includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/class-wp-filesystem-ssh2.php
r8865 r8880 64 64 $this->errors = new WP_Error(); 65 65 66 //Check if possible to use ftpfunctions.66 //Check if possible to use ssh2 functions. 67 67 if ( ! extension_loaded('ssh2') ) { 68 68 $this->errors->add('no_ssh2_ext', __('The ssh2 PHP extension is not available')); … … 90 90 $this->options['username'] = $opt['username']; 91 91 92 if ( ( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) )) {92 if ( ( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) ) ) { 93 93 $this->options['public_key'] = $opt['public_key']; 94 94 $this->options['private_key'] = $opt['private_key']; … … 100 100 101 101 102 if ( empty ($opt['password']) ) 102 if ( empty ($opt['password']) ) { 103 103 if ( !$this->keys ) // password can be blank if we are using keys 104 104 $this->errors->add('empty_password', __('SSH2 password is required')); 105 else105 } else { 106 106 $this->options['password'] = $opt['password']; 107 } 107 108 108 109 } … … 110 111 function connect() { 111 112 $this->debug("connect();"); 112 if ( ! $this->keys ) 113 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port']); 114 else 115 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']); 113 114 if ( ! $this->keys ) { 115 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port']); 116 } else { 117 $this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']); 118 } 116 119 117 120 if ( ! $this->link ) { … … 203 206 204 207 function put_contents($file, $contents, $type = '' ) { 205 $this->debug("put_contents( );");208 $this->debug("put_contents($file);"); 206 209 $tempfile = wp_tempnam( $file ); 207 210 $temp = fopen($tempfile, 'w'); … … 327 330 $this->debug("is_dir();"); 328 331 //DO NOT RELY ON dirlist()! 329 $list = $this->parselisting($this->run_command($this->link, sprintf('ls -lad %s', rtrim($path, '/'))));332 $list = $this->parselisting($this->run_command($this->link, sprintf('ls -lad %s', untrailingslashit($path)))); 330 333 if ( ! $list ) 331 334 return false; … … 360 363 function mkdir($path, $chmod = null, $chown = false, $chgrp = false) { 361 364 $this->debug("mkdir();"); 362 $path = trim($path, '/');365 $path = untrailingslashit($path); 363 366 if( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) ) 364 367 return false; -
trunk/wp-admin/includes/file.php
r8865 r8880 387 387 return new WP_Error('empty_archive', __('Empty archive')); 388 388 389 $path = explode('/', $to);389 $path = explode('/', untrailingslashit($to)); 390 390 for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/' 391 391 $tmppath = implode('/', array_slice($path, 0, $i) ); … … 402 402 $to = trailingslashit($to); 403 403 foreach ($archive_files as $file) { 404 $path = explode('/', $file['filename']); 405 for ( $i = count($path) - 1; $i >= 0; $i-- ) { //>=0 as the first element contains data, count()-1, as we do not want the file component 404 $path = $file['folder'] ? $file['filename'] : dirname($file['filename']); 405 $path = explode('/', $path); 406 for ( $i = count($path); $i >= 0; $i-- ) { //>=0 as the first element contains data 407 if ( empty($path[$i]) ) 408 continue; 406 409 $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 407 410 if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here 408 411 for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please. 409 412 $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 410 if ( ! $fs-> mkdir($tmppath, 0755) )413 if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, 0755) ) 411 414 return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath); 412 415 } … … 504 507 return true; 505 508 506 if( ! $credentials = get_option('ftp_credentials') ) 507 $credentials = array(); 509 $credentials = get_option('ftp_credentials', array()); 508 510 // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option) 509 511 $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']); … … 522 524 else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) ) 523 525 $credentials['connection_type'] = 'ftps'; 524 else 526 else if ( !isset($credentials['connection_type']) || (isset($_POST['connection_type']) && 'ftp' == $_POST['connection_type']) ) 525 527 $credentials['connection_type'] = 'ftp'; 526 528 … … 548 550 jQuery(function($){ 549 551 jQuery("#ssh").click(function () { 550 jQuery("#ssh_keys").show(); 552 jQuery("#ssh_keys").show(); 551 553 }); 552 jQuery("#ftp ").click(function () {553 jQuery("#ssh_keys").hide(); 554 jQuery("#ftp, #ftps").click(function () { 555 jQuery("#ssh_keys").hide(); 554 556 }); 555 jQuery("#ftps").click(function () {556 jQuery("#ssh_keys").hide();557 });558 jQuery(document).ready(function(){559 if ( jQuery("#ssh:checked").length )560 {561 jQuery("#ssh_keys").show();562 }563 });564 557 }); 565 558 --> … … 567 560 <form action="<?php echo $form_post ?>" method="post"> 568 561 <div class="wrap"> 569 <h2><?php _e(' FTPConnection Information') ?></h2>570 <p><?php _e('To perform the requested action, FTPconnection information is required.') ?></p>562 <h2><?php _e('Connection Information') ?></h2> 563 <p><?php _e('To perform the requested action, connection information is required.') ?></p> 571 564 <table class="form-table"> 572 565 <tr valign="top"> … … 582 575 <td><input name="password" type="password" id="password" value=""<?php if( defined('FTP_PASS') ) echo ' disabled="disabled"' ?> size="40" /><?php if( defined('FTP_PASS') && !empty($password) ) echo '<em>'.__('(Password not shown)').'</em>'; ?></td> 583 576 </tr> 584 <tr id="ssh_keys" valign="top" style=" display:none">577 <tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>"> 585 578 <th scope="row"><label id="keys" for="keys"><?php _e('Authentication Keys') ?></label></th> 586 579 <td><label for="public_key"><?php _e('Public Key:') ?></label ><input name="public_key" type="text" id="public_key" value=""<?php if( defined('FTP_PUBKEY') ) echo ' disabled="disabled"' ?> size="40" /> <label for="private_key"><?php _e('Private Key:') ?></label> <input name="private_key" type="text" id="private_key" value=""<?php if( defined('FTP_PRIKEY') ) echo ' disabled="disabled"' ?> size="40" /><br/><div><?php _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.') ?></div></td> … … 590 583 <td> 591 584 <fieldset><legend class="hidden"><?php _e('Connection Type') ?> </legend> 592 <p><label><input id="ftp" name="connection_type" type="radio" value="ftp" <?php checked('ftp', $connection_type); ?>/> <?php _e('FTP') ?></label><br />593 <label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?>/> <?php _e('FTPS (SSL)') ?></label><br />594 <?php if ( extension_loaded('ssh2') ) { ?><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?>/> <?php _e('SSH') ?></label><?php } ?></p>585 <p><label><input id="ftp" name="connection_type" type="radio" value="ftp" <?php checked('ftp', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('FTP') ?></label><br /> 586 <label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); if ( defined('FTP_SSH') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('FTPS (SSL)') ?></label><br /> 587 <?php if ( extension_loaded('ssh2') ) { ?><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('SSH') ?></label><?php } ?></p> 595 588 </fieldset> 596 589 </td>
Note: See TracChangeset
for help on using the changeset viewer.