Ticket #6531: patch-recursive-editors.diff
File patch-recursive-editors.diff, 10.5 KB (added by , 14 years ago) |
---|
-
wp-includes/theme.php
345 345 $stylesheet_files = array(); 346 346 $template_files = array(); 347 347 348 $stylesheet_dir = @ dir("$theme_root/$stylesheet"); 349 if ( $stylesheet_dir ) { 350 while ( ($file = $stylesheet_dir->read()) !== false ) { 351 if ( !preg_match('|^\.+$|', $file) ) { 352 if ( preg_match('|\.css$|', $file) ) 353 $stylesheet_files[] = "$theme_root/$stylesheet/$file"; 354 elseif ( preg_match('|\.php$|', $file) ) 355 $template_files[] = "$theme_root/$stylesheet/$file"; 356 } 357 } 358 @ $stylesheet_dir->close(); 359 } 348 search_for_theme_files_r("$theme_root/$stylesheet", 'both', $stylesheet_files, $template_files); 349 search_for_theme_files_r("$template_directory", 'script', $stylesheet_files, $template_files); 360 350 361 $template_dir = @ dir("$template_directory");362 if ( $template_dir ) {363 while ( ($file = $template_dir->read()) !== false ) {364 if ( preg_match('|^\.+$|', $file) )365 continue;366 if ( preg_match('|\.php$|', $file) ) {367 $template_files[] = "$template_directory/$file";368 } elseif ( is_dir("$template_directory/$file") ) {369 $template_subdir = @ dir("$template_directory/$file");370 if ( !$template_subdir )371 continue;372 while ( ($subfile = $template_subdir->read()) !== false ) {373 if ( preg_match('|^\.+$|', $subfile) )374 continue;375 if ( preg_match('|\.php$|', $subfile) )376 $template_files[] = "$template_directory/$file/$subfile";377 }378 @ $template_subdir->close();379 }380 }381 @ $template_dir->close();382 }383 384 351 //Make unique and remove duplicates when stylesheet and template are the same i.e. most themes 385 352 $template_files = array_unique($template_files); 386 353 $stylesheet_files = array_unique($stylesheet_files); … … 465 432 } 466 433 467 434 /** 435 * Search recursively for theme files 436 * 437 * @global array $__search_for_theme_files_parsed_directories To avoid recursion 438 * 439 * @param string Path to the current directory to search 440 * @param string File types to add ('css', 'script' or 'both') 441 * @param array Array to store stylesheet (.css) files 442 * @param array Array to store template (.php|.js) files 443 */ 444 $__search_for_theme_files_parsed_directories = array(); 445 446 function search_for_theme_files_r( $path, $file_types, array &$stylesheet_files, array &$template_files ) { 447 global $__search_for_theme_files_parsed_directories; 448 449 // Avoiding recursion 450 $rp = realpath($path); 451 if (in_array($rp, $__search_for_theme_files_parsed_directories)) 452 return; 453 $__search_for_theme_files_parsed_directories[] = $rp; 454 455 // Looking for files 456 $dir = @dir($path); 457 if ($dir) { 458 while ( ($file = $dir->read()) !== false ) { 459 if ( !preg_match('|^\.+$|', $file) ) { 460 $fn = "{$path}/{$file}"; 461 if ( !is_readable( $fn ) ) 462 continue; 463 if ( is_dir( $fn ) ) 464 search_for_theme_files_r( $fn, $file_types, $stylesheet_files, $template_files ); 465 else if ( preg_match('|\.css$|', $file) && ( 'css' == $file_types || 'both' == $file_types ) ) 466 $stylesheet_files[] = $fn; 467 elseif ( preg_match('#\.(php|js)$#', $file) && ( 'script' == $file_types || 'both' == $file_types ) ) 468 $template_files[] = $fn; 469 } 470 } 471 @$dir->close(); 472 } 473 } 474 475 /** 468 476 * Retrieve theme roots. 469 477 * 470 478 * @since 2.9.0 -
wp-includes/functions.php
6 6 */ 7 7 8 8 /** 9 * Sort files by path 10 * 11 * Please refer to http://www.php.net/manual/en/function.usort.php for further information on the parameters 12 * 13 * @param mixed First item to compare 14 * @param midex Second item to compare 15 * @return int an integer based on the comparison result 16 */ 17 function sort_files_by_path($a, $b) { 18 $dirA = dirname( $a ); 19 if ( '.' != $dirA ) 20 $dirA .= '/'; 21 $dirB = dirname( $b ); 22 if ( '.' != $dirB ) 23 $dirB .= '/'; 24 $countA = substr_count( $dirA, DIRECTORY_SEPARATOR ); 25 $countB = substr_count( $dirB, DIRECTORY_SEPARATOR ); 26 if ( $countA == $countB ) 27 return strcmp($a, $b); 28 else 29 return $countA - $countB; 30 } 31 32 /** 9 33 * Converts MySQL DATETIME field to user specified date format. 10 34 * 11 35 * If $dateformatstring has 'G' value, then gmmktime() function will be used to -
wp-admin/includes/plugin.php
159 159 * 160 160 * @since 2.8.0 161 161 * 162 * @global $plugins 163 * 162 164 * @param string $plugin Plugin ID 163 165 * @return array List of files relative to the plugin root. 164 166 */ 165 167 function get_plugin_files($plugin) { 166 168 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; 167 $dir = dirname($plugin_file); 168 $plugin_files = array($plugin); 169 if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) { 170 $plugins_dir = @ opendir( $dir ); 171 if ( $plugins_dir ) { 172 while (($file = readdir( $plugins_dir ) ) !== false ) { 173 if ( substr($file, 0, 1) == '.' ) 174 continue; 175 if ( is_dir( $dir . '/' . $file ) ) { 176 $plugins_subdir = @ opendir( $dir . '/' . $file ); 177 if ( $plugins_subdir ) { 178 while (($subfile = readdir( $plugins_subdir ) ) !== false ) { 179 if ( substr($subfile, 0, 1) == '.' ) 180 continue; 181 $plugin_files[] = plugin_basename("$dir/$file/$subfile"); 182 } 183 @closedir( $plugins_subdir ); 184 } 185 } else { 186 if ( plugin_basename("$dir/$file") != $plugin ) 187 $plugin_files[] = plugin_basename("$dir/$file"); 188 } 169 $plugin_keys = array_keys( $GLOBALS['plugins'] ); 170 171 if ( in_array($plugin, $plugin_keys) ) { 172 $dir = dirname( $plugin_file ); 173 $plugin_files = array($plugin); 174 if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) { 175 search_for_plugin_files_r($dir, $plugin_files); 176 $plugin_files = array_unique($plugin_files); 177 } 178 } 179 else { 180 foreach ($plugin_keys as $p) { 181 $pdir = dirname( WP_PLUGIN_DIR . '/' . $plugin ); 182 if ( substr( $plugin_file, 0, strlen( $pdir ) ) == $pdir) { 183 var_dump($p); 184 return get_plugin_files( $p ); 189 185 } 190 @closedir( $plugins_dir );191 186 } 192 187 } 193 188 … … 277 272 } 278 273 279 274 /** 275 * Search recursively for plugin files 276 * 277 * @global array $__search_for_plugin_files_parsed_directories To avoid recursion 278 * 279 * @param string Path to the current directory to search 280 * @param array Array to store files 281 */ 282 $__search_for_plugin_files_parsed_directories = array(); 283 284 function search_for_plugin_files_r( $path, array &$files ) { 285 global $__search_for_plugin_files_parsed_directories; 286 287 // Avoiding recursion 288 $rp = realpath($path); 289 if (in_array($rp, $__search_for_plugin_files_parsed_directories)) 290 return; 291 $__search_for_plugin_files_parsed_directories[] = $rp; 292 293 // Looking for files 294 $dir = @dir($path); 295 if ($dir) { 296 while ( ($file = $dir->read()) !== false ) { 297 if ( !preg_match('|^\.+$|', $file) ) { 298 $fn = "{$path}/{$file}"; 299 if ( !is_readable( $fn ) ) 300 continue; 301 if ( is_dir( $fn ) ) 302 search_for_plugin_files_r( $fn, $files ); 303 elseif ( preg_match('#\.(php|js)$#', $file) ) 304 $files[] = plugin_basename( $fn ); 305 } 306 } 307 @$dir->close(); 308 } 309 } 310 311 /** 280 312 * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data. 281 313 * 282 314 * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins). -
wp-admin/theme-editor.php
183 183 if ( $is_child_theme && strpos( $template_file, trailingslashit( $template_dir ) ) === 0 ) 184 184 continue; 185 185 186 $description = trim( get_file_description($template_file) ); 187 $template_show = basename($template_file); 186 if ( dirname( $template_file ) == $template_dir ) 187 $description = trim( get_file_description($template_file) ); 188 else 189 $description = trim( str_replace( "{$template_dir}/", '', $template_file ) ); 190 $template_show = str_replace("{$template_dir}/", '', $template_file); 188 191 $filedesc = ( $description != $template_file ) ? "$description<br /><span class='nonessential'>($template_show)</span>" : "$description"; 189 192 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($template_show)</span></span>" : $filedesc; 190 193 $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc ); 191 194 } 192 ksort( $template_mapping);195 uksort( $template_mapping, 'sort_files_by_path' ); 193 196 while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) : 194 197 ?> 195 198 <li><a href="theme-editor.php?file=<?php echo urlencode( $template_file ) ?>&theme=<?php echo urlencode( $theme ) ?>&dir=theme"><?php echo $filedesc ?></a></li> … … 205 208 if ( $is_child_theme && strpos( $style_file, trailingslashit( $template_dir ) ) === 0 ) 206 209 continue; 207 210 208 $description = trim( get_file_description($style_file) ); 209 $style_show = basename($style_file); 211 if ( dirname( $style_file ) == $template_dir ) 212 $description = trim( get_file_description($style_file) ); 213 else 214 $description = trim( str_replace( "{$stylesheet_dir}/", '', $style_file ) ); 215 $style_show = str_replace("{$stylesheet_dir}/", '', $style_file); 210 216 $filedesc = ( $description != $style_file ) ? "$description<br /><span class='nonessential'>($style_show)</span>" : "$description"; 211 217 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($style_show)</span></span>" : $filedesc; 212 218 $template_mapping[ $description ] = array( _get_template_edit_filename($style_file, $stylesheet_dir), $filedesc ); 213 219 } 214 ksort( $template_mapping);220 uksort( $template_mapping, 'sort_files_by_path' ); 215 221 while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) : 216 222 ?> 217 223 <li><a href="theme-editor.php?file=<?php echo urlencode( $style_file ) ?>&theme=<?php echo urlencode($theme) ?>&dir=style"><?php echo $filedesc ?></a></li> -
wp-admin/plugin-editor.php
203 203 204 204 <ul> 205 205 <?php 206 usort($plugin_files, 'sort_files_by_path'); 206 207 foreach ( $plugin_files as $plugin_file ) : 207 208 // Get the extension of the file 208 209 if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) {