Ticket #9173: 9173.diff

File 9173.diff, 4.7 KB (added by beaulebens, 3 years ago)

Add CodePress support. You MUST download the CodePress library itself separately still.

  • wp-includes/script-loader.php

     
    377377 
    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' ); 
    381382        } 
    382383} 
    383384 
  • wp-admin/includes/misc.php

     
    238238        echo "<p>$message</p>\n"; 
    239239} 
    240240 
     241/** 
     242 * Determines the language to use for CodePress syntax highlighting, 
     243 * based only on a filename. 
     244 *  
     245 * @since 2.8 
     246 *  
     247 * @param string $filename The name of the file to be highlighting 
     248**/ 
     249function codepress_get_lang( $filename ) { 
     250        $codepress_supported_langs = apply_filters( 'codepress_supported_langs',  
     251                                                                        array( 'css' => 'css', 
     252                                                                                        'js' => 'javascript',  
     253                                                                                        'php' => 'php',  
     254                                                                                        'html' => 'html',  
     255                                                                                        'htm' => 'html',  
     256                                                                                        'txt' => 'text'  
     257                                                                                        ) ); 
     258        $extension = mb_substr( $filename, mb_strrpos( $filename, '.' ) + 1 ); 
     259        return isset( $codepress_supported_langs[$extension] ) ? $codepress_supported_langs[$extension] : 'generic'; 
     260} 
     261 
     262/** 
     263 * Adds Javascript required to make CodePress work on the theme/plugin editors. 
     264 *  
     265 * This code is attached to the action admin_print_footer_scripts. 
     266 *  
     267 * @since 2.8 
     268**/ 
     269function codepress_footer_js() { 
     270        // Script-loader breaks CP's automatic path-detection, thus CodePress.path 
     271        // CP edits in an iframe, so we need to grab content back into normal form 
     272        ?><script type="text/javascript"> 
     273/* <![CDATA[ */ 
     274CodePress.path = '<?php echo get_option('siteurl') ?>/wp-includes/js/codepress/'; 
     275jQuery('#template').submit(function(){ 
     276        jQuery('#newcontent_cp').val(newcontent.getCode()).removeAttr('disabled'); 
     277}); 
     278/* ]]> */ 
     279</script> 
     280<?php 
     281} 
     282 
    241283?> 
  • wp-admin/theme-editor.php

     
    7777        if ( !current_user_can('edit_themes') ) 
    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 
    8284        update_recently_edited($file); 
     
    8890                $f = fopen($real_file, 'r'); 
    8991                $content = fread($f, filesize($real_file)); 
    9092                $content = htmlspecialchars($content); 
     93                $codepress_lang = codepress_get_lang($real_file); 
    9194        } 
    9295 
    9396        ?> 
     
    182185        ?> 
    183186        <form name="template" id="template" action="theme-editor.php" method="post"> 
    184187        <?php wp_nonce_field('edit-theme_' . $file . $theme) ?> 
    185                  <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
     188                 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea> 
    186189                 <input type="hidden" name="action" value="update" /> 
    187190                 <input type="hidden" name="file" value="<?php echo $file ?>" /> 
    188191                 <input type="hidden" name="theme" value="<?php echo $theme ?>" /> 
  • wp-admin/plugin-editor.php

     
    7474                exit; 
    7575        } 
    7676 
     77        wp_enqueue_script( 'codepress' ); 
     78        add_action( 'admin_print_footer_scripts', 'codepress_footer_js' ); 
    7779        require_once('admin-header.php'); 
    7880 
    7981        update_recently_edited(WP_PLUGIN_DIR . '/' . $file); 
     
    8183        if ( ! is_file($real_file) ) 
    8284                $error = 1; 
    8385 
    84         if ( ! $error ) 
     86        if ( ! $error ) { 
    8587                $content = htmlspecialchars(file_get_contents($real_file)); 
     88                $codepress_lang = codepress_get_lang($real_file); 
     89        } 
    8690 
    8791        ?> 
    8892<?php if (isset($_GET['a'])) : ?> 
     
    131135<?php   if ( ! $error ) { ?> 
    132136        <form name="template" id="template" action="plugin-editor.php" method="post"> 
    133137        <?php wp_nonce_field('edit-plugin_' . $file) ?> 
    134                 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
     138                <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea> 
    135139                <input type="hidden" name="action" value="update" /> 
    136140                <input type="hidden" name="file" value="<?php echo $file ?>" /> 
    137141                </div>