web/wp-admin/plugin-editor.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
     7  */
     7  */
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once('admin.php');
    10 require_once('admin.php');
    11 
    11 
       
    12 if ( !current_user_can('edit_plugins') )
       
    13 	wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
       
    14 
    12 $title = __("Edit Plugins");
    15 $title = __("Edit Plugins");
    13 $parent_file = 'plugins.php';
    16 $parent_file = 'plugins.php';
    14 
    17 
    15 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
    18 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin'));
    16 
    19 
    17 wp_admin_css( 'theme-editor' );
    20 wp_admin_css( 'theme-editor' );
    18 
    21 
    19 $plugins = get_plugins();
    22 $plugins = get_plugins();
    20 
    23 
    21 if ( isset($_REQUEST['file']) )
    24 if ( isset($_REQUEST['file']) )
    22 	$plugin = $_REQUEST['file'];
    25 	$plugin = stripslashes($_REQUEST['file']);
    23 
    26 
    24 if ( empty($plugin) ) {
    27 if ( empty($plugin) ) {
    25 	$plugin = array_keys($plugins);
    28 	$plugin = array_keys($plugins);
    26 	$plugin = $plugin[0];
    29 	$plugin = $plugin[0];
    27 }
    30 }
    28 
    31 
    29 $plugin_files = get_plugin_files($plugin);
    32 $plugin_files = get_plugin_files($plugin);
    30 
    33 
    31 if ( empty($file) )
    34 if ( empty($file) )
    32 	$file = $plugin_files[0];
    35 	$file = $plugin_files[0];
       
    36 else
       
    37 	$file = stripslashes($file);
    33 
    38 
    34 $file = validate_file_to_edit($file, $plugin_files);
    39 $file = validate_file_to_edit($file, $plugin_files);
    35 $real_file = WP_PLUGIN_DIR . '/' . $file;
    40 $real_file = WP_PLUGIN_DIR . '/' . $file;
       
    41 $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
    36 
    42 
    37 switch ( $action ) {
    43 switch ( $action ) {
    38 
    44 
    39 case 'update':
    45 case 'update':
    40 
    46 
    41 	check_admin_referer('edit-plugin_' . $file);
    47 	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 
    48 
    46 	$newcontent = stripslashes($_POST['newcontent']);
    49 	$newcontent = stripslashes($_POST['newcontent']);
    47 	if ( is_writeable($real_file) ) {
    50 	if ( is_writeable($real_file) ) {
    48 		$f = fopen($real_file, 'w+');
    51 		$f = fopen($real_file, 'w+');
    49 		fwrite($f, $newcontent);
    52 		fwrite($f, $newcontent);
    51 
    54 
    52 		// Deactivate so we can test it.
    55 		// Deactivate so we can test it.
    53 		if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
    56 		if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
    54 			if ( is_plugin_active($file) )
    57 			if ( is_plugin_active($file) )
    55 				deactivate_plugins($file, true);
    58 				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"));
    59 			wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto"));
    57 			exit;
    60 			exit;
    58 		}
    61 		}
    59 		wp_redirect("plugin-editor.php?file=$file&a=te");
    62 		wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
    60 	} else {
    63 	} else {
    61 		wp_redirect("plugin-editor.php?file=$file");
    64 		wp_redirect("plugin-editor.php?file=$file&scrollto=$scrollto");
    62 	}
    65 	}
    63 	exit;
    66 	exit;
    64 
    67 
    65 break;
    68 break;
    66 
    69 
    67 default:
    70 default:
    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 
    71 
    72 	if ( isset($_GET['liveupdate']) ) {
    72 	if ( isset($_GET['liveupdate']) ) {
    73 		check_admin_referer('edit-plugin-test_' . $file);
    73 		check_admin_referer('edit-plugin-test_' . $file);
    74 
    74 
    75 		$error = validate_plugin($file);
    75 		$error = validate_plugin($file);
    77 			wp_die( $error );
    77 			wp_die( $error );
    78 
    78 
    79 		if ( ! is_plugin_active($file) )
    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
    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 
    81 
    82 		wp_redirect("plugin-editor.php?file=$file&a=te");
    82 		wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
    83 		exit;
    83 		exit;
    84 	}
    84 	}
    85 
    85 
    86 	// List of allowable extensions
    86 	// List of allowable extensions
    87 	$editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
    87 	$editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
   200 	<?php wp_nonce_field('edit-plugin_' . $file) ?>
   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>
   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" />
   202 		<input type="hidden" name="action" value="update" />
   203 		<input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
   203 		<input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
   204 		<input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
   204 		<input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
       
   205 		<input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
   205 		</div>
   206 		</div>
   206 		<?php if ( !empty( $docs_select ) ) : ?>
   207 		<?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 		<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 endif; ?>
   209 <?php if ( is_writeable($real_file) ) : ?>
   210 <?php if ( is_writeable($real_file) ) : ?>
   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 	<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 <?php endif; ?>
   224 </form>
   225 </form>
   225 <br class="clear" />
   226 <br class="clear" />
   226 </div>
   227 </div>
       
   228 <script type="text/javascript">
       
   229 /* <![CDATA[ */
       
   230 jQuery(document).ready(function($){
       
   231 	$('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
       
   232 	$('#newcontent').scrollTop( $('#scrollto').val() );
       
   233 });
       
   234 /* ]]> */
       
   235 </script>
   227 <?php
   236 <?php
   228 	break;
   237 	break;
   229 }
   238 }
   230 include("admin-footer.php");
   239 include("admin-footer.php");