Make WordPress Core

Ticket #7690: 7690.15.diff

File 7690.15.diff, 8.1 KB (added by DD32, 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']));
     
    202205        }
    203206
    204207        function put_contents($file, $contents, $type = '' ) {
    205                 $this->debug("put_contents();");
     208                $this->debug("put_contents($file);");
    206209                $tempfile = wp_tempnam( $file );
    207210                $temp = fopen($tempfile, 'w');
    208211                if ( ! $temp )
     
    326329        function is_dir($path) {
    327330                $this->debug("is_dir();");
    328331                //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))));
    330333                if ( ! $list )
    331334                        return false;
    332335                else
     
    359362       
    360363        function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
    361364                $this->debug("mkdir();");
    362                 $path = trim($path, '/');
     365                $path = untrailingslashit($path);
    363366                if( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
    364367                        return false;
    365368                if( $chown )
  • wp-admin/includes/file.php

     
    386386        if ( 0 == count($archive_files) )
    387387                return new WP_Error('empty_archive', __('Empty archive'));
    388388
    389         $path = explode('/', $to);
     389        $path = explode('/', untrailingslashit($to));
    390390        for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/'
    391391                $tmppath = implode('/', array_slice($path, 0, $i) );
    392392                if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1)
     
    401401
    402402        $to = trailingslashit($to);
    403403        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;
    406409                        $tmppath = $to . implode('/', array_slice($path, 0, $i) );
    407410                        if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here
    408411                                for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please.
    409412                                        $tmppath = $to . implode('/', array_slice($path, 0, $i) );
    410                                         if ( ! $fs->mkdir($tmppath, 0755) )
     413                                        if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, 0755) )
    411414                                                return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
    412415                                }
    413416                                break; //Exit main for loop
     
    503506        if ( 'direct' == $type )
    504507                return true;
    505508
    506         if( ! $credentials = get_option('ftp_credentials') )
    507                 $credentials = array();
     509        $credentials = get_option('ftp_credentials', array());
    508510        // 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)
    509511        $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
    510512        $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
     
    521523                $credentials['connection_type'] = 'ssh';
    522524        else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) )
    523525                $credentials['connection_type'] = 'ftps';
    524         else
     526        else if ( !isset($credentials['connection_type']) || (isset($_POST['connection_type']) && 'ftp' == $_POST['connection_type']) )
    525527                $credentials['connection_type'] = 'ftp';
    526528
    527529        if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
     
    547549<!--
    548550jQuery(function($){
    549551        jQuery("#ssh").click(function () {
    550                 jQuery("#ssh_keys").show();             
     552                jQuery("#ssh_keys").show();
    551553        });
    552554        jQuery("#ftp").click(function () {
    553                 jQuery("#ssh_keys").hide();             
     555                jQuery("#ssh_keys").hide();
    554556        });     
    555557        jQuery("#ftps").click(function () {
    556                 jQuery("#ssh_keys").hide();             
     558                jQuery("#ssh_keys").hide();
    557559        });
    558560        jQuery(document).ready(function(){
    559                 if ( jQuery("#ssh:checked").length )
    560                 {
     561                if ( jQuery("#ssh:checked").length ) {
    561562                        jQuery("#ssh_keys").show();
    562563                }
    563564        });
     
    566567</script>
    567568<form action="<?php echo $form_post ?>" method="post">
    568569<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>
     570<h2><?php _e('Connection Information') ?></h2>
     571<p><?php _e('To perform the requested action, connection information is required.') ?></p>
    571572<table class="form-table">
    572573<tr valign="top">
    573574<th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
     
    589590<th scope="row"><?php _e('Connection Type') ?></th>
    590591<td>
    591592<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>
     593<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 />
     594<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 />
     595<?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>
    595596</fieldset>
    596597</td>
    597598</tr>