Make WordPress Core


Ignore:
Timestamp:
09/09/2008 03:24:05 AM (18 years ago)
Author:
azaozz
Message:

SSH2 filesystem improvements, props ShaneF, see #7690

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r8811 r8852  
    387387                return new WP_Error('empty_archive', __('Empty archive'));
    388388
     389        $path = explode('/', $to);
     390        for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/'
     391                $tmppath = implode('/', array_slice($path, 0, $i) );
     392                if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1)
     393                        for ( $i = $i + 1; $i <= count($path); $i++ ) {
     394                                $tmppath = implode('/', array_slice($path, 0, $i) );
     395                                if ( ! $fs->mkdir($tmppath, 0755) )
     396                                        return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
     397                        }
     398                        break; //Exit main for loop
     399                }
     400        }
     401
    389402        $to = trailingslashit($to);
    390         $path = explode('/', $to);
    391         $tmppath = '';
    392         for ( $j = 0; $j < count($path) - 1; $j++ ) {
    393                 $tmppath .= $path[$j] . '/';
    394                 if ( ! $fs->is_dir($tmppath) )
    395                         $fs->mkdir($tmppath, 0755);
    396         }
    397 
    398403        foreach ($archive_files as $file) {
    399404                $path = explode('/', $file['filename']);
    400                 $tmppath = '';
    401 
    402                 // Loop through each of the items and check that the folder exists.
    403                 for ( $j = 0; $j < count($path) - 1; $j++ ) {
    404                         $tmppath .= $path[$j] . '/';
    405                         if ( ! $fs->is_dir($to . $tmppath) )
    406                                 if ( !$fs->mkdir($to . $tmppath, 0755) )
    407                                         return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath);
     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
     406                        $tmppath = $to . implode('/', array_slice($path, 0, $i) );
     407                        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.
     409                                        $tmppath = $to . implode('/', array_slice($path, 0, $i) );
     410                                        if ( ! $fs->mkdir($tmppath, 0755) )
     411                                                return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
     412                                }
     413                                break; //Exit main for loop
     414                        }
    408415                }
    409416
    … …  
    415422                }
    416423        }
    417 
    418424        return true;
    419425}
    … …  
    454460                return false;
    455461
    456         $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
     462        $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
    457463        if( ! file_exists($abstraction_file) )
    458464                return;
    … …  
    481487        }
    482488
    483         if ( isset($args['connection_type']) && 'ssh' == $args['connection_type'] ) {
    484                 $method = 'SSH2';
    485                 return apply_filters('filesystem_method', $method);
    486         }
    487 
     489        if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') ) $method = 'ssh2';
    488490        if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
    489491        if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
    … …  
    508510        $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
    509511        $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']);
    510         if ( defined('FTP_SSH') || 'ssh' == $_POST['connection_type'] )
     512       
     513        if ( strpos($credentials['hostname'], ':') )
     514                list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2);
     515
     516        if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) )
    511517                $credentials['connection_type'] = 'ssh';
    512         else if ( defined('FTP_SSL') || 'ftps' == $_POST['connection_type'] )
     518        else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type']) )
    513519                $credentials['connection_type'] = 'ftps';
    514520        else
    … …  
    524530        $username = '';
    525531        $password = '';
    526         $ssl = '';
     532        $connection_type = '';
    527533        if ( !empty($credentials) )
    528534                extract($credentials, EXTR_OVERWRITE);
    … …  
    541547<tr valign="top">
    542548<th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
    543 <td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname) ?>"<?php if( defined('FTP_HOST') ) echo ' disabled="disabled"' ?> size="40" /></td>
     549<td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php if( defined('FTP_HOST') ) echo ' disabled="disabled"' ?> size="40" /></td>
    544550</tr>
    545551<tr valign="top">
    … …  
    557563<p><label><input name="connection_type"  type="radio" value="ftp" <?php checked('ftp', $connection_type); ?>    /> <?php _e('FTP') ?></label><br />
    558564<label><input name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br />
    559 <label><input name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label></p>
     565<?php if ( extension_loaded('ssh2') ) { ?><label><input name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label><?php } ?></p>
    560566</fieldset>
    561567</td>
Note: See TracChangeset for help on using the changeset viewer.