Die on file error. Cleanup. Props hakre. fixes #9452

git-svn-id: http://svn.automattic.com/wordpress/trunk@11214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-05-06 04:08:13 +00:00
parent c0f2a493ee
commit d3ef269013
1 changed files with 23 additions and 32 deletions

View File

@ -85,29 +85,27 @@ default:
wp_enqueue_script( 'codepress' );
add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
require_once('admin-header.php');
update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
// List of allowable extensions
$editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
$extra_extensions = apply_filters('editable_extensions', null);
if ( is_array($extra_extensions) )
$editable_extensions = array_merge($editable_extensions, $extra_extensions);
$editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
if ( ! is_file($real_file) ) {
$error = __('No such file exists! Double check the name and try again.');
wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
} else {
// Get the extension of the file
if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
$ext = strtolower($matches[1]);
// If extension is not in the acceptable list, skip it
if ( !in_array( $ext, $editable_extensions) )
$error = __('Files of this type are not editable.');
wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
}
}
if ( ! $error ) {
require_once('admin-header.php');
update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
$content = file_get_contents( $real_file );
if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) {
@ -123,7 +121,6 @@ default:
$content = htmlspecialchars( $content );
$codepress_lang = codepress_get_lang($real_file);
}
?>
<?php if (isset($_GET['a'])) : ?>
@ -141,7 +138,7 @@ default:
<h2><?php echo wp_specialchars( $title ); ?></h2>
<div class="bordertitle">
<form id="themeselector" action="plugin-editor.php" method="post">
<strong><label for="theme"><?php _e('Select plugin to edit:'); ?> </label></strong>
<strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong>
<select name="plugin" id="plugin">
<?php
foreach ( $plugins as $plugin_key => $a_plugin ) {
@ -195,11 +192,10 @@ foreach ( $plugin_files as $plugin_file ) :
continue;
}
?>
<li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>&plugin=<?php echo $plugin; ?>"><?php echo $plugin_file ?></a></li>
<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>
<?php endforeach; ?>
</ul>
</div>
<?php if ( ! $error ) { ?>
<form name="template" id="template" action="plugin-editor.php" method="post">
<?php wp_nonce_field('edit-plugin_' . $file) ?>
<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
@ -208,7 +204,7 @@ foreach ( $plugin_files as $plugin_file ) :
<input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
</div>
<?php if ( count( $functions ) ) : ?>
<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() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div>
<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>
<?php endif; ?>
<?php if ( is_writeable($real_file) ) : ?>
<?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
@ -226,11 +222,6 @@ foreach ( $plugin_files as $plugin_file ) :
<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>
<?php endif; ?>
</form>
<?php
} else {
echo '<div class="error"><p>' . $error . '</p></div>';
}
?>
<div class="clear"> &nbsp; </div>
</div>
<?php