Ticket #9173: 9173-3.diff

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

New patch prevents CP from loading at all in WebKit browsers (not supported) and also avoids a JS error when CP wasn't cached in your browser. Please test/confirm. Esp on Opera/IE/Chrome

  • 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' ); 
     382                $scripts->add_data( 'codepress', 'group', 1 ); 
    381383        } 
    382384} 
    383385 
  • wp-admin/includes/misc.php

     
    272272        return $out; 
    273273} 
    274274 
    275 ?> 
     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 
     318?> 
     319 No newline at end of file 
  • 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); 
     
    100102                } 
    101103 
    102104                $content = htmlspecialchars( $content ); 
     105                $codepress_lang = codepress_get_lang($real_file); 
    103106        } 
    104107 
    105108        ?> 
     
    194197        ?> 
    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 ?>" /> 
    200203                 <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); 
     
    9698                } 
    9799                 
    98100                $content = htmlspecialchars( $content ); 
     101                $codepress_lang = codepress_get_lang($real_file); 
    99102        } 
    100103 
    101104        ?> 
     
    145148<?php   if ( ! $error ) { ?> 
    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 ?>" /> 
    151154                </div>