mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Theme editor administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once('admin.php');
mp-wp_genesis 11
mp-wp_genesis 12 $title = __("Edit Themes");
mp-wp_genesis 13 $parent_file = 'themes.php';
mp-wp_genesis 14
mp-wp_genesis 15 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme'));
mp-wp_genesis 16
mp-wp_genesis 17 wp_admin_css( 'theme-editor' );
mp-wp_genesis 18
mp-wp_genesis 19 $themes = get_themes();
mp-wp_genesis 20
mp-wp_genesis 21 if (empty($theme)) {
mp-wp_genesis 22 $theme = get_current_theme();
mp-wp_genesis 23 } else {
mp-wp_genesis 24 $theme = stripslashes($theme);
mp-wp_genesis 25 }
mp-wp_genesis 26
mp-wp_genesis 27
mp-wp_genesis 28 if ( ! isset($themes[$theme]) )
mp-wp_genesis 29 wp_die(__('The requested theme does not exist.'));
mp-wp_genesis 30
mp-wp_genesis 31 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
mp-wp_genesis 32
mp-wp_genesis 33 if (empty($file)) {
mp-wp_genesis 34 $file = $allowed_files[0];
mp-wp_genesis 35 }
mp-wp_genesis 36
mp-wp_genesis 37 $file = validate_file_to_edit($file, $allowed_files);
mp-wp_genesis 38 $real_file = get_real_file_to_edit($file);
mp-wp_genesis 39
mp-wp_genesis 40 $file_show = basename( $file );
mp-wp_genesis 41
mp-wp_genesis 42 switch($action) {
mp-wp_genesis 43
mp-wp_genesis 44 case 'update':
mp-wp_genesis 45
mp-wp_genesis 46 check_admin_referer('edit-theme_' . $file . $theme);
mp-wp_genesis 47
mp-wp_genesis 48 if ( !current_user_can('edit_themes') )
mp-wp_genesis 49 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
mp-wp_genesis 50
mp-wp_genesis 51 $newcontent = stripslashes($_POST['newcontent']);
mp-wp_genesis 52 $theme = urlencode($theme);
mp-wp_genesis 53 if (is_writeable($real_file)) {
mp-wp_genesis 54 //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
mp-wp_genesis 55 $f = fopen($real_file, 'w+');
mp-wp_genesis 56 if ($f !== FALSE) {
mp-wp_genesis 57 fwrite($f, $newcontent);
mp-wp_genesis 58 fclose($f);
mp-wp_genesis 59 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
mp-wp_genesis 60 } else {
mp-wp_genesis 61 $location = "theme-editor.php?file=$file&theme=$theme";
mp-wp_genesis 62 }
mp-wp_genesis 63 } else {
mp-wp_genesis 64 $location = "theme-editor.php?file=$file&theme=$theme";
mp-wp_genesis 65 }
mp-wp_genesis 66
mp-wp_genesis 67 $location = wp_kses_no_null($location);
mp-wp_genesis 68 $strip = array('%0d', '%0a');
mp-wp_genesis 69 $location = str_replace($strip, '', $location);
mp-wp_genesis 70 header("Location: $location");
mp-wp_genesis 71 exit();
mp-wp_genesis 72
mp-wp_genesis 73 break;
mp-wp_genesis 74
mp-wp_genesis 75 default:
mp-wp_genesis 76
mp-wp_genesis 77 if ( !current_user_can('edit_themes') )
mp-wp_genesis 78 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
mp-wp_genesis 79
mp-wp_genesis 80 require_once('admin-header.php');
mp-wp_genesis 81
mp-wp_genesis 82 update_recently_edited($file);
mp-wp_genesis 83
mp-wp_genesis 84 if (!is_file($real_file))
mp-wp_genesis 85 $error = 1;
mp-wp_genesis 86
mp-wp_genesis 87 if (!$error && filesize($real_file) > 0) {
mp-wp_genesis 88 $f = fopen($real_file, 'r');
mp-wp_genesis 89 $content = fread($f, filesize($real_file));
mp-wp_genesis 90 $content = htmlspecialchars($content);
mp-wp_genesis 91 }
mp-wp_genesis 92
mp-wp_genesis 93 ?>
mp-wp_genesis 94 <?php if (isset($_GET['a'])) : ?>
mp-wp_genesis 95 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
mp-wp_genesis 96 <?php endif;
mp-wp_genesis 97
mp-wp_genesis 98 $description = get_file_description($file);
mp-wp_genesis 99 $desc_header = ( $description != $file_show ) ? "$description</strong> (%s)" : "%s";
mp-wp_genesis 100 ?>
mp-wp_genesis 101 <div class="wrap">
mp-wp_genesis 102 <?php screen_icon(); ?>
mp-wp_genesis 103 <h2><?php echo wp_specialchars( $title ); ?></h2>
mp-wp_genesis 104 <div class="bordertitle">
mp-wp_genesis 105 <form id="themeselector" action="theme-editor.php" method="post">
mp-wp_genesis 106 <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
mp-wp_genesis 107 <select name="theme" id="theme">
mp-wp_genesis 108 <?php
mp-wp_genesis 109 foreach ($themes as $a_theme) {
mp-wp_genesis 110 $theme_name = $a_theme['Name'];
mp-wp_genesis 111 if ($theme_name == $theme) $selected = " selected='selected'";
mp-wp_genesis 112 else $selected = '';
mp-wp_genesis 113 $theme_name = attribute_escape($theme_name);
mp-wp_genesis 114 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
mp-wp_genesis 115 }
mp-wp_genesis 116 ?>
mp-wp_genesis 117 </select>
mp-wp_genesis 118 <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
mp-wp_genesis 119 </form>
mp-wp_genesis 120 </div>
mp-wp_genesis 121 <div class="tablenav">
mp-wp_genesis 122 <div class="alignleft">
mp-wp_genesis 123 <big><strong><?php echo sprintf($desc_header, $file_show); ?></big>
mp-wp_genesis 124 </div>
mp-wp_genesis 125 <br class="clear" />
mp-wp_genesis 126 </div>
mp-wp_genesis 127 <br class="clear" />
mp-wp_genesis 128 <div id="templateside">
mp-wp_genesis 129 <h3 id="bordertitle"><?php _e("Theme Files"); ?></h3>
mp-wp_genesis 130
mp-wp_genesis 131 <?php
mp-wp_genesis 132 if ($allowed_files) :
mp-wp_genesis 133 ?>
mp-wp_genesis 134 <h4><?php _e('Templates'); ?></h4>
mp-wp_genesis 135 <ul>
mp-wp_genesis 136 <?php
mp-wp_genesis 137 $template_mapping = array();
mp-wp_genesis 138 $template_dir = $themes[$theme]['Template Dir'];
mp-wp_genesis 139 foreach($themes[$theme]['Template Files'] as $template_file) {
mp-wp_genesis 140 $description = trim( get_file_description($template_file) );
mp-wp_genesis 141 $template_show = basename($template_file);
mp-wp_genesis 142 $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
mp-wp_genesis 143 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc;
mp-wp_genesis 144
mp-wp_genesis 145 // If we have two files of the same name prefer the one in the Template Directory
mp-wp_genesis 146 // This means that we display the correct files for child themes which overload Templates as well as Styles
mp-wp_genesis 147 if( array_key_exists($description, $template_mapping ) ) {
mp-wp_genesis 148 if ( false !== strpos( $template_file, $template_dir ) ) {
mp-wp_genesis 149 $template_mapping[ $description ] = array( $template_file, $filedesc );
mp-wp_genesis 150 }
mp-wp_genesis 151 } else {
mp-wp_genesis 152 $template_mapping[ $description ] = array( $template_file, $filedesc );
mp-wp_genesis 153 }
mp-wp_genesis 154 }
mp-wp_genesis 155 ksort( $template_mapping );
mp-wp_genesis 156 while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) :
mp-wp_genesis 157 ?>
mp-wp_genesis 158 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
mp-wp_genesis 159 <?php endwhile; ?>
mp-wp_genesis 160 </ul>
mp-wp_genesis 161 <h4><?php echo _c('Styles|Theme stylesheets in theme editor'); ?></h4>
mp-wp_genesis 162 <ul>
mp-wp_genesis 163 <?php
mp-wp_genesis 164 $template_mapping = array();
mp-wp_genesis 165 foreach($themes[$theme]['Stylesheet Files'] as $style_file) {
mp-wp_genesis 166 $description = trim( get_file_description($style_file) );
mp-wp_genesis 167 $style_show = basename($style_file);
mp-wp_genesis 168 $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
mp-wp_genesis 169 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc;
mp-wp_genesis 170 $template_mapping[ $description ] = array( $style_file, $filedesc );
mp-wp_genesis 171 }
mp-wp_genesis 172 ksort( $template_mapping );
mp-wp_genesis 173 while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) :
mp-wp_genesis 174 ?>
mp-wp_genesis 175 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
mp-wp_genesis 176 <?php endwhile; ?>
mp-wp_genesis 177 </ul>
mp-wp_genesis 178 <?php endif; ?>
mp-wp_genesis 179 </div>
mp-wp_genesis 180 <?php
mp-wp_genesis 181 if (!$error) {
mp-wp_genesis 182 ?>
mp-wp_genesis 183 <form name="template" id="template" action="theme-editor.php" method="post">
mp-wp_genesis 184 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
mp-wp_genesis 185 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
mp-wp_genesis 186 <input type="hidden" name="action" value="update" />
mp-wp_genesis 187 <input type="hidden" name="file" value="<?php echo $file ?>" />
mp-wp_genesis 188 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
mp-wp_genesis 189 </div>
mp-wp_genesis 190
mp-wp_genesis 191 <div>
mp-wp_genesis 192 <?php if ( is_writeable($real_file) ) : ?>
mp-wp_genesis 193 <p class="submit">
mp-wp_genesis 194 <?php
mp-wp_genesis 195 echo "<input type='submit' name='submit' class='button-primary' value='" . __('Update File') . "' tabindex='2' />";
mp-wp_genesis 196 ?>
mp-wp_genesis 197 </p>
mp-wp_genesis 198 <?php else : ?>
mp-wp_genesis 199 <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>
mp-wp_genesis 200 <?php endif; ?>
mp-wp_genesis 201 </div>
mp-wp_genesis 202 </form>
mp-wp_genesis 203 <?php
mp-wp_genesis 204 } else {
mp-wp_genesis 205 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
mp-wp_genesis 206 }
mp-wp_genesis 207 ?>
mp-wp_genesis 208 <div class="clear"> </div>
mp-wp_genesis 209 </div>
mp-wp_genesis 210 <?php
mp-wp_genesis 211 break;
mp-wp_genesis 212 }
mp-wp_genesis 213
mp-wp_genesis 214 include("admin-footer.php") ?>