source: trunk/www.guidonia.net/wp/wp-admin/plugin-editor.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 8.1 KB
Line 
1<?php
2/**
3 * Edit plugin editor administration panel.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/** WordPress Administration Bootstrap */
10require_once('admin.php');
11
12$title = __("Edit Plugins");
13$parent_file = 'plugins.php';
14
15wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
16
17wp_admin_css( 'theme-editor' );
18
19$plugins = get_plugins();
20
21if ( isset($_REQUEST['file']) )
22 $plugin = $_REQUEST['file'];
23
24if ( empty($plugin) ) {
25 $plugin = array_keys($plugins);
26 $plugin = $plugin[0];
27}
28
29$plugin_files = get_plugin_files($plugin);
30
31if ( empty($file) )
32 $file = $plugin_files[0];
33
34$file = validate_file_to_edit($file, $plugin_files);
35$real_file = WP_PLUGIN_DIR . '/' . $file;
36
37switch ( $action ) {
38
39case 'update':
40
41 check_admin_referer('edit-plugin_' . $file);
42
43 if ( !current_user_can('edit_plugins') )
44 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
45
46 $newcontent = stripslashes($_POST['newcontent']);
47 if ( is_writeable($real_file) ) {
48 $f = fopen($real_file, 'w+');
49 fwrite($f, $newcontent);
50 fclose($f);
51
52 // Deactivate so we can test it.
53 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
54 if ( is_plugin_active($file) )
55 deactivate_plugins($file, true);
56 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
57 exit;
58 }
59 wp_redirect("plugin-editor.php?file=$file&a=te");
60 } else {
61 wp_redirect("plugin-editor.php?file=$file");
62 }
63 exit;
64
65break;
66
67default:
68
69 if ( !current_user_can('edit_plugins') )
70 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
71
72 if ( isset($_GET['liveupdate']) ) {
73 check_admin_referer('edit-plugin-test_' . $file);
74
75 $error = validate_plugin($file);
76 if ( is_wp_error($error) )
77 wp_die( $error );
78
79 if ( ! is_plugin_active($file) )
80 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
81
82 wp_redirect("plugin-editor.php?file=$file&a=te");
83 exit;
84 }
85
86 // List of allowable extensions
87 $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
88 $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
89
90 if ( ! is_file($real_file) ) {
91 wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
92 } else {
93 // Get the extension of the file
94 if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
95 $ext = strtolower($matches[1]);
96 // If extension is not in the acceptable list, skip it
97 if ( !in_array( $ext, $editable_extensions) )
98 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
99 }
100 }
101
102 require_once('admin-header.php');
103
104 update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
105
106 $content = file_get_contents( $real_file );
107
108 if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) {
109 $functions = wp_doc_link_parse( $content );
110
111 if ( !empty($functions) ) {
112 $docs_select = '<select name="docs-list" id="docs-list">';
113 $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>';
114 foreach ( $functions as $function) {
115 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . htmlspecialchars( $function ) . '()</option>';
116 }
117 $docs_select .= '</select>';
118 }
119 }
120
121 $content = htmlspecialchars( $content );
122 $codepress_lang = codepress_get_lang($real_file);
123
124 ?>
125<?php if (isset($_GET['a'])) : ?>
126 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
127<?php elseif (isset($_GET['phperror'])) : ?>
128 <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>
129 <?php
130 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
131 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo esc_attr($file); ?>&amp;_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe>
132 <?php } ?>
133</div>
134<?php endif; ?>
135<div class="wrap">
136<?php screen_icon(); ?>
137<h2><?php echo esc_html( $title ); ?></h2>
138
139<div class="fileedit-sub">
140<div class="alignleft">
141<big><?php
142 if ( is_plugin_active($plugin) ) {
143 if ( is_writeable($real_file) )
144 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
145 else
146 echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
147 } else {
148 if ( is_writeable($real_file) )
149 echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
150 else
151 echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
152 }
153 ?></big>
154</div>
155<div class="alignright">
156 <form action="plugin-editor.php" method="post">
157 <strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong>
158 <select name="plugin" id="plugin">
159<?php
160 foreach ( $plugins as $plugin_key => $a_plugin ) {
161 $plugin_name = $a_plugin['Name'];
162 if ( $plugin_key == $plugin )
163 $selected = " selected='selected'";
164 else
165 $selected = '';
166 $plugin_name = esc_attr($plugin_name);
167 $plugin_key = esc_attr($plugin_key);
168 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
169 }
170?>
171 </select>
172 <input type="submit" name="Submit" value="<?php esc_attr_e('Select') ?>" class="button" />
173 </form>
174</div>
175<br class="clear" />
176</div>
177
178<div id="templateside">
179 <h3><?php _e('Plugin Files'); ?></h3>
180
181 <ul>
182<?php
183foreach ( $plugin_files as $plugin_file ) :
184 // Get the extension of the file
185 if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) {
186 $ext = strtolower($matches[1]);
187 // If extension is not in the acceptable list, skip it
188 if ( !in_array( $ext, $editable_extensions ) )
189 continue;
190 } else {
191 // No extension found
192 continue;
193 }
194?>
195 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>&amp;plugin=<?php echo $plugin; ?>"><?php echo $plugin_file ?></a></li>
196<?php endforeach; ?>
197 </ul>
198</div>
199<form name="template" id="template" action="plugin-editor.php" method="post">
200 <?php wp_nonce_field('edit-plugin_' . $file) ?>
201 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
202 <input type="hidden" name="action" value="update" />
203 <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
204 <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
205 </div>
206 <?php if ( !empty( $docs_select ) ) : ?>
207 <div id="documentation"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php echo urlencode( get_locale() ) ?>&amp;version=<?php echo urlencode( $wp_version ) ?>&amp;redirect=true'); }" /></div>
208 <?php endif; ?>
209<?php if ( is_writeable($real_file) ) : ?>
210 <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
211 <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>
212 <?php } ?>
213 <p class="submit">
214 <?php
215 if ( isset($_GET['phperror']) )
216 echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File and Attempt to Reactivate') . "' tabindex='2' />";
217 else
218 echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />";
219 ?>
220 </p>
221<?php else : ?>
222 <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>
223<?php endif; ?>
224</form>
225<br class="clear" />
226</div>
227<?php
228 break;
229}
230include("admin-footer.php");
Note: See TracBrowser for help on using the repository browser.