Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41161 r42343  
    1818
    1919    /**
    20      *
    2120     * @param array $opt
    2221     */
     
    2625
    2726        // Check if possible to use ftp functions.
    28         if ( ! extension_loaded('ftp') ) {
    29             $this->errors->add('no_ftp_ext', __('The ftp PHP extension is not available'));
     27        if ( ! extension_loaded( 'ftp' ) ) {
     28            $this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) );
    3029            return;
    3130        }
     
    3332        // This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
    3433
    35         if ( ! defined('FS_TIMEOUT') )
    36             define('FS_TIMEOUT', 240);
    37 
    38         if ( empty($opt['port']) )
     34        if ( ! defined( 'FS_TIMEOUT' ) ) {
     35            define( 'FS_TIMEOUT', 240 );
     36        }
     37
     38        if ( empty( $opt['port'] ) ) {
    3939            $this->options['port'] = 21;
    40         else
     40        } else {
    4141            $this->options['port'] = $opt['port'];
    42 
    43         if ( empty($opt['hostname']) )
    44             $this->errors->add('empty_hostname', __('FTP hostname is required'));
    45         else
     42        }
     43
     44        if ( empty( $opt['hostname'] ) ) {
     45            $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) );
     46        } else {
    4647            $this->options['hostname'] = $opt['hostname'];
     48        }
    4749
    4850        // Check if the options provided are OK.
    49         if ( empty($opt['username']) )
    50             $this->errors->add('empty_username', __('FTP username is required'));
    51         else
     51        if ( empty( $opt['username'] ) ) {
     52            $this->errors->add( 'empty_username', __( 'FTP username is required' ) );
     53        } else {
    5254            $this->options['username'] = $opt['username'];
    53 
    54         if ( empty($opt['password']) )
    55             $this->errors->add('empty_password', __('FTP password is required'));
    56         else
     55        }
     56
     57        if ( empty( $opt['password'] ) ) {
     58            $this->errors->add( 'empty_password', __( 'FTP password is required' ) );
     59        } else {
    5760            $this->options['password'] = $opt['password'];
     61        }
    5862
    5963        $this->options['ssl'] = false;
    60         if ( isset($opt['connection_type']) && 'ftps' == $opt['connection_type'] )
     64        if ( isset( $opt['connection_type'] ) && 'ftps' == $opt['connection_type'] ) {
    6165            $this->options['ssl'] = true;
    62     }
    63 
    64     /**
    65      *
     66        }
     67    }
     68
     69    /**
    6670     * @return bool
    6771     */
    6872    public function connect() {
    69         if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
    70             $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
    71         else
    72             $this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
     73        if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
     74            $this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
     75        } else {
     76            $this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT );
     77        }
    7378
    7479        if ( ! $this->link ) {
    75             $this->errors->add( 'connect',
     80            $this->errors->add(
     81                'connect',
    7682                /* translators: %s: hostname:port */
    77                 sprintf( __( 'Failed to connect to FTP Server %s' ),
     83                sprintf(
     84                    __( 'Failed to connect to FTP Server %s' ),
    7885                    $this->options['hostname'] . ':' . $this->options['port']
    7986                )
     
    8289        }
    8390
    84         if ( ! @ftp_login( $this->link,$this->options['username'], $this->options['password'] ) ) {
    85             $this->errors->add( 'auth',
     91        if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) {
     92            $this->errors->add(
     93                'auth',
    8694                /* translators: %s: username */
    87                 sprintf( __( 'Username/Password incorrect for %s' ),
     95                sprintf(
     96                    __( 'Username/Password incorrect for %s' ),
    8897                    $this->options['username']
    8998                )
     
    94103        // Set the Connection to use Passive FTP
    95104        @ftp_pasv( $this->link, true );
    96         if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT )
    97             @ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT);
     105        if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
     106            @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
     107        }
    98108
    99109        return true;
     
    110120     */
    111121    public function get_contents( $file ) {
    112         $tempfile = wp_tempnam($file);
    113         $temp = fopen($tempfile, 'w+');
     122        $tempfile = wp_tempnam( $file );
     123        $temp     = fopen( $tempfile, 'w+' );
    114124
    115125        if ( ! $temp ) {
     
    127137        $contents = '';
    128138
    129         while ( ! feof($temp) )
    130             $contents .= fread($temp, 8192);
    131 
    132         fclose($temp);
    133         unlink($tempfile);
     139        while ( ! feof( $temp ) ) {
     140            $contents .= fread( $temp, 8192 );
     141        }
     142
     143        fclose( $temp );
     144        unlink( $tempfile );
    134145        return $contents;
    135146    }
    136147
    137148    /**
    138      *
    139149     * @param string $file
    140150     * @return array
    141151     */
    142     public function get_contents_array($file) {
    143         return explode("\n", $this->get_contents($file));
    144     }
    145 
    146     /**
    147      *
     152    public function get_contents_array( $file ) {
     153        return explode( "\n", $this->get_contents( $file ) );
     154    }
     155
     156    /**
    148157     * @param string $file
    149158     * @param string $contents
     
    151160     * @return bool
    152161     */
    153     public function put_contents($file, $contents, $mode = false ) {
    154         $tempfile = wp_tempnam($file);
    155         $temp = fopen( $tempfile, 'wb+' );
     162    public function put_contents( $file, $contents, $mode = false ) {
     163        $tempfile = wp_tempnam( $file );
     164        $temp     = fopen( $tempfile, 'wb+' );
    156165
    157166        if ( ! $temp ) {
     
    162171        mbstring_binary_safe_encoding();
    163172
    164         $data_length = strlen( $contents );
     173        $data_length   = strlen( $contents );
    165174        $bytes_written = fwrite( $temp, $contents );
    166175
     
    177186        $ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY );
    178187
    179         fclose($temp);
    180         unlink($tempfile);
    181 
    182         $this->chmod($file, $mode);
     188        fclose( $temp );
     189        unlink( $tempfile );
     190
     191        $this->chmod( $file, $mode );
    183192
    184193        return $ret;
     
    186195
    187196    /**
    188      *
    189197     * @return string
    190198     */
    191199    public function cwd() {
    192         $cwd = @ftp_pwd($this->link);
    193         if ( $cwd )
    194             $cwd = trailingslashit($cwd);
     200        $cwd = @ftp_pwd( $this->link );
     201        if ( $cwd ) {
     202            $cwd = trailingslashit( $cwd );
     203        }
    195204        return $cwd;
    196205    }
    197206
    198207    /**
    199      *
    200208     * @param string $dir
    201209     * @return bool
    202210     */
    203     public function chdir($dir) {
    204         return @ftp_chdir($this->link, $dir);
    205     }
    206 
    207     /**
    208      *
     211    public function chdir( $dir ) {
     212        return @ftp_chdir( $this->link, $dir );
     213    }
     214
     215    /**
    209216     * @param string $file
    210217     * @param int $mode
     
    212219     * @return bool
    213220     */
    214     public function chmod($file, $mode = false, $recursive = false) {
     221    public function chmod( $file, $mode = false, $recursive = false ) {
    215222        if ( ! $mode ) {
    216             if ( $this->is_file($file) )
     223            if ( $this->is_file( $file ) ) {
    217224                $mode = FS_CHMOD_FILE;
    218             elseif ( $this->is_dir($file) )
     225            } elseif ( $this->is_dir( $file ) ) {
    219226                $mode = FS_CHMOD_DIR;
    220             else
     227            } else {
    221228                return false;
     229            }
    222230        }
    223231
    224232        // chmod any sub-objects if recursive.
    225         if ( $recursive && $this->is_dir($file) ) {
    226             $filelist = $this->dirlist($file);
    227             foreach ( (array)$filelist as $filename => $filemeta )
    228                 $this->chmod($file . '/' . $filename, $mode, $recursive);
     233        if ( $recursive && $this->is_dir( $file ) ) {
     234            $filelist = $this->dirlist( $file );
     235            foreach ( (array) $filelist as $filename => $filemeta ) {
     236                $this->chmod( $file . '/' . $filename, $mode, $recursive );
     237            }
    229238        }
    230239
    231240        // chmod the file or directory
    232         if ( ! function_exists('ftp_chmod') )
    233             return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
    234         return (bool)@ftp_chmod($this->link, $mode, $file);
    235     }
    236 
    237     /**
    238      *
     241        if ( ! function_exists( 'ftp_chmod' ) ) {
     242            return (bool) @ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
     243        }
     244        return (bool) @ftp_chmod( $this->link, $mode, $file );
     245    }
     246
     247    /**
    239248     * @param string $file
    240249     * @return string
    241250     */
    242     public function owner($file) {
    243         $dir = $this->dirlist($file);
    244         return $dir[$file]['owner'];
    245     }
    246     /**
    247      *
     251    public function owner( $file ) {
     252        $dir = $this->dirlist( $file );
     253        return $dir[ $file ]['owner'];
     254    }
     255    /**
    248256     * @param string $file
    249257     * @return string
    250258     */
    251     public function getchmod($file) {
    252         $dir = $this->dirlist($file);
    253         return $dir[$file]['permsn'];
    254     }
    255 
    256     /**
    257      *
     259    public function getchmod( $file ) {
     260        $dir = $this->dirlist( $file );
     261        return $dir[ $file ]['permsn'];
     262    }
     263
     264    /**
    258265     * @param string $file
    259266     * @return string
    260267     */
    261     public function group($file) {
    262         $dir = $this->dirlist($file);
    263         return $dir[$file]['group'];
    264     }
    265 
    266     /**
    267      *
     268    public function group( $file ) {
     269        $dir = $this->dirlist( $file );
     270        return $dir[ $file ]['group'];
     271    }
     272
     273    /**
    268274     * @param string $source
    269275     * @param string $destination
     
    272278     * @return bool
    273279     */
    274     public function copy($source, $destination, $overwrite = false, $mode = false) {
    275         if ( ! $overwrite && $this->exists($destination) )
    276             return false;
    277         $content = $this->get_contents($source);
    278         if ( false === $content )
    279             return false;
    280         return $this->put_contents($destination, $content, $mode);
    281     }
    282 
    283     /**
    284      *
     280    public function copy( $source, $destination, $overwrite = false, $mode = false ) {
     281        if ( ! $overwrite && $this->exists( $destination ) ) {
     282            return false;
     283        }
     284        $content = $this->get_contents( $source );
     285        if ( false === $content ) {
     286            return false;
     287        }
     288        return $this->put_contents( $destination, $content, $mode );
     289    }
     290
     291    /**
    285292     * @param string $source
    286293     * @param string $destination
     
    288295     * @return bool
    289296     */
    290     public function move($source, $destination, $overwrite = false) {
    291         return ftp_rename($this->link, $source, $destination);
    292     }
    293 
    294     /**
    295      *
     297    public function move( $source, $destination, $overwrite = false ) {
     298        return ftp_rename( $this->link, $source, $destination );
     299    }
     300
     301    /**
    296302     * @param string $file
    297303     * @param bool $recursive
     
    299305     * @return bool
    300306     */
    301     public function delete($file, $recursive = false, $type = false) {
    302         if ( empty($file) )
    303             return false;
    304         if ( 'f' == $type || $this->is_file($file) )
    305             return @ftp_delete($this->link, $file);
    306         if ( !$recursive )
    307             return @ftp_rmdir($this->link, $file);
    308 
    309         $filelist = $this->dirlist( trailingslashit($file) );
    310         if ( !empty($filelist) )
    311             foreach ( $filelist as $delete_file )
    312                 $this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] );
    313         return @ftp_rmdir($this->link, $file);
    314     }
    315 
    316     /**
    317      *
    318      * @param string $file
    319      * @return bool
    320      */
    321     public function exists($file) {
    322         $list = @ftp_nlist($this->link, $file);
     307    public function delete( $file, $recursive = false, $type = false ) {
     308        if ( empty( $file ) ) {
     309            return false;
     310        }
     311        if ( 'f' == $type || $this->is_file( $file ) ) {
     312            return @ftp_delete( $this->link, $file );
     313        }
     314        if ( ! $recursive ) {
     315            return @ftp_rmdir( $this->link, $file );
     316        }
     317
     318        $filelist = $this->dirlist( trailingslashit( $file ) );
     319        if ( ! empty( $filelist ) ) {
     320            foreach ( $filelist as $delete_file ) {
     321                $this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] );
     322            }
     323        }
     324        return @ftp_rmdir( $this->link, $file );
     325    }
     326
     327    /**
     328     * @param string $file
     329     * @return bool
     330     */
     331    public function exists( $file ) {
     332        $list = @ftp_nlist( $this->link, $file );
    323333
    324334        if ( empty( $list ) && $this->is_dir( $file ) ) {
     
    326336        }
    327337
    328         return !empty($list); //empty list = no file, so invert.
    329     }
    330 
    331     /**
    332      *
    333      * @param string $file
    334      * @return bool
    335      */
    336     public function is_file($file) {
    337         return $this->exists($file) && !$this->is_dir($file);
    338     }
    339 
    340     /**
    341      *
     338        return ! empty( $list ); //empty list = no file, so invert.
     339    }
     340
     341    /**
     342     * @param string $file
     343     * @return bool
     344     */
     345    public function is_file( $file ) {
     346        return $this->exists( $file ) && ! $this->is_dir( $file );
     347    }
     348
     349    /**
    342350     * @param string $path
    343351     * @return bool
    344352     */
    345     public function is_dir($path) {
    346         $cwd = $this->cwd();
    347         $result = @ftp_chdir($this->link, trailingslashit($path) );
     353    public function is_dir( $path ) {
     354        $cwd    = $this->cwd();
     355        $result = @ftp_chdir( $this->link, trailingslashit( $path ) );
    348356        if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
    349             @ftp_chdir($this->link, $cwd);
     357            @ftp_chdir( $this->link, $cwd );
    350358            return true;
    351359        }
     
    354362
    355363    /**
    356      *
    357      * @param string $file
    358      * @return bool
    359      */
    360     public function is_readable($file) {
     364     * @param string $file
     365     * @return bool
     366     */
     367    public function is_readable( $file ) {
    361368        return true;
    362369    }
    363370
    364371    /**
    365      *
    366      * @param string $file
    367      * @return bool
    368      */
    369     public function is_writable($file) {
     372     * @param string $file
     373     * @return bool
     374     */
     375    public function is_writable( $file ) {
    370376        return true;
    371377    }
    372378
    373379    /**
    374      *
    375      * @param string $file
    376      * @return bool
    377      */
    378     public function atime($file) {
     380     * @param string $file
     381     * @return bool
     382     */
     383    public function atime( $file ) {
    379384        return false;
    380385    }
    381386
    382387    /**
    383      *
    384388     * @param string $file
    385389     * @return int
    386390     */
    387     public function mtime($file) {
    388         return ftp_mdtm($this->link, $file);
    389     }
    390 
    391     /**
    392      *
     391    public function mtime( $file ) {
     392        return ftp_mdtm( $this->link, $file );
     393    }
     394
     395    /**
    393396     * @param string $file
    394397     * @return int
    395398     */
    396     public function size($file) {
    397         return ftp_size($this->link, $file);
    398     }
    399 
    400     /**
    401      *
    402      * @param string $file
    403      * @return bool
    404      */
    405     public function touch($file, $time = 0, $atime = 0) {
     399    public function size( $file ) {
     400        return ftp_size( $this->link, $file );
     401    }
     402
     403    /**
     404     * @param string $file
     405     * @return bool
     406     */
     407    public function touch( $file, $time = 0, $atime = 0 ) {
    406408        return false;
    407409    }
    408410
    409411    /**
    410      *
    411412     * @param string $path
    412413     * @param mixed $chmod
     
    415416     * @return bool
    416417     */
    417     public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
    418         $path = untrailingslashit($path);
    419         if ( empty($path) )
    420             return false;
    421 
    422         if ( !@ftp_mkdir($this->link, $path) )
    423             return false;
    424         $this->chmod($path, $chmod);
     418    public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
     419        $path = untrailingslashit( $path );
     420        if ( empty( $path ) ) {
     421            return false;
     422        }
     423
     424        if ( ! @ftp_mkdir( $this->link, $path ) ) {
     425            return false;
     426        }
     427        $this->chmod( $path, $chmod );
    425428        return true;
    426429    }
    427430
    428431    /**
    429      *
    430432     * @param string $path
    431433     * @param bool $recursive
    432434     * @return bool
    433435     */
    434     public function rmdir($path, $recursive = false) {
    435         return $this->delete($path, $recursive);
    436     }
    437 
    438     /**
    439      *
     436    public function rmdir( $path, $recursive = false ) {
     437        return $this->delete( $path, $recursive );
     438    }
     439
     440    /**
    440441     * @staticvar bool $is_windows
    441442     * @param string $line
    442443     * @return array
    443444     */
    444     public function parselisting($line) {
     445    public function parselisting( $line ) {
    445446        static $is_windows = null;
    446         if ( is_null($is_windows) )
    447             $is_windows = stripos( ftp_systype($this->link), 'win') !== false;
    448 
    449         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) ) {
     447        if ( is_null( $is_windows ) ) {
     448            $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
     449        }
     450
     451        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 ) ) {
    450452            $b = array();
    451             if ( $lucifer[3] < 70 )
    452                 $lucifer[3] +=2000;
    453             else
     453            if ( $lucifer[3] < 70 ) {
     454                $lucifer[3] += 2000;
     455            } else {
    454456                $lucifer[3] += 1900; // 4digit year fix
    455             $b['isdir'] = ( $lucifer[7] == '<DIR>');
    456             if ( $b['isdir'] )
     457            }
     458            $b['isdir'] = ( $lucifer[7] == '<DIR>' );
     459            if ( $b['isdir'] ) {
    457460                $b['type'] = 'd';
    458             else
     461            } else {
    459462                $b['type'] = 'f';
    460             $b['size'] = $lucifer[7];
    461             $b['month'] = $lucifer[1];
    462             $b['day'] = $lucifer[2];
    463             $b['year'] = $lucifer[3];
    464             $b['hour'] = $lucifer[4];
     463            }
     464            $b['size']   = $lucifer[7];
     465            $b['month']  = $lucifer[1];
     466            $b['day']    = $lucifer[2];
     467            $b['year']   = $lucifer[3];
     468            $b['hour']   = $lucifer[4];
    465469            $b['minute'] = $lucifer[5];
    466             $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
    467             $b['am/pm'] = $lucifer[6];
    468             $b['name'] = $lucifer[8];
    469         } elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
     470            $b['time']   = @mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) == 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] );
     471            $b['am/pm']  = $lucifer[6];
     472            $b['name']   = $lucifer[8];
     473        } elseif ( ! $is_windows && $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ) ) {
    470474            //echo $line."\n";
    471             $lcount = count($lucifer);
    472             if ( $lcount < 8 )
     475            $lcount = count( $lucifer );
     476            if ( $lcount < 8 ) {
    473477                return '';
    474             $b = array();
    475             $b['isdir'] = $lucifer[0]{0} === 'd';
     478            }
     479            $b           = array();
     480            $b['isdir']  = $lucifer[0]{0} === 'd';
    476481            $b['islink'] = $lucifer[0]{0} === 'l';
    477             if ( $b['isdir'] )
     482            if ( $b['isdir'] ) {
    478483                $b['type'] = 'd';
    479             elseif ( $b['islink'] )
     484            } elseif ( $b['islink'] ) {
    480485                $b['type'] = 'l';
    481             else
     486            } else {
    482487                $b['type'] = 'f';
    483             $b['perms'] = $lucifer[0];
     488            }
     489            $b['perms']  = $lucifer[0];
    484490            $b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
    485491            $b['number'] = $lucifer[1];
    486             $b['owner'] = $lucifer[2];
    487             $b['group'] = $lucifer[3];
    488             $b['size'] = $lucifer[4];
     492            $b['owner']  = $lucifer[2];
     493            $b['group']  = $lucifer[3];
     494            $b['size']   = $lucifer[4];
    489495            if ( $lcount == 8 ) {
    490                 sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
    491                 sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
    492                 $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
     496                sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
     497                sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
     498                $b['time'] = @mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
    493499                $b['name'] = $lucifer[7];
    494500            } else {
    495501                $b['month'] = $lucifer[5];
    496                 $b['day'] = $lucifer[6];
    497                 if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
    498                     $b['year'] = date("Y");
    499                     $b['hour'] = $l2[1];
     502                $b['day']   = $lucifer[6];
     503                if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
     504                    $b['year']   = date( 'Y' );
     505                    $b['hour']   = $l2[1];
    500506                    $b['minute'] = $l2[2];
    501507                } else {
    502                     $b['year'] = $lucifer[7];
    503                     $b['hour'] = 0;
     508                    $b['year']   = $lucifer[7];
     509                    $b['hour']   = 0;
    504510                    $b['minute'] = 0;
    505511                }
    506                 $b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );
     512                $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
    507513                $b['name'] = $lucifer[8];
    508514            }
     
    518524
    519525    /**
    520      *
    521526     * @param string $path
    522527     * @param bool $include_hidden
     
    524529     * @return bool|array
    525530     */
    526     public function dirlist($path = '.', $include_hidden = true, $recursive = false) {
    527         if ( $this->is_file($path) ) {
    528             $limit_file = basename($path);
    529             $path = dirname($path) . '/';
     531    public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) {
     532        if ( $this->is_file( $path ) ) {
     533            $limit_file = basename( $path );
     534            $path       = dirname( $path ) . '/';
    530535        } else {
    531536            $limit_file = false;
    532537        }
    533538
    534         $pwd = @ftp_pwd($this->link);
    535         if ( ! @ftp_chdir($this->link, $path) ) // Cant change to folder = folder doesn't exist
    536             return false;
    537         $list = @ftp_rawlist($this->link, '-a', false);
    538         @ftp_chdir($this->link, $pwd);
    539 
    540         if ( empty($list) ) // Empty array = non-existent folder (real folder will show . at least)
    541             return false;
     539        $pwd = @ftp_pwd( $this->link );
     540        if ( ! @ftp_chdir( $this->link, $path ) ) { // Cant change to folder = folder doesn't exist
     541            return false;
     542        }
     543        $list = @ftp_rawlist( $this->link, '-a', false );
     544        @ftp_chdir( $this->link, $pwd );
     545
     546        if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least)
     547            return false;
     548        }
    542549
    543550        $dirlist = array();
    544551        foreach ( $list as $k => $v ) {
    545             $entry = $this->parselisting($v);
    546             if ( empty($entry) )
     552            $entry = $this->parselisting( $v );
     553            if ( empty( $entry ) ) {
    547554                continue;
    548 
    549             if ( '.' == $entry['name'] || '..' == $entry['name'] )
     555            }
     556
     557            if ( '.' == $entry['name'] || '..' == $entry['name'] ) {
    550558                continue;
    551 
    552             if ( ! $include_hidden && '.' == $entry['name'][0] )
     559            }
     560
     561            if ( ! $include_hidden && '.' == $entry['name'][0] ) {
    553562                continue;
    554 
    555             if ( $limit_file && $entry['name'] != $limit_file)
     563            }
     564
     565            if ( $limit_file && $entry['name'] != $limit_file ) {
    556566                continue;
     567            }
    557568
    558569            $dirlist[ $entry['name'] ] = $entry;
     
    560571
    561572        $ret = array();
    562         foreach ( (array)$dirlist as $struc ) {
     573        foreach ( (array) $dirlist as $struc ) {
    563574            if ( 'd' == $struc['type'] ) {
    564                 if ( $recursive )
    565                     $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
    566                 else
     575                if ( $recursive ) {
     576                    $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
     577                } else {
    567578                    $struc['files'] = array();
     579                }
    568580            }
    569581
     
    576588     */
    577589    public function __destruct() {
    578         if ( $this->link )
    579             ftp_close($this->link);
     590        if ( $this->link ) {
     591            ftp_close( $this->link );
     592        }
    580593    }
    581594}
Note: See TracChangeset for help on using the changeset viewer.