Make WordPress Core

Ticket #27201: 27201.patch

File 27201.patch, 5.7 KB (added by bravokeyl, 11 years ago)

different approach instead of comparing to 'themes' directory.

  • includes/file.php

     
    5353 * @uses _cleanup_header_comment
    5454 * @uses $wp_file_descriptions
    5555 * @param string $file Filesystem path or filename
    56  * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist
     56 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist,
     57 * appends 'Page Template' to basename of $file if the file is a page template
    5758 */
    5859function get_file_description( $file ) {
    59         global $wp_file_descriptions;
    60 
    61         if ( isset( $wp_file_descriptions[basename( $file )] ) ) {
    62                 return $wp_file_descriptions[basename( $file )];
     60        global $wp_file_descriptions , $allowed_files;
     61        $relative_pathinfo = pathinfo( $file );
     62        $file_path = $allowed_files[ $file ];
     63        if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' == $relative_pathinfo['dirname'] ) {
     64                return $wp_file_descriptions[ basename( $file ) ];
    6365        }
    64         elseif ( file_exists( $file ) && is_file( $file ) ) {
    65                 $template_data = implode( '', file( $file ) );
     66        elseif ( file_exists( $file_path ) && is_file( $file_path) ) {
     67                $template_data = implode( '', file( $file_path ) );
    6668                if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ))
    6769                        return sprintf( __( '%s Page Template' ), _cleanup_header_comment($name[1]) );
    6870        }
     
    11091111</form>
    11101112<?php
    11111113        return false;
    1112 }
     1114}
     1115 No newline at end of file
  • theme-editor.php

     
    1414        exit();
    1515}
    1616
    17 if ( !current_user_can('edit_themes') )
     17if ( ! current_user_can('edit_themes') ) {
    1818        wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this site.').'</p>');
     19}
    1920
    2021$title = __("Edit Themes");
    2122$parent_file = 'themes.php';
     
    2425'id'            => 'overview',
    2526'title'         => __('Overview'),
    2627'content'       =>
    27         '<p>' . __('You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.') . '</p>
    28         <p>' . __('Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of all the template files. Clicking once on any file name causes the file to appear in the large Editor box.') . '</p>
     28        '<p>' . __('You can use the Theme Editor to edit the individual CSS and PHP files which make up part of your theme.') . '</p>
     29        <p>' . __('Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list of php files with one level deep and css files of flat level appears . Clicking once on any file name causes the file to appear in the large Editor box.') . '</p>
    2930        <p>' . __('For PHP files, you can use the Documentation dropdown to select from functions recognized in that file. Look Up takes you to a web page with reference material about that particular function.') . '</p>
    3031        <p id="newcontent-description">' . __('In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key.') . '</p>
    3132        <p>' . __('After typing in your edits, click Update File.') . '</p>
     
    4546
    4647wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) );
    4748
    48 if ( $theme )
     49if ( $theme ) {
    4950        $stylesheet = $theme;
    50 else
     51}
     52else {
    5153        $stylesheet = get_stylesheet();
     54}
    5255
    5356$theme = wp_get_theme( $stylesheet );
    5457
    55 if ( ! $theme->exists() )
     58if ( ! $theme->exists() ) {
    5659        wp_die( __( 'The requested theme does not exist.' ) );
     60}
    5761
    58 if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() )
     62if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) {
    5963        wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() );
     64}
    6065
    6166$allowed_files = $theme->get_files( 'php', 1 );
    6267$has_templates = ! empty( $allowed_files );
     
    100105
    101106        update_recently_edited( $file );
    102107
    103         if ( ! is_file( $file ) )
     108        if ( ! is_file( $file ) ) {
    104109                $error = true;
     110        }
    105111
    106112        $content = '';
    107113        if ( ! $error && filesize( $file ) > 0 ) {
     
    127133 <div id="message" class="updated"><p><?php _e( 'File edited successfully.' ) ?></p></div>
    128134<?php endif;
    129135
    130 $description = get_file_description( $file );
     136$description = get_file_description( $relative_file );
    131137$file_show = array_search( $file, array_filter( $allowed_files ) );
    132138if ( $description != $file_show )
    133139        $description .= ' <span>(' . $file_show . ')</span>';
     
    176182        endif;
    177183
    178184        foreach ( $allowed_files as $filename => $absolute_filename ) :
    179                 if ( 'style.css' == $filename )
     185                if ( 'style.css' == $filename ) {
    180186                        echo "\t</ul>\n\t<h3>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h3>\n\t<ul>\n";
     187                }
    181188
    182                 $file_description = get_file_description( $absolute_filename );
    183                 if ( $file_description != basename( $filename ) )
     189                $file_description = get_file_description( $filename );
     190                if ( $filename != basename($absolute_filename) || $file_description !== $filename ) {
    184191                        $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>';
    185 
    186                 if ( $absolute_filename == $file )
     192                }
     193                if ( $absolute_filename == $file ) {
    187194                        $file_description = '<span class="highlight">' . $file_description . '</span>';
     195                }
    188196?>
    189197                <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&amp;theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li>
    190198<?php
     
    242250break;
    243251}
    244252
    245 include(ABSPATH . 'wp-admin/admin-footer.php' );
     253include(ABSPATH . 'wp-admin/admin-footer.php' );
     254 No newline at end of file