]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/theme-editor.php
Wordpress 2.5.1
[autoinstalls/wordpress.git] / wp-admin / theme-editor.php
1 <?php
2 require_once('admin.php');
3
4 $title = __("Edit Themes");
5 $parent_file = 'themes.php';
6
7 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme'));
8
9 add_action( 'admin_head', 'theme_editor_css' );
10 function theme_editor_css(){
11         wp_admin_css( 'css/theme-editor' );
12 }
13
14 $themes = get_themes();
15
16 if (empty($theme)) {
17         $theme = get_current_theme();
18 } else {
19         $theme = stripslashes($theme);
20  }
21
22
23 if ( ! isset($themes[$theme]) )
24         wp_die(__('The requested theme does not exist.'));
25
26 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
27
28 if (empty($file)) {
29         $file = $allowed_files[0];
30 }
31
32 $file = validate_file_to_edit($file, $allowed_files);
33 $real_file = get_real_file_to_edit($file);
34
35 $file_show = basename( $file );
36
37 switch($action) {
38
39 case 'update':
40
41         check_admin_referer('edit-theme_' . $file . $theme);
42
43         if ( !current_user_can('edit_themes') )
44                 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
45
46         $newcontent = stripslashes($_POST['newcontent']);
47         $theme = urlencode($theme);
48         if (is_writeable($real_file)) {
49                 $f = fopen($real_file, 'w+');
50                 fwrite($f, $newcontent);
51                 fclose($f);
52                 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
53         } else {
54                 $location = "theme-editor.php?file=$file&theme=$theme";
55         }
56
57         $location = wp_kses_no_null($location);
58         $strip = array('%0d', '%0a');
59         $location = str_replace($strip, '', $location);
60         header("Location: $location");
61         exit();
62
63 break;
64
65 default:
66
67         if ( !current_user_can('edit_themes') )
68                 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
69
70         require_once('admin-header.php');
71
72         update_recently_edited($file);
73
74         if (!is_file($real_file))
75                 $error = 1;
76
77         if (!$error && filesize($real_file) > 0) {
78                 $f = fopen($real_file, 'r');
79                 $content = fread($f, filesize($real_file));
80                 $content = htmlspecialchars($content);
81         }
82
83         ?>
84 <?php if (isset($_GET['a'])) : ?>
85  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
86 <?php endif;
87
88 $description = get_file_description($file);
89 $desc_header = ( $description != $file_show ) ? "$description</strong> (%s)" : "%s";
90 ?>
91 <div class="wrap">
92 <div class="bordertitle">
93         <h2><?php _e('Theme Editor'); ?></h2>
94         <form id="themeselector" name="theme" action="theme-editor.php" method="post">
95                 <strong><?php _e('Select theme to edit:'); ?> </strong>
96                 <select name="theme" id="theme">
97 <?php
98         foreach ($themes as $a_theme) {
99         $theme_name = $a_theme['Name'];
100         if ($theme_name == $theme) $selected = " selected='selected'";
101         else $selected = '';
102         $theme_name = attribute_escape($theme_name);
103         echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
104 }
105 ?>
106                 </select>
107                 <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
108         </form>
109 </div>
110 <div class="tablenav">
111 <div class="alignleft">
112 <big><strong><?php echo sprintf($desc_header, $file_show); ?></big>
113 </div>
114 <br class="clear" />
115 </div>
116 <br class="clear" />
117         <div id="templateside">
118         <h3 id="bordertitle"><?php _e("Theme Files"); ?></h3>
119
120 <?php
121 if ($allowed_files) :
122 ?>
123         <h4><?php _e('Templates'); ?></h4>
124         <ul>
125 <?php foreach($themes[$theme]['Template Files'] as $template_file) :
126                 $description = get_file_description($template_file);
127                 $template_show = basename($template_file);
128                 $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
129                 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc;
130                 ?>
131                 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&amp;theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
132 <?php endforeach; ?>
133         </ul>
134         <h4><?php echo _c('Styles|Theme stylesheets in theme editor'); ?></h4>
135         <ul>
136 <?php foreach($themes[$theme]['Stylesheet Files'] as $style_file) :
137                 $description = get_file_description($style_file);
138                 $style_show = basename($style_file);
139                 $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
140                 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc;
141                 ?>
142                 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&amp;theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
143 <?php endforeach; ?>
144         </ul>
145 <?php endif; ?>
146 </div>
147         <?php
148         if (!$error) {
149         ?>
150         <form name="template" id="template" action="theme-editor.php" method="post">
151         <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
152                  <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
153                  <input type="hidden" name="action" value="update" />
154                  <input type="hidden" name="file" value="<?php echo $file ?>" />
155                  <input type="hidden" name="theme" value="<?php echo $theme ?>" />
156                  </div>
157
158                 <div>
159 <?php if ( is_writeable($real_file) ) : ?>
160                         <p class="submit">
161 <?php
162         echo "<input type='submit' name='submit' value='" . __('Update File') . "' tabindex='2' />";
163 ?>
164 </p>
165 <?php else : ?>
166 <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>
167 <?php endif; ?>
168                 </div>
169         </form>
170         <?php
171         } else {
172                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
173         }
174         ?>
175 <div class="clear"> &nbsp; </div>
176 </div>
177 <?php
178 break;
179 }
180
181 include("admin-footer.php") ?>