| [ Root ] [ Index ] |
PHP Cross Reference of WordPress 2.9Provided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Theme editor administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once ('admin.php'); 11 12 if ( !current_user_can('edit_themes') ) 13 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>'); 14 15 $title = __("Edit Themes"); 16 $parent_file = 'themes.php'; 17 18 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme', 'dir')); 19 20 wp_admin_css( 'theme-editor' ); 21 22 $themes = get_themes(); 23 24 if (empty($theme)) { 25 $theme = get_current_theme(); 26 } else { 27 $theme = stripslashes($theme); 28 } 29 30 if ( ! isset($themes[$theme]) ) 31 wp_die(__('The requested theme does not exist.')); 32 33 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']); 34 35 if (empty($file)) { 36 $file = $allowed_files[0]; 37 } else { 38 $file = stripslashes($file); 39 if ( 'theme' == $dir ) { 40 $file = dirname(dirname($themes[$theme]['Template Dir'])) . $file ; 41 } else if ( 'style' == $dir) { 42 $file = dirname(dirname($themes[$theme]['Stylesheet Dir'])) . $file ; 43 } 44 } 45 46 validate_file_to_edit($file, $allowed_files); 47 $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; 48 $file_show = basename( $file ); 49 50 switch($action) { 51 52 case 'update': 53 54 check_admin_referer('edit-theme_' . $file . $theme); 55 56 $newcontent = stripslashes($_POST['newcontent']); 57 $theme = urlencode($theme); 58 if (is_writeable($file)) { 59 //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable 60 $f = fopen($file, 'w+'); 61 if ($f !== FALSE) { 62 fwrite($f, $newcontent); 63 fclose($f); 64 $location = "theme-editor.php?file=$file&theme=$theme&a=te&scrollto=$scrollto"; 65 } else { 66 $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto"; 67 } 68 } else { 69 $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto"; 70 } 71 72 $location = wp_kses_no_null($location); 73 $strip = array('%0d', '%0a', '%0D', '%0A'); 74 $location = _deep_replace($strip, $location); 75 header("Location: $location"); 76 exit(); 77 78 break; 79 80 default: 81 82 require_once ('admin-header.php'); 83 84 update_recently_edited($file); 85 86 if ( !is_file($file) ) 87 $error = 1; 88 89 if ( !$error && filesize($file) > 0 ) { 90 $f = fopen($file, 'r'); 91 $content = fread($f, filesize($file)); 92 93 if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) { 94 $functions = wp_doc_link_parse( $content ); 95 96 $docs_select = '<select name="docs-list" id="docs-list">'; 97 $docs_select .= '<option value="">' . esc_attr__( 'Function Name...' ) . '</option>'; 98 foreach ( $functions as $function ) { 99 $docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>'; 100 } 101 $docs_select .= '</select>'; 102 } 103 104 $content = htmlspecialchars( $content ); 105 $codepress_lang = codepress_get_lang($file); 106 } 107 108 ?> 109 <?php if (isset($_GET['a'])) : ?> 110 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div> 111 <?php endif; 112 113 $description = get_file_description($file); 114 $desc_header = ( $description != $file_show ) ? "<strong>$description</strong> (%s)" : "%s"; 115 ?> 116 <div class="wrap"> 117 <?php screen_icon(); ?> 118 <h2><?php echo esc_html( $title ); ?></h2> 119 120 <div class="fileedit-sub"> 121 <div class="alignleft"> 122 <big><?php echo sprintf($desc_header, $file_show); ?></big> 123 </div> 124 <div class="alignright"> 125 <form action="theme-editor.php" method="post"> 126 <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong> 127 <select name="theme" id="theme"> 128 <?php 129 foreach ($themes as $a_theme) { 130 $theme_name = $a_theme['Name']; 131 if ($theme_name == $theme) $selected = " selected='selected'"; 132 else $selected = ''; 133 $theme_name = esc_attr($theme_name); 134 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>"; 135 } 136 ?> 137 </select> 138 <input type="submit" name="Submit" value="<?php esc_attr_e('Select') ?>" class="button" /> 139 </form> 140 </div> 141 <br class="clear" /> 142 </div> 143 <br class="clear" /> 144 <div id="templateside"> 145 <h3><?php _e("Theme Files"); ?></h3> 146 147 <?php 148 if ($allowed_files) : 149 ?> 150 <h4><?php _e('Templates'); ?></h4> 151 <ul> 152 <?php 153 $template_mapping = array(); 154 $template_dir = $themes[$theme]['Template Dir']; 155 foreach ( $themes[$theme]['Template Files'] as $template_file ) { 156 $description = trim( get_file_description($template_file) ); 157 $template_show = basename($template_file); 158 $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description"; 159 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc; 160 161 // If we have two files of the same name prefer the one in the Template Directory 162 // This means that we display the correct files for child themes which overload Templates as well as Styles 163 if( array_key_exists($description, $template_mapping ) ) { 164 if ( false !== strpos( $template_file, $template_dir ) ) { 165 $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc ); 166 } 167 } else { 168 $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc ); 169 } 170 } 171 ksort( $template_mapping ); 172 while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) : 173 ?> 174 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>&dir=theme"><?php echo $filedesc ?></a></li> 175 <?php endwhile; ?> 176 </ul> 177 <h4><?php /* translators: Theme stylesheets in theme editor */ echo _x('Styles', 'Theme stylesheets in theme editor'); ?></h4> 178 <ul> 179 <?php 180 $template_mapping = array(); 181 $stylesheet_dir = $themes[$theme]['Stylesheet Dir']; 182 foreach ( $themes[$theme]['Stylesheet Files'] as $style_file ) { 183 $description = trim( get_file_description($style_file) ); 184 $style_show = basename($style_file); 185 $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description"; 186 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc; 187 $template_mapping[ $description ] = array( _get_template_edit_filename($style_file, $stylesheet_dir), $filedesc ); 188 } 189 ksort( $template_mapping ); 190 while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) : 191 ?> 192 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>&dir=style"><?php echo $filedesc ?></a></li> 193 <?php endwhile; ?> 194 </ul> 195 <?php endif; ?> 196 </div> 197 <?php if (!$error) { ?> 198 <form name="template" id="template" action="theme-editor.php" method="post"> 199 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?> 200 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea> 201 <input type="hidden" name="action" value="update" /> 202 <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> 203 <input type="hidden" name="theme" value="<?php echo esc_attr($theme) ?>" /> 204 <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> 205 </div> 206 <?php if ( isset($functions ) && count($functions) ) { ?> 207 <div id="documentation"> 208 <label for="docs-list"><?php _e('Documentation:') ?></label> 209 <?php echo $docs_select; ?> 210 <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'); }" /> 211 </div> 212 <?php } ?> 213 214 <div> 215 <?php if ( is_writeable($file) ) : ?> 216 <p class="submit"> 217 <?php 218 echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />"; 219 ?> 220 </p> 221 <?php else : ?> 222 <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p> 223 <?php endif; ?> 224 </div> 225 </form> 226 <?php 227 } else { 228 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; 229 } 230 ?> 231 <br class="clear" /> 232 </div> 233 <script type="text/javascript"> 234 /* <![CDATA[ */ 235 jQuery(document).ready(function($){ 236 $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); }); 237 $('#newcontent').scrollTop( $('#scrollto').val() ); 238 }); 239 /* ]]> */ 240 </script> 241 <?php 242 break; 243 } 244 245 include ("admin-footer.php");
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 27 21:34:27 2010 | Cross-referenced by PHPXref 0.7 |