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