]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/theme-editor.php
Wordpress 2.3.2-scripts
[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 $themes = get_themes();
10
11 if (empty($theme)) {
12         $theme = get_current_theme();
13 } else {
14         $theme = stripslashes($theme);
15  }
16
17
18 if ( ! isset($themes[$theme]) )
19         wp_die(__('The requested theme does not exist.'));
20
21 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
22
23 if (empty($file)) {
24         $file = $allowed_files[0];
25 }
26
27 $file = validate_file_to_edit($file, $allowed_files);
28 $real_file = get_real_file_to_edit($file);
29
30 $file_show = basename( $file );
31
32 switch($action) {
33
34 case 'update':
35
36         check_admin_referer('edit-theme_' . $file . $theme);
37
38         if ( !current_user_can('edit_themes') )
39                 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
40
41         $newcontent = stripslashes($_POST['newcontent']);
42         $theme = urlencode($theme);
43         if (is_writeable($real_file)) {
44                 $f = fopen($real_file, 'w+');
45                 fwrite($f, $newcontent);
46                 fclose($f);
47                 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
48         } else {
49                 $location = "theme-editor.php?file=$file&theme=$theme";
50         }
51
52         $location = wp_kses_no_null($location);
53         $strip = array('%0d', '%0a');
54         $location = str_replace($strip, '', $location);
55         header("Location: $location");
56         exit();
57
58 break;
59
60 default:
61
62         if ( !current_user_can('edit_themes') )
63                 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
64
65         require_once('admin-header.php');
66
67         update_recently_edited($file);
68
69         if (!is_file($real_file))
70                 $error = 1;
71
72         if (!$error && filesize($real_file) > 0) {
73                 $f = fopen($real_file, 'r');
74                 $content = fread($f, filesize($real_file));
75                 $content = htmlspecialchars($content);
76         }
77
78         ?>
79 <?php if (isset($_GET['a'])) : ?>
80  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
81 <?php endif; ?>
82  <div class="wrap">
83         <form name="theme" action="theme-editor.php" method="post">
84                 <?php _e('Select theme to edit:') ?>
85                 <select name="theme" id="theme">
86         <?php
87                 foreach ($themes as $a_theme) {
88                 $theme_name = $a_theme['Name'];
89                 if ($theme_name == $theme) $selected = " selected='selected'";
90                 else $selected = '';
91                 $theme_name = attribute_escape($theme_name);
92                 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
93         }
94 ?>
95  </select>
96  <input type="submit" name="Submit" value="<?php _e('Select &raquo;') ?>" class="button" />
97  </form>
98  </div>
99
100  <div class="wrap">
101   <?php
102         if ( is_writeable($real_file) ) {
103                 echo '<h2>' . sprintf(__('Editing <code>%s</code>'), $file_show) . '</h2>';
104         } else {
105                 echo '<h2>' . sprintf(__('Browsing <code>%s</code>'), $file_show) . '</h2>';
106         }
107         ?>
108         <div id="templateside">
109         <h3><?php printf(__("<strong>'%s'</strong> theme files"), $theme) ?></h3>
110
111 <?php
112 if ($allowed_files) :
113 ?>
114         <ul>
115 <?php foreach($allowed_files as $allowed_file) : ?>
116                  <li><a href="theme-editor.php?file=<?php echo "$allowed_file"; ?>&amp;theme=<?php echo urlencode($theme) ?>"><?php echo get_file_description($allowed_file); ?></a></li>
117 <?php endforeach; ?>
118         </ul>
119 <?php endif; ?>
120 </div>
121         <?php
122         if (!$error) {
123         ?>
124         <form name="template" id="template" action="theme-editor.php" method="post">
125         <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
126                  <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
127                  <input type="hidden" name="action" value="update" />
128                  <input type="hidden" name="file" value="<?php echo $file ?>" />
129                  <input type="hidden" name="theme" value="<?php echo $theme ?>" />
130                  </div>
131 <?php if ( is_writeable($real_file) ) : ?>
132         <p class="submit">
133 <?php
134         echo "<input type='submit' name='submit' value='        " . __('Update File &raquo;') . "' tabindex='2' />";
135 ?>
136 </p>
137 <?php else : ?>
138 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
139 <?php endif; ?>
140         </form>
141         <?php
142         } else {
143                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
144         }
145         ?>
146 <div class="clear"> &nbsp; </div>
147 </div>
148 <?php
149 break;
150 }
151
152 include("admin-footer.php") ?>