Make WordPress Core


Ignore:
Timestamp:
04/19/2009 07:36:28 PM (16 years ago)
Author:
ryan
Message:

consolidate plugin/theme/core upgrade/install functions. Props DD32. see #7875

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-ftpext.php

    r10930 r11005  
    1818    var $link;
    1919    var $timeout = 5;
    20     var $errors = array();
     20    var $errors = null;
    2121    var $options = array();
    2222
     
    6666
    6767    function connect() {
    68         if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') )
     68        if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
    6969            $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout);
    7070        else
     
    188188    }
    189189
    190     function delete($file,$recursive=false) {
     190    function delete($file, $recursive = false ) {
     191        if ( empty($file) )
     192            return false;
    191193        if ( $this->is_file($file) )
    192194            return @ftp_delete($this->link, $file);
    193195        if ( !$recursive )
    194196            return @ftp_rmdir($this->link, $file);
    195         $filelist = $this->dirlist($file);
    196         foreach ((array) $filelist as $filename => $fileinfo) {
    197             $this->delete($file . '/' . $filename, $recursive);
    198         }
     197
     198        $filelist = $this->dirlist( trailingslashit($file) );
     199        if ( !empty($filelist) )
     200            foreach ( $filelist as $delete_file )
     201                $this->delete( trailingslashit($file) . $delete_file['name'], $recursive);
    199202        return @ftp_rmdir($this->link, $file);
    200203    }
    201204
    202205    function exists($file) {
    203         $list = ftp_rawlist($this->link, $file, false);
    204         if( ! $list )
    205             return false;
    206         return count($list) == 1 ? true : false;
     206        $list = @ftp_rawlist($this->link, $file, false);
     207        return !empty($list); //empty list = no file, so invert.
    207208    }
    208209    function is_file($file) {
    209         return $this->is_dir($file) ? false : true;
     210        return $this->exists($file) && !$this->is_dir($file);
    210211    }
    211212    function is_dir($path) {
    212213        $cwd = $this->cwd();
    213         $result = @ftp_chdir($this->link, $path);
     214        $result = @ftp_chdir($this->link, trailingslashit($path) );
    214215        if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
    215216            @ftp_chdir($this->link, $cwd);
     
    219220    }
    220221    function is_readable($file) {
    221         //Get dir list, Check if the file is writable by the current user??
     222        //Get dir list, Check if the file is readable by the current user??
    222223        return true;
    223224    }
     
    239240    }
    240241    function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
    241         if( !@ftp_mkdir($this->link, $path) )
     242        if( !ftp_mkdir($this->link, $path) )
    242243            return false;
    243244        if( $chmod )
     
    250251    }
    251252    function rmdir($path, $recursive = false) {
    252         if( ! $recursive )
    253             return @ftp_rmdir($this->link, $path);
    254 
    255         //TODO: Recursive Directory delete, Have to delete files from the folder first.
    256         //$dir = $this->dirlist($path);
    257         //foreach($dir as $file)
    258 
     253        return $this->delete($path, $recursive);
    259254    }
    260255
    261256    function parselisting($line) {
    262         $is_windows = ($this->OS_remote == FTP_OS_Windows);
     257        static $is_windows;
     258        if ( is_null($is_windows) )
     259            $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
     260
    263261        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)) {
    264262            $b = array();
Note: See TracChangeset for help on using the changeset viewer.