WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[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"><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 <div id="templateside"> 144 145 <?php 146 if ($allowed_files) : 147 ?> 148 <h3><?php _e('Templates'); ?></h3> 149 <ul> 150 <?php 151 $template_mapping = array(); 152 $template_dir = $themes[$theme]['Template Dir']; 153 foreach ( $themes[$theme]['Template Files'] as $template_file ) { 154 $description = trim( get_file_description($template_file) ); 155 $template_show = basename($template_file); 156 $filedesc = ( $description != $template_file ) ? "$description<br /><span class='nonessential'>($template_show)</span>" : "$description"; 157 $filedesc = ( $template_file == $file ) ? "<div class='highlight'>$description<br /><span class='nonessential'>($template_show)</span></div>" : $filedesc; 158 159 // If we have two files of the same name prefer the one in the Template Directory 160 // This means that we display the correct files for child themes which overload Templates as well as Styles 161 if ( array_key_exists($description, $template_mapping ) ) { 162 if ( false !== strpos( $template_file, $template_dir ) ) { 163 $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc ); 164 } 165 } else { 166 $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc ); 167 } 168 } 169 ksort( $template_mapping ); 170 while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) : 171 ?> 172 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>&dir=theme"><?php echo $filedesc ?></a></li> 173 <?php endwhile; ?> 174 </ul> 175 <h3><?php /* translators: Theme stylesheets in theme editor */ echo _x('Styles', 'Theme stylesheets in theme editor'); ?></h3> 176 <ul> 177 <?php 178 $template_mapping = array(); 179 $stylesheet_dir = $themes[$theme]['Stylesheet Dir']; 180 foreach ( $themes[$theme]['Stylesheet Files'] as $style_file ) { 181 $description = trim( get_file_description($style_file) ); 182 $style_show = basename($style_file); 183 $filedesc = ( $description != $style_file ) ? "$description<br /><span class='nonessential'>($style_show)</span>" : "$description"; 184 $filedesc = ( $style_file == $file ) ? "<div class='highlight'>$description<br /><span class='nonessential'>($style_show)</span></div>" : $filedesc; 185 $template_mapping[ $description ] = array( _get_template_edit_filename($style_file, $stylesheet_dir), $filedesc ); 186 } 187 ksort( $template_mapping ); 188 while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) : 189 ?> 190 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>&dir=style"><?php echo $filedesc ?></a></li> 191 <?php endwhile; ?> 192 </ul> 193 <?php endif; ?> 194 </div> 195 <?php if (!$error) { ?> 196 <form name="template" id="template" action="theme-editor.php" method="post"> 197 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?> 198 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea> 199 <input type="hidden" name="action" value="update" /> 200 <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> 201 <input type="hidden" name="theme" value="<?php echo esc_attr($theme) ?>" /> 202 <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> 203 </div> 204 <?php if ( isset($functions ) && count($functions) ) { ?> 205 <div id="documentation"> 206 <label for="docs-list"><?php _e('Documentation:') ?></label> 207 <?php echo $docs_select; ?> 208 <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'); }" /> 209 </div> 210 <?php } ?> 211 212 <div> 213 <?php if ( is_writeable($file) ) : ?> 214 <p class="submit"> 215 <?php 216 echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />"; 217 ?> 218 </p> 219 <?php else : ?> 220 <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> 221 <?php endif; ?> 222 </div> 223 </form> 224 <?php 225 } else { 226 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; 227 } 228 ?> 229 <br class="clear" /> 230 </div> 231 <script type="text/javascript"> 232 /* <![CDATA[ */ 233 jQuery(document).ready(function($){ 234 $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); }); 235 $('#newcontent').scrollTop( $('#scrollto').val() ); 236 }); 237 /* ]]> */ 238 </script> 239 <?php 240 break; 241 } 242 243 include ("admin-footer.php");
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |