Make WordPress Core

Changeset 10614


Ignore:
Timestamp:
02/21/2009 02:12:00 AM (17 years ago)
Author:
azaozz
Message:

Add CodePress syntax highlighting to Theme and Plugin editors (first run), props beaulebens, see #9173

Location:
trunk
Files:
44 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/misc.php

    r10607 r10614  
    273273}
    274274
     275/**
     276 * Determines the language to use for CodePress syntax highlighting,
     277 * based only on a filename.
     278 *
     279 * @since 2.8
     280 *
     281 * @param string $filename The name of the file to be highlighting
     282**/
     283function codepress_get_lang( $filename ) {
     284    $codepress_supported_langs = apply_filters( 'codepress_supported_langs',
     285                                    array( 'css' => 'css',
     286                                            'js' => 'javascript',
     287                                            'php' => 'php',
     288                                            'html' => 'html',
     289                                            'htm' => 'html',
     290                                            'txt' => 'text'
     291                                            ) );
     292    $extension = mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 );
     293    return isset( $codepress_supported_langs[$extension] ) ? $codepress_supported_langs[$extension] : 'generic';
     294}
     295
     296/**
     297 * Adds Javascript required to make CodePress work on the theme/plugin editors.
     298 *
     299 * This code is attached to the action admin_print_footer_scripts.
     300 *
     301 * @since 2.8
     302**/
     303function codepress_footer_js() {
     304    // Script-loader breaks CP's automatic path-detection, thus CodePress.path
     305    // CP edits in an iframe, so we need to grab content back into normal form
     306    ?><script type="text/javascript">
     307/* <![CDATA[ */
     308var codepress_path = '<?php echo get_option('home') ?>/wp-includes/js/codepress/';
     309jQuery('#template').submit(function(){
     310    if (jQuery('#newcontent_cp').length)
     311        jQuery('#newcontent_cp').val(newcontent.getCode()).removeAttr('disabled');
     312});
     313/* ]]> */
     314</script>
     315<?php
     316}
     317
    275318?>
  • trunk/wp-admin/plugin-editor.php

    r10607 r10614  
    7575    }
    7676
     77    wp_enqueue_script( 'codepress' );
     78    add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
    7779    require_once('admin-header.php');
    7880
     
    9799       
    98100        $content = htmlspecialchars( $content );
     101        $codepress_lang = codepress_get_lang($real_file);
    99102    }
    100103
     
    146149    <form name="template" id="template" action="plugin-editor.php" method="post">
    147150    <?php wp_nonce_field('edit-plugin_' . $file) ?>
    148         <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
     151        <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
    149152        <input type="hidden" name="action" value="update" />
    150153        <input type="hidden" name="file" value="<?php echo $file ?>" />
  • trunk/wp-admin/theme-editor.php

    r10607 r10614  
    7878        wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
    7979
     80    wp_enqueue_script( 'codepress' );
     81    add_action( 'admin_print_footer_scripts', 'codepress_footer_js' );
    8082    require_once('admin-header.php');
    8183
     
    101103
    102104        $content = htmlspecialchars( $content );
     105        $codepress_lang = codepress_get_lang($real_file);
    103106    }
    104107
     
    195198    <form name="template" id="template" action="theme-editor.php" method="post">
    196199    <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
    197          <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
     200         <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea>
    198201         <input type="hidden" name="action" value="update" />
    199202         <input type="hidden" name="file" value="<?php echo $file ?>" />
  • trunk/wp-includes/script-loader.php

    r10596 r10614  
    378378        $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable', 'jquery-ui-resizable' ), '20090113' );
    379379        $scripts->add_data( 'media', 'group', 1 );
    380 
     380       
     381        $scripts->add( 'codepress', '/wp-includes/js/codepress/codepress.js', false, '0.9.6' );
     382        $scripts->add_data( 'codepress', 'group', 1 );
    381383    }
    382384}
Note: See TracChangeset for help on using the changeset viewer.