Changes in trunk/wp-admin/theme-editor.php [19528:20844]
- File:
-
- 1 edited
-
trunk/wp-admin/theme-editor.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/theme-editor.php
r19528 r20844 43 43 ); 44 44 45 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme', 'dir')); 46 47 $themes = get_themes(); 48 49 if (empty($theme)) { 50 $theme = get_current_theme(); 45 wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) ); 46 47 if ( $theme ) 48 $stylesheet = urldecode( $theme ); 49 else 50 $stylesheet = get_stylesheet(); 51 52 $theme = wp_get_theme( $stylesheet ); 53 54 if ( ! $theme->exists() ) 55 wp_die( __( 'The requested theme does not exist.' ) ); 56 57 if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) 58 wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() ); 59 60 $allowed_files = $theme->get_files( 'php', 1 ); 61 $has_templates = ! empty( $allowed_files ); 62 $style_files = $theme->get_files( 'css' ); 63 $allowed_files['style.css'] = $style_files['style.css']; 64 $allowed_files += $style_files; 65 66 if ( empty( $file ) ) { 67 $relative_file = 'style.css'; 68 $file = $allowed_files['style.css']; 51 69 } else { 52 $theme = stripslashes($theme); 53 } 54 55 if ( ! isset($themes[$theme]) ) 56 wp_die(__('The requested theme does not exist.')); 57 58 $allowed_files = array_merge( $themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files'] ); 59 60 if ( empty( $file ) ) { 61 if ( false !== array_search( $themes[$theme]['Stylesheet Dir'] . '/style.css', $allowed_files ) ) 62 $file = $themes[$theme]['Stylesheet Dir'] . '/style.css'; 63 else 64 $file = $allowed_files[0]; 65 } else { 66 $file = stripslashes($file); 67 if ( 'theme' == $dir ) { 68 $file = dirname(dirname($themes[$theme]['Template Dir'])) . $file ; 69 } else if ( 'style' == $dir) { 70 $file = dirname(dirname($themes[$theme]['Stylesheet Dir'])) . $file ; 70 $relative_file = urldecode( stripslashes( $file ) ); 71 $file = $theme->get_stylesheet_directory() . '/' . $relative_file; 72 } 73 74 validate_file_to_edit( $file, $allowed_files ); 75 $scrollto = isset( $_REQUEST['scrollto'] ) ? (int) $_REQUEST['scrollto'] : 0; 76 77 switch( $action ) { 78 case 'update': 79 check_admin_referer( 'edit-theme_' . $file . $stylesheet ); 80 $newcontent = stripslashes( $_POST['newcontent'] ); 81 $location = 'theme-editor.php?file=' . urlencode( $relative_file ) . '&theme=' . urlencode( $stylesheet ) . '&scrollto=' . $scrollto; 82 if ( is_writeable( $file ) ) { 83 //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable 84 $f = fopen( $file, 'w+' ); 85 if ( $f !== false ) { 86 fwrite( $f, $newcontent ); 87 fclose( $f ); 88 $location .= '&updated=true'; 89 $theme->cache_delete(); 90 } 71 91 } 72 } 73 74 validate_file_to_edit($file, $allowed_files); 75 $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; 76 $file_show = basename( $file ); 77 78 switch($action) { 79 80 case 'update': 81 82 check_admin_referer('edit-theme_' . $file . $theme); 83 84 $newcontent = stripslashes($_POST['newcontent']); 85 $theme = urlencode($theme); 86 if (is_writeable($file)) { 87 //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable 88 $f = fopen($file, 'w+'); 89 if ($f !== FALSE) { 90 fwrite($f, $newcontent); 91 fclose($f); 92 $location = "theme-editor.php?file=$file&theme=$theme&a=te&scrollto=$scrollto"; 93 } else { 94 $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto"; 95 } 96 } else { 97 $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto"; 98 } 99 100 $location = wp_kses_no_null($location); 101 $strip = array('%0d', '%0a', '%0D', '%0A'); 102 $location = _deep_replace($strip, $location); 103 header("Location: $location"); 104 exit(); 105 92 wp_redirect( $location ); 93 exit; 106 94 break; 107 95 108 96 default: 109 97 110 require_once( ABSPATH . 'wp-admin/admin-header.php');111 112 update_recently_edited( $file);113 114 if ( ! is_file($file) )115 $error = 1;98 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 99 100 update_recently_edited( $file ); 101 102 if ( ! is_file( $file ) ) 103 $error = true; 116 104 117 105 $content = ''; 118 if ( ! $error && filesize($file) > 0 ) {106 if ( ! $error && filesize( $file ) > 0 ) { 119 107 $f = fopen($file, 'r'); 120 108 $content = fread($f, filesize($file)); … … 135 123 136 124 ?> 137 <?php if ( isset($_GET['a'])) : ?>138 <div id="message" class="updated"><p><?php _e( 'File edited successfully.') ?></p></div>125 <?php if ( isset( $_GET['updated'] ) ) : ?> 126 <div id="message" class="updated"><p><?php _e( 'File edited successfully.' ) ?></p></div> 139 127 <?php endif; 140 128 141 $description = get_file_description( $file);142 $ desc_header = ( $description != $file_show ) ? "$description <span>($file_show)</span>" : $file_show;143 144 $is_child_theme = $themes[$theme]['Template'] != $themes[$theme]['Stylesheet'];129 $description = get_file_description( $file ); 130 $file_show = array_search( $file, array_filter( $allowed_files ) ); 131 if ( $description != $file_show ) 132 $description .= ' <span>(' . $file_show . ')</span>'; 145 133 ?> 146 134 <div class="wrap"> … … 150 138 <div class="fileedit-sub"> 151 139 <div class="alignleft"> 152 <h3><?php echo $theme s[$theme]['Name'] . ': ' . $desc_header; ?></h3>140 <h3><?php echo $theme->display('Name'); if ( $description ) echo ': ' . $description; ?></h3> 153 141 </div> 154 142 <div class="alignright"> … … 157 145 <select name="theme" id="theme"> 158 146 <?php 159 foreach ($themes as $a_theme) {160 $theme_name = $a_theme['Name'];161 if ($theme_name == $theme) $selected = " selected='selected'";162 else $selected = ''; 163 $ theme_name = esc_attr($theme_name);164 echo "\n\t <option value=\"$theme_name\" $selected>$theme_name</option>";147 foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) { 148 if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) 149 continue; 150 151 $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : ''; 152 echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>'; 165 153 } 166 154 ?> … … 171 159 <br class="clear" /> 172 160 </div> 161 <?php 162 if ( $theme->errors() ) 163 echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>'; 164 ?> 173 165 <div id="templateside"> 174 166 <?php 175 if ($allowed_files) : 167 if ( $allowed_files ) : 168 if ( $has_templates || $theme->parent() ) : 176 169 ?> 177 170 <h3><?php _e('Templates'); ?></h3> 178 <?php if ( $ is_child_theme) : ?>179 <p class="howto"><?php printf( __( 'This child theme inherits templates from a parent theme, %s.' ), $themes[$theme]['Parent Theme']); ?></p>171 <?php if ( $theme->parent() ) : ?> 172 <p class="howto"><?php printf( __( 'This child theme inherits templates from a parent theme, %s.' ), '<a href="' . self_admin_url('theme-editor.php?theme=' . urlencode( $theme->get_template() ) ) . '">' . $theme->parent()->display('Name') . '</a>' ); ?></p> 180 173 <?php endif; ?> 181 174 <ul> 182 175 <?php 183 $template_mapping = array(); 184 $template_dir = $themes[$theme]['Template Dir']; 185 foreach ( $themes[$theme]['Template Files'] as $template_file ) { 186 // Don't show parent templates. 187 if ( $is_child_theme && strpos( $template_file, trailingslashit( $template_dir ) ) === 0 ) 188 continue; 189 190 $description = trim( get_file_description($template_file) ); 191 $template_show = basename($template_file); 192 $filedesc = ( $description != $template_file ) ? "$description<br /><span class='nonessential'>($template_show)</span>" : "$description"; 193 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($template_show)</span></span>" : $filedesc; 194 $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc ); 195 } 196 ksort( $template_mapping ); 197 while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) : 198 ?> 199 <li><a href="theme-editor.php?file=<?php echo urlencode( $template_file ) ?>&theme=<?php echo urlencode( $theme ) ?>&dir=theme"><?php echo $filedesc ?></a></li> 200 <?php endwhile; ?> 201 </ul> 202 <h3><?php /* translators: Theme stylesheets in theme editor */ _ex('Styles', 'Theme stylesheets in theme editor'); ?></h3> 203 <ul> 204 <?php 205 $template_mapping = array(); 206 $stylesheet_dir = $themes[$theme]['Stylesheet Dir']; 207 foreach ( $themes[$theme]['Stylesheet Files'] as $style_file ) { 208 // Don't show parent styles. 209 if ( $is_child_theme && strpos( $style_file, trailingslashit( $template_dir ) ) === 0 ) 210 continue; 211 212 $description = trim( get_file_description($style_file) ); 213 $style_show = basename($style_file); 214 $filedesc = ( $description != $style_file ) ? "$description<br /><span class='nonessential'>($style_show)</span>" : "$description"; 215 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($style_show)</span></span>" : $filedesc; 216 $template_mapping[ $description ] = array( _get_template_edit_filename($style_file, $stylesheet_dir), $filedesc ); 217 } 218 ksort( $template_mapping ); 219 while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) : 220 ?> 221 <li><a href="theme-editor.php?file=<?php echo urlencode( $style_file ) ?>&theme=<?php echo urlencode($theme) ?>&dir=style"><?php echo $filedesc ?></a></li> 222 <?php endwhile; ?> 223 </ul> 176 endif; 177 178 foreach ( $allowed_files as $filename => $absolute_filename ) : 179 if ( 'style.css' == $filename ) 180 echo "\t</ul>\n\t<h3>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h3>\n\t<ul>\n"; 181 182 $file_description = get_file_description( $absolute_filename ); 183 if ( $file_description != basename( $filename ) ) 184 $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>'; 185 186 if ( $absolute_filename == $file ) 187 $file_description = '<span class="highlight">' . $file_description . '</span>'; 188 ?> 189 <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li> 190 <?php 191 endforeach; 192 ?> 193 </ul> 224 194 <?php endif; ?> 225 195 </div> 226 <?php if (!$error) { ?> 196 <?php if ( $error ) : 197 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; 198 else : ?> 227 199 <form name="template" id="template" action="theme-editor.php" method="post"> 228 <?php wp_nonce_field( 'edit-theme_' . $file . $theme)?>229 <div><textarea cols="70" rows=" 25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>200 <?php wp_nonce_field( 'edit-theme_' . $file . $stylesheet ); ?> 201 <div><textarea cols="70" rows="30" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 230 202 <input type="hidden" name="action" value="update" /> 231 <input type="hidden" name="file" value="<?php echo esc_attr( $file)?>" />232 <input type="hidden" name="theme" value="<?php echo esc_attr( $theme)?>" />203 <input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" /> 204 <input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" /> 233 205 <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> 234 206 </div> 235 <?php if ( isset($functions ) && count($functions) ) {?>207 <?php if ( ! empty( $functions ) ) : ?> 236 208 <div id="documentation" class="hide-if-no-js"> 237 209 <label for="docs-list"><?php _e('Documentation:') ?></label> … … 239 211 <input type="button" class="button" value=" <?php esc_attr_e( 'Lookup' ); ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /> 240 212 </div> 241 <?php }?>213 <?php endif; ?> 242 214 243 215 <div> 244 <?php if ( is_child_theme() && ! $is_child_theme && $themes[$theme]['Template'] == get_option('template') ) : ?>216 <?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?> 245 217 <p><?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?> 246 218 <?php _e( 'This is a file in your current parent theme.' ); ?></p> … … 255 227 </form> 256 228 <?php 257 } else { 258 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; 259 } 229 endif; // $error 260 230 ?> 261 231 <br class="clear" /> … … 273 243 } 274 244 275 include(ABSPATH . "wp-admin/admin-footer.php");245 include(ABSPATH . 'wp-admin/admin-footer.php' );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)