mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Add CodePress syntax highlighting to Theme and Plugin editors (first run), props beaulebens, see #9173
git-svn-id: https://develop.svn.wordpress.org/trunk@10614 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -272,4 +272,47 @@ function wp_doc_link_parse( $content ) {
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the language to use for CodePress syntax highlighting,
|
||||
* based only on a filename.
|
||||
*
|
||||
* @since 2.8
|
||||
*
|
||||
* @param string $filename The name of the file to be highlighting
|
||||
**/
|
||||
function codepress_get_lang( $filename ) {
|
||||
$codepress_supported_langs = apply_filters( 'codepress_supported_langs',
|
||||
array( 'css' => 'css',
|
||||
'js' => 'javascript',
|
||||
'php' => 'php',
|
||||
'html' => 'html',
|
||||
'htm' => 'html',
|
||||
'txt' => 'text'
|
||||
) );
|
||||
$extension = mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 );
|
||||
return isset( $codepress_supported_langs[$extension] ) ? $codepress_supported_langs[$extension] : 'generic';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Javascript required to make CodePress work on the theme/plugin editors.
|
||||
*
|
||||
* This code is attached to the action admin_print_footer_scripts.
|
||||
*
|
||||
* @since 2.8
|
||||
**/
|
||||
function codepress_footer_js() {
|
||||
// Script-loader breaks CP's automatic path-detection, thus CodePress.path
|
||||
// CP edits in an iframe, so we need to grab content back into normal form
|
||||
?><script type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
var codepress_path = '<?php echo get_option('home') ?>/wp-includes/js/codepress/';
|
||||
jQuery('#template').submit(function(){
|
||||
if (jQuery('#newcontent_cp').length)
|
||||
jQuery('#newcontent_cp').val(newcontent.getCode()).removeAttr('disabled');
|
||||
});
|
||||
/* ]]> */
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -74,6 +74,8 @@ default:
|
||||
exit;
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -96,6 +98,7 @@ default:
|
||||
}
|
||||
|
||||
$content = htmlspecialchars( $content );
|
||||
$codepress_lang = codepress_get_lang($real_file);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -145,7 +148,7 @@ default:
|
||||
<?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"><?php echo $content ?></textarea>
|
||||
<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="hidden" name="file" value="<?php echo $file ?>" />
|
||||
</div>
|
||||
@@ -178,4 +181,4 @@ default:
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
include("admin-footer.php") ?>
|
||||
include("admin-footer.php") ?>
|
||||
|
||||
@@ -77,6 +77,8 @@ default:
|
||||
if ( !current_user_can('edit_themes') )
|
||||
wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
|
||||
|
||||
wp_enqueue_script( 'codepress' );
|
||||
add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
|
||||
require_once('admin-header.php');
|
||||
|
||||
update_recently_edited($file);
|
||||
@@ -100,6 +102,7 @@ default:
|
||||
}
|
||||
|
||||
$content = htmlspecialchars( $content );
|
||||
$codepress_lang = codepress_get_lang($real_file);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -194,7 +197,7 @@ if ($allowed_files) :
|
||||
?>
|
||||
<form name="template" id="template" action="theme-editor.php" method="post">
|
||||
<?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
|
||||
<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
|
||||
<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="hidden" name="file" value="<?php echo $file ?>" />
|
||||
<input type="hidden" name="theme" value="<?php echo $theme ?>" />
|
||||
|
||||
Reference in New Issue
Block a user