Make WordPress Core

Ticket #16938: 16938.patch

File 16938.patch, 1.4 KB (added by hakre, 14 years ago)

going through

  • wp-admin/includes/file.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk bare
     
    126126 * @return bool|array False on failure, Else array of files
    127127 */
    128128function list_files( $folder = '', $levels = 100 ) {
    129         if ( empty($folder) )
     129        if ( empty($folder) || empty($levels) )
    130130                return false;
    131131
    132         if ( ! $levels )
    133                 return false;
    134 
    135132        $files = array();
    136         if ( $dir = @opendir( $folder ) ) {
    137                 while (($file = readdir( $dir ) ) !== false ) {
    138                         if ( in_array($file, array('.', '..') ) )
     133        if ( $handle = @opendir( $folder ) ) {
     134                while ( $file = readdir( $handle ) ) {
     135                        if ( $file === '.' || $file === '..' )
    139136                                continue;
    140                         if ( is_dir( $folder . '/' . $file ) ) {
    141                                 $files2 = list_files( $folder . '/' . $file, $levels - 1);
    142                                 if ( $files2 )
    143                                         $files = array_merge($files, $files2 );
    144                                 else
    145                                         $files[] = $folder . '/' . $file . '/';
    146                         } else {
    147                                 $files[] = $folder . '/' . $file;
     137                        $path = $folder . '/' . $file;
     138                        if ( is_dir( $path ) ) {
     139                                if ( $files_subdir = list_files( $path, $levels - 1) ) {
     140                                        $files = array_merge( $files, $files_subdir );
     141                                        continue;
     142                                }
     143                                $path .= '/';
    148144                        }
     145                        $files[] = $path;
    149146                }
     147                @closedir( $handle );
    150148        }
    151         @closedir( $dir );
    152149        return $files;
    153150}
    154151