]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/plugin-editor.php
Wordpress 2.3.2-scripts
[autoinstalls/wordpress.git] / wp-admin / plugin-editor.php
1 <?php
2 require_once('admin.php');
3
4 $title = __("Edit Plugins");
5 $parent_file = 'plugins.php';
6
7 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
8
9 $plugins = get_plugins();
10 $plugin_files = array_keys($plugins);
11
12 if (empty($file)) {
13         $file = $plugin_files[0];
14 }
15
16 $file = validate_file_to_edit($file, $plugin_files);
17 $real_file = get_real_file_to_edit( PLUGINDIR . "/$file");
18
19 switch($action) {
20
21 case 'update':
22
23         check_admin_referer('edit-plugin_' . $file);
24
25         if ( !current_user_can('edit_plugins') )
26                 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
27
28         $newcontent = stripslashes($_POST['newcontent']);
29         if (is_writeable($real_file)) {
30                 $f = fopen($real_file, 'w+');
31                 fwrite($f, $newcontent);
32                 fclose($f);
33
34                 // Deactivate so we can test it.
35                 $current = get_option('active_plugins');
36                 if ( in_array($file, $current) || isset($_POST['phperror']) ) {
37                         if ( in_array($file, $current) ) {
38                                 array_splice($current, array_search( $file, $current), 1 ); // Array-fu!
39                                 update_option('active_plugins', $current);
40                         }
41                         wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
42                         exit();
43                 }
44                 wp_redirect("plugin-editor.php?file=$file&a=te");
45         } else {
46                 wp_redirect("plugin-editor.php?file=$file");
47         }
48
49         exit();
50
51 break;
52
53 default:
54
55         if ( !current_user_can('edit_plugins') )
56                 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
57
58         if ( $_GET['liveupdate'] ) {
59                 check_admin_referer('edit-plugin-test_' . $file);
60                 $current = get_option('active_plugins');
61                 $plugin = $file;
62                 if ( validate_file($plugin) )
63                         wp_die(__('Invalid plugin.'));
64                 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
65                         wp_die(__('Plugin file does not exist.'));
66                 if (!in_array($plugin, $current)) {
67                         wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
68                         @include(ABSPATH . PLUGINDIR . '/' . $plugin);
69                         $current[] = $plugin;
70                         sort($current);
71                         update_option('active_plugins', $current);
72                 }
73                 wp_redirect("plugin-editor.php?file=$file&a=te");
74         }
75
76         require_once('admin-header.php');
77
78         update_recently_edited(PLUGINDIR . "/$file");
79
80         if (!is_file($real_file))
81                 $error = 1;
82
83         if (!$error) {
84                 $f = fopen($real_file, 'r');
85                 $content = fread($f, filesize($real_file));
86                 $content = htmlspecialchars($content);
87         }
88
89         ?>
90 <?php if (isset($_GET['a'])) : ?>
91  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
92 <?php elseif (isset($_GET['phperror'])) : ?>
93  <div id="message" class="updated fade"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p></div>
94 <?php endif; ?>
95  <div class="wrap">
96         <?php
97         if ( in_array($file, (array) get_option('active_plugins')) ) {
98                 if (is_writeable($real_file)) {
99                         echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (active)'), $file) . '</h2>';
100                 } else {
101                 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (active)'), $file) . '</h2>';
102                 }
103         } else {
104                 if (is_writeable($real_file)) {
105                         echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (inactive)'), $file) . '</h2>';
106                 } else {
107                 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file) . '</h2>';
108                 }
109         }
110         ?>
111         <div id="templateside">
112 <h3><?php _e('Plugin files') ?></h3>
113
114 <?php
115 if ($plugin_files) :
116 ?>
117         <ul>
118         <?php foreach($plugin_files as $plugin_file) : ?>
119                  <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
120         <?php endforeach; ?>
121         </ul>
122 <?php endif; ?>
123 </div>
124 <?php   if (!$error) { ?>
125         <form name="template" id="template" action="plugin-editor.php" method="post">
126         <?php wp_nonce_field('edit-plugin_' . $file) ?>
127                 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
128                 <input type="hidden" name="action" value="update" />
129                 <input type="hidden" name="file" value="<?php echo $file ?>" />
130                 </div>
131 <?php if ( is_writeable($real_file) ) : ?>
132         <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
133                 <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended.  If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p>
134         <?php } ?>
135         <p class="submit">
136         <?php
137                 if ( isset($_GET['phperror']) )
138                         echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' value='" . __('Update File and Attempt to Reactivate &raquo;') . "' tabindex='2' />";
139                 else
140                         echo "<input type='submit' name='submit' value='" . __('Update File &raquo;') . "' tabindex='2' />";
141         ?>
142         </p>
143 <?php else : ?>
144         <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
145 <?php endif; ?>
146  </form>
147 <?php
148         } else {
149                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
150         }
151 ?>
152 <div class="clear"> &nbsp; </div>
153 </div>
154 <?php
155 break;
156 }
157
158 include("admin-footer.php") ?>