diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 447b2d678..9ff24384c 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -65,7 +65,7 @@ function get_file_description( $file ) { return sprintf( __( '%s Page Template' ), _cleanup_header_comment($name[1]) ); } - return basename( $file ); + return trim( basename( $file ) ); } /** diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php index 71dbd1275..0258e3af3 100644 --- a/wp-admin/theme-editor.php +++ b/wp-admin/theme-editor.php @@ -42,80 +42,73 @@ get_current_screen()->set_help_sidebar( '
' . __('Support Forums') . '
' ); -wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme', 'dir')); +wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) ); -$themes = get_themes(); +if ( $theme ) + $stylesheet = $theme; +else + $stylesheet = get_stylesheet(); -if (empty($theme)) { - $theme = get_current_theme(); +$theme = wp_get_theme( $stylesheet ); + +if ( ! $theme ) + wp_die( __( 'The requested theme does not exist.' ) ); + +$allowed_files = $theme->get_files( 'php', 1 ); +$style_files = $theme->get_files( 'css' ); +if ( isset( $style_files['style.css'] ) ) { + $allowed_files['style.css'] = $style_files['style.css']; + unset( $style_files['style.css'] ); } else { - $theme = stripslashes($theme); + $style_files['style.css'] = false; } - -if ( ! isset($themes[$theme]) ) - wp_die(__('The requested theme does not exist.')); - -$allowed_files = array_merge( $themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files'] ); +$allowed_files += $style_files; if ( empty( $file ) ) { - if ( false !== array_search( $themes[$theme]['Stylesheet Dir'] . '/style.css', $allowed_files ) ) - $file = $themes[$theme]['Stylesheet Dir'] . '/style.css'; - else - $file = $allowed_files[0]; -} else { - $file = stripslashes($file); - if ( 'theme' == $dir ) { - $file = dirname(dirname($themes[$theme]['Template Dir'])) . $file ; - } else if ( 'style' == $dir) { - $file = dirname(dirname($themes[$theme]['Stylesheet Dir'])) . $file ; + if ( ! empty( $allowed_files['style.css'] ) ) { + $relative_file = 'style.css'; + $file = $allowed_files['style.css']; + } else { + $relative_file = key( $allowed_files ); + $file = current( $allowed_files ); } +} else { + $relative_file = stripslashes( $file ); + $file = $theme->get_stylesheet_directory() . '/' . $relative_file; } -validate_file_to_edit($file, $allowed_files); -$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; -$file_show = basename( $file ); - -switch($action) { +validate_file_to_edit( $file, $allowed_files ); +$scrollto = isset( $_REQUEST['scrollto'] ) ? (int) $_REQUEST['scrollto'] : 0; +switch( $action ) { case 'update': - - check_admin_referer('edit-theme_' . $file . $theme); - - $newcontent = stripslashes($_POST['newcontent']); - $theme = urlencode($theme); - if (is_writeable($file)) { + check_admin_referer( 'edit-theme_' . $file . $stylesheet ); + $newcontent = stripslashes( $_POST['newcontent'] ); + $location = 'theme-editor.php?file=' . urlencode( $relative_file ) . '&theme=' . urlencode( $stylesheet ) . '&scrollto=' . $scrollto; + if ( is_writeable( $file ) ) { //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable - $f = fopen($file, 'w+'); - if ($f !== false) { - fwrite($f, $newcontent); - fclose($f); - $location = "theme-editor.php?file=$file&theme=$theme&a=te&scrollto=$scrollto"; - } else { - $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto"; + $f = fopen( $file, 'w+' ); + if ( $f !== false ) { + fwrite( $f, $newcontent ); + fclose( $f ); + $location .= '&updated=true'; } - } else { - $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto"; } - - $location = wp_kses_no_null($location); - $strip = array('%0d', '%0a', '%0D', '%0A'); - $location = _deep_replace($strip, $location); - header("Location: $location"); - exit(); - + wp_redirect( $location ); + exit; break; default: - require_once(ABSPATH . 'wp-admin/admin-header.php'); + require_once( ABSPATH . 'wp-admin/admin-header.php' ); - update_recently_edited($file); + update_recently_edited( $file ); - if ( !is_file($file) ) - $error = 1; + if ( ! is_file( $file ) ) + $error = true; $content = ''; - if ( !$error && filesize($file) > 0 ) { + if ( ! $error && filesize( $file ) > 0 ) { $f = fopen($file, 'r'); $content = fread($f, filesize($file)); @@ -134,14 +127,14 @@ default: } ?> - -get_template()) . '">' . $theme->parent()->display('Name') . '' ); ?>
' . __('Oops, no such file exists! Double check the name and try again, merci.') . '