### Eclipse Workspace Patch 1.0
#P wordpress-trunk bare
|
|
|
126 | 126 | * @return bool|array False on failure, Else array of files |
127 | 127 | */ |
128 | 128 | function list_files( $folder = '', $levels = 100 ) { |
129 | | if ( empty($folder) ) |
| 129 | if ( empty($folder) || empty($levels) ) |
130 | 130 | return false; |
131 | 131 | |
132 | | if ( ! $levels ) |
133 | | return false; |
134 | | |
135 | 132 | $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 === '..' ) |
139 | 136 | 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 .= '/'; |
148 | 144 | } |
| 145 | $files[] = $path; |
149 | 146 | } |
| 147 | @closedir( $handle ); |
150 | 148 | } |
151 | | @closedir( $dir ); |
152 | 149 | return $files; |
153 | 150 | } |
154 | 151 | |