Make WordPress Core

Ticket #7690: 7690.12.diff

File 7690.12.diff, 5.5 KB (added by ShaneF, 18 years ago)
  • wp-admin/includes/class-wp-filesystem-ssh2.php

     
    6363                $this->method = 'ssh2';
    6464                $this->errors = new WP_Error();
    6565
    66                 //Check if possible to use ftp functions.
     66                //Check if possible to use ssh2 functions.
    6767                if ( ! extension_loaded('ssh2') ) {
    6868                        $this->errors->add('no_ssh2_ext', __('The ssh2 PHP extension is not available'));
    6969                        return false;
     
    8989                else
    9090                        $this->options['username'] = $opt['username'];
    9191
    92                 if (( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) )) {
     92                if ( ( !empty ($opt['public_key']) ) && ( !empty ($opt['private_key']) ) ) {
    9393                        $this->options['public_key'] = $opt['public_key'];     
    9494                        $this->options['private_key'] = $opt['private_key'];
    9595                       
     
    9999                }
    100100
    101101
    102                 if ( empty ($opt['password']) )
     102                if ( empty ($opt['password']) ) {
    103103                        if ( !$this->keys )     //       password can be blank if we are using keys
    104104                                $this->errors->add('empty_password', __('SSH2 password is required'));
    105                 else
     105                } else {
    106106                        $this->options['password'] = $opt['password'];
     107                }
    107108                       
    108109        }
    109110
    110111        function connect() {
    111112                $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                }
    116119                       
    117120                if ( ! $this->link ) {
    118121                        $this->errors->add('connect', sprintf(__('Failed to connect to SSH2 Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
     
    359362       
    360363        function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
    361364                $this->debug("mkdir();");
    362                 $path = trim($path, '/');
     365                $path = rtrim($path, '/');
    363366                if( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
    364367                        return false;
    365368                if( $chown )
  • wp-admin/includes/file.php

     
    405405                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
    406406                        $tmppath = $to . implode('/', array_slice($path, 0, $i) );
    407407                        if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here
    408                                 for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please.
     408                                for ( $i = $i + 1; $i < count($path); $i++ ) { //< count() no file component please.
    409409                                        $tmppath = $to . implode('/', array_slice($path, 0, $i) );
    410410                                        if ( ! $fs->mkdir($tmppath, 0755) )
    411411                                                return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
     
    503503        if ( 'direct' == $type )
    504504                return true;
    505505
    506         if( ! $credentials = get_option('ftp_credentials') )
    507                 $credentials = array();
     506        $credentials = get_option('ftp_credentials');
     507
    508508        // 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)
    509509        $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
    510510        $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
     
    517517        if ( strpos($credentials['hostname'], ':') )
    518518                list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
    519519
    520         if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) )
     520        if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) || $credentials['connection_type'] == 'ssh' )
    521521                $credentials['connection_type'] = 'ssh';
    522         else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) )
     522        else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) || $credentials['connection_type'] == 'ftps' )
    523523                $credentials['connection_type'] = 'ftps';
    524524        else
    525525                $credentials['connection_type'] = 'ftp';
    526 
    527         if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
     526       
     527        if ( !$error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
    528528                $stored_credentials = $credentials;
    529529                unset($stored_credentials['password'], $stored_credentials['private_key'], $stored_credentials['public_key']);
    530530                update_option('ftp_credentials', $stored_credentials);
     
    566566</script>
    567567<form action="<?php echo $form_post ?>" method="post">
    568568<div class="wrap">
    569 <h2><?php _e('FTP Connection Information') ?></h2>
    570 <p><?php _e('To perform the requested action, FTP connection information is required.') ?></p>
     569<h2><?php _e('Connection Information') ?></h2>
     570<p><?php _e('To perform the requested action, connection information is required.') ?></p>
    571571<table class="form-table">
    572572<tr valign="top">
    573573<th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>