Make WordPress Core

Changeset 6789


Ignore:
Timestamp:
02/11/2008 05:45:18 PM (16 years ago)
Author:
ryan
Message:

New gzip compressor for TinyMCE from azaozz. fixes #5807

Location:
trunk/wp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-filters.php

    r6712 r6789  
    144144add_filter('option_home', '_config_wp_home');
    145145add_filter('option_siteurl', '_config_wp_siteurl');
    146 add_filter('mce_plugins', '_mce_load_rtl_plugin');
    147 add_filter('mce_buttons', '_mce_add_direction_buttons');
     146add_filter('tiny_mce_before_init', '_mce_set_direction');
    148147add_filter('pre_kses', 'wp_pre_kses_less_than');
    149148add_filter('sanitize_title', 'sanitize_title_with_dashes');
     
    174173add_action('sanitize_comment_cookies', 'sanitize_comment_cookies');
    175174add_action('admin_print_scripts', 'wp_print_scripts', 20);
    176 add_action('mce_options', '_mce_set_direction');
    177175add_action('init', 'smilies_init', 5);
    178176add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
  • trunk/wp-includes/functions.php

    r6786 r6789  
    13831383
    13841384
    1385 function _mce_set_direction() {
     1385function _mce_set_direction( $input ) {
    13861386    global $wp_locale;
    13871387
    13881388    if ( 'rtl' == $wp_locale->text_direction ) {
    1389         echo 'directionality : "rtl" ,';
    1390         echo 'theme_advanced_toolbar_align : "right" ,';
    1391     }
    1392 }
    1393 
    1394 
    1395 function _mce_load_rtl_plugin( $input ) {
    1396     global $wp_locale;
    1397 
    1398     if ( 'rtl' == $wp_locale->text_direction )
    1399         $input[] = 'directionality';
    1400 
    1401     return $input;
    1402 }
    1403 
    1404 
    1405 function _mce_add_direction_buttons( $input ) {
    1406     global $wp_locale;
    1407 
    1408     if ( 'rtl' == $wp_locale->text_direction ) {
    1409         $new_buttons = array( 'separator', 'ltr', 'rtl' );
    1410         $input = array_merge( $input, $new_buttons );
     1389        $input['directionality'] = 'rtl';
     1390        $input['theme_advanced_toolbar_align'] = 'right';
     1391        $input['plugins'] .= ',directionality';
     1392        $input['theme_advanced_buttons2'] .= ',|,ltr,rtl';
    14111393    }
    14121394
  • trunk/wp-includes/js/tinymce/tiny_mce_config.php

    r6765 r6789  
    1 <?php
    2     @ require('../../../wp-config.php');
    3     cache_javascript_headers();
    4 
    5     // deprecated
    6     function wp_translate_tinymce_lang($text) {
    7         if ( ! function_exists('__') ) {
    8             return $text;
    9         } else {
    10             $search1 = "/^tinyMCELang\\[(['\"])(.*)\\1\]( ?= ?)(['\"])(.*)\\4/Uem";
    11             $replace1 = "'tinyMCELang[\\1\\2\\1]\\3'.stripslashes('\\4').__('\\5').stripslashes('\\4')";
    12 
    13             $search2 = "/ : (['\"])(.*)\\1/Uem";
    14             $replace2 = "' : '.stripslashes('\\1').__('\\2').stripslashes('\\1')";
    15 
    16             $search = array($search1, $search2);
    17             $replace = array($replace1, $replace2);
    18 
    19             $text = preg_replace($search, $replace, $text);
    20 
    21             return $text;
     1<?php
     2// some code below is from:
     3/**
     4 * $Id: tiny_mce_gzip.php 315 2007-10-25 14:03:43Z spocke $
     5 *
     6 * @author Moxiecode
     7 * @copyright Copyright © 2005-2006, Moxiecode Systems AB, All rights reserved.
     8 *
     9 * This file compresses the TinyMCE JavaScript using GZip.
     10 **/
     11 
     12@ require('../../../wp-config.php');
     13
     14function getFileContents($path) {
     15    $path = realpath($path);
     16
     17    if ( ! $path || ! @is_file($path) )
     18        return '';
     19
     20    if ( function_exists('file_get_contents') )
     21        return @file_get_contents($path);
     22
     23    $content = '';
     24    $fp = @fopen($path, 'r');
     25    if ( ! $fp )
     26        return '';
     27
     28    while ( ! feof($fp) )
     29        $content .= fgets($fp);
     30
     31    fclose($fp);
     32    return $content;
     33}
     34
     35function putFileContents( $path, $content ) {
     36    if ( function_exists('file_put_contents') )
     37        return @file_put_contents( $path, $content );
     38
     39    $fp = @fopen( $path, 'wb' );
     40    if ($fp) {
     41        fwrite( $fp, $content );
     42        fclose($fp);
     43    }
     44}
     45
     46// Set up init variables
     47$https = ( isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ) ? true : false;
     48   
     49$baseurl = get_option('siteurl') . '/wp-includes/js/tinymce';
     50$baseurl = $https ? str_replace('http://', 'https://', $baseurl) : $baseurl;
     51
     52$mce_css = $baseurl . '/wordpress.css';
     53$mce_css = apply_filters('mce_css', $mce_css);
     54$mce_css = $https ? str_replace('http://', 'https://', $mce_css) : $mce_css;
     55
     56$valid_elements = '*[*]';
     57$valid_elements = apply_filters('mce_valid_elements', $valid_elements);
     58   
     59$invalid_elements = apply_filters('mce_invalid_elements', '');
     60
     61$plugins = array( 'safari', 'inlinepopups', 'autosave', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen' );
     62
     63/*
     64The following filter takes an associative array of external plugins for TinyMCE in the form "name" => "url".
     65It adds the plugin's name (including the required dash) to TinyMCE's plugins init and the call to PluginManager to load the plugin.
     66The url should be absolute and should include the js file name to be loaded.
     67Example: array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' ).
     68If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
     69*/
     70$mce_external_plugins = apply_filters('mce_external_plugins', array());
     71
     72$ext_plugins = "\n";
     73foreach ( $mce_external_plugins as $name => $url ) {
     74    $plugins[] = '-' . $name;
     75    $url = $https ? str_replace('http://', 'https://', $url) : $url;
     76   
     77    $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
     78}
     79
     80$plugins = implode($plugins, ',');
     81
     82$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'outdent', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'image', 'wp_more', '|', 'spellchecker', '|', 'wp_help', 'wp_adv' ));
     83$mce_buttons = implode($mce_buttons, ',');
     84
     85$mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', '|', 'removeformat', 'cleanup', '|', 'media', 'charmap', 'blockquote', '|', 'undo', 'redo', 'fullscreen' ));
     86$mce_buttons_2 = implode($mce_buttons_2, ',');
     87
     88$mce_buttons_3 = apply_filters('mce_buttons_3', array());
     89$mce_buttons_3 = implode($mce_buttons_3, ',');
     90   
     91$mce_buttons_4 = apply_filters('mce_buttons_4', array());
     92$mce_buttons_4 = implode($mce_buttons_4, ',');
     93
     94// all these browsers are now 100% supported, no need for this
     95//$mce_browsers = apply_filters('mce_browsers', array('msie', 'gecko', 'opera', 'safari'));
     96//$mce_browsers = implode($mce_browsers, ',');
     97
     98$mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
     99
     100// TinyMCE init settings
     101$initArray = array (
     102    'mode' => 'none',
     103    'onpageload' => 'wpEditorInit',
     104    'width' => '100%',
     105    'theme' => 'advanced',
     106    'skin' => 'wp_theme',
     107    'theme_advanced_buttons1' => "$mce_buttons",
     108    'theme_advanced_buttons2' => "$mce_buttons_2",
     109    'theme_advanced_buttons3' => "$mce_buttons_3",
     110    'theme_advanced_buttons4' => "$mce_buttons_4",
     111    'language' => "$mce_locale",
     112    'theme_advanced_toolbar_location' => 'top',
     113    'theme_advanced_toolbar_align' => 'left',
     114    'theme_advanced_statusbar_location' => 'bottom',
     115    'theme_advanced_resizing' => true,
     116    'theme_advanced_resize_horizontal' => false,
     117//  'browsers' => "$mce_browsers",
     118    'dialog_type' => 'modal',
     119    'convert_urls' => false,
     120    'relative_urls' => false,
     121    'remove_script_host' => false,
     122    'fix_list_elements' => true,
     123    'fix_table_elements' => true,
     124    'gecko_spellcheck' => true,
     125    'entities' => '38,amp,60,lt,62,gt',
     126    'accessibility_focus' => false,
     127    'tab_focus' => ':next',
     128    'content_css' => "$mce_css",
     129    'save_callback' => 'switchEditors.saveCallback',
     130    'plugins' => "$plugins",
     131    // pass-through the settings for compression and caching, so they can be changed with "tiny_mce_before_init"
     132    'disk_cache' => true,
     133    'compress' => true,
     134    'del_old_cache' => true
     135);
     136
     137if ( $valid_elements ) $initArray['valid_elements'] = $valid_elements;
     138if ( $invalid_elements ) $initArray['invalid_elements'] = $invalid_elements;
     139
     140// For people who really REALLY know what they're doing with TinyMCE
     141// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
     142$initArray = apply_filters('tiny_mce_before_init', $initArray); // changed from action to filter
     143
     144// support for deprecated actions
     145ob_start();
     146do_action('mce_options');
     147$mce_deprecated1 = ob_get_contents() || '';
     148ob_end_clean();
     149
     150/*
     151// Do we need to support this? Most likely will breal TinyMCE 3...
     152ob_start();
     153do_action('tinymce_before_init');
     154$mce_deprecated2 = ob_get_contents() || '';
     155ob_end_clean();
     156*/
     157
     158// Settings for the gzip compression and cache
     159$cache_path = dirname(__FILE__); // Cache path, this is where the .gz files will be stored
     160$cache_ext = '.js';
     161
     162$disk_cache = ( ! isset($initArray['disk_cache']) || false == $initArray['disk_cache'] ) ? false : true;
     163$compress = ( ! isset($initArray['compress']) || false == $initArray['compress'] ) ? false : true;
     164$del_old_cache = ( ! isset($initArray['del_old_cache']) || false == $initArray['del_old_cache'] ) ? false : true;
     165
     166$initArray['disk_cache'] = $initArray['compress'] = $initArray['del_old_cache'] = null;
     167unset( $initArray['disk_cache'], $initArray['compress'], $initArray['del_old_cache'] );
     168
     169$plugins = explode( ',', $initArray['plugins'] );
     170$theme = ( 'simple' == $initArray['theme'] ) ? 'simple' : 'advanced';
     171$language = isset($initArray['language']) ? substr( $initArray['language'], 0, 2 ) : 'en';
     172$enc = $cacheKey = $suffix = $mce_options = '';
     173
     174// Custom extra javascripts to pack
     175$custom_js = array(); //$custom_js = apply_filters('tinymce_custom_js', array());
     176
     177// Check if supports gzip
     178if ( $compress && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
     179    $encodings = explode( ',', strtolower( preg_replace('/\s+/', '', $_SERVER['HTTP_ACCEPT_ENCODING']) ) );
     180
     181    if ( (in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------']) ) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression') ) {
     182        $enc = in_array('x-gzip', $encodings) ? 'x-gzip' : 'gzip';
     183        $cache_ext = '.gz';
     184    }
     185}
     186
     187// Setup cache info
     188if ( $disk_cache && $cache_path ) {
     189
     190    $ver = isset($_GET['ver']) ? (int) $_GET['ver'] : '';
     191    $cacheKey = $initArray['plugins'] . $language . $theme . $suffix . $ver;
     192
     193    foreach ( $custom_js as $file )
     194        $cacheKey .= $file;
     195
     196    $cacheKey = md5( $cacheKey );
     197    $cache_file = $cache_path . '/tiny_mce_' . $cacheKey . $cache_ext;
     198}
     199
     200cache_javascript_headers();
     201
     202// Use cached file if exists
     203if ( $disk_cache && file_exists($cache_file) ) {
     204    if ( '.gz' == $cache_ext )
     205        header( 'Content-Encoding: ' . $enc );
     206
     207    echo getFileContents( $cache_file );
     208    exit;
     209}
     210
     211foreach ( $initArray as $k => $v )
     212    $mce_options .= $k . ':"' . $v . '", ';
     213
     214$mce_options .= $mce_deprecated1;
     215$mce_options = rtrim( trim($mce_options), '\n\r,' );
     216
     217$content = 'var tinyMCEPreInit = { suffix : "' . $suffix . '", base : "' . $baseurl . '" };';
     218$content .= 'var tinyMCE_GZ = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false, suffix : "' . $suffix . '" }, baseURL : "' . $baseurl . '" };';
     219
     220// Load patch
     221$content .= getFileContents( 'tiny_mce_ext.js' );
     222
     223// Add core
     224$content .= getFileContents( 'tiny_mce' . $suffix . '.js' );
     225
     226// Patch loading functions
     227$content .= 'tinyMCE_GZ.start();';
     228
     229// Add all languages (WP)
     230include_once( dirname(__FILE__).'/langs/wp-langs.php' );
     231$content .= $strings;
     232
     233// Add themes
     234$content .= getFileContents( 'themes/' . $theme . '/editor_template' . $suffix . '.js' );
     235
     236// Add plugins
     237foreach ( $plugins as $plugin )
     238    $content .= getFileContents( 'plugins/' . $plugin . '/editor_plugin' . $suffix . '.js' );
     239
     240// Add custom files
     241foreach ( $custom_js as $file )
     242    $content .= getFileContents($file);
     243
     244// Add external plugins and init
     245$content .= $ext_plugins . 'tinyMCE.init({' . $mce_options . '});'; // $mce_deprecated2 .
     246
     247// Generate GZIP'd content
     248if ( '.gz' == $cache_ext ) {
     249    header('Content-Encoding: ' . $enc);
     250    $cache_data = gzencode( $content, 9, FORCE_GZIP );
     251} else
     252    $cache_data = $content;
     253
     254// Stream to client
     255echo $cache_data;
     256
     257// Write file
     258if ( '' != $cacheKey ) {
     259    if ( $del_old_cache ) {
     260        $old_key = getFileContents('tiny_mce_compressed_key');
     261           
     262        if ( '' != $old_key ) { //  && $old_key != $cacheKey
     263            $old_cache = $cache_path . '/tiny_mce_' . $old_key . $cache_ext;
     264            @unlink($old_cache);
    22265        }
     266           
     267        putFileContents( 'tiny_mce_compressed_key', $cacheKey );
    23268    }
    24 
    25     // Set up init variables
    26     $valid_elements = '*[*]';
    27     $valid_elements = apply_filters('mce_valid_elements', $valid_elements);
    28 
    29     $invalid_elements = apply_filters('mce_invalid_elements', '');
    30 
    31     $plugins = array( 'safari', 'inlinepopups', 'autosave', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen' );
    32     $plugins = apply_filters('mce_plugins', $plugins);
    33     $plugins = implode($plugins, ',');
    34 
    35     $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'outdent', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'image', 'wp_more', '|', 'spellchecker', '|', 'wp_help', 'wp_adv' ));
    36     $mce_buttons = implode($mce_buttons, ',');
    37 
    38 
    39     $mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', '|', 'removeformat', 'cleanup', '|', 'media', 'charmap', 'blockquote', '|', 'undo', 'redo', 'fullscreen' ));
    40     $mce_buttons_2 = implode($mce_buttons_2, ',');
    41 
    42     $mce_buttons_3 = apply_filters('mce_buttons_3', array());
    43     $mce_buttons_3 = implode($mce_buttons_3, ',');
    44 
    45     $mce_buttons_4 = apply_filters('mce_buttons_4', array());
    46     $mce_buttons_4 = implode($mce_buttons_4, ',');
    47 
    48     $mce_browsers = apply_filters('mce_browsers', array('msie', 'gecko', 'opera', 'safari'));
    49     $mce_browsers = implode($mce_browsers, ',');
    50 
    51     $mce_css = get_option('siteurl') . '/wp-includes/js/tinymce/wordpress.css';
    52     $mce_css = apply_filters('mce_css', $mce_css);
    53     if ( $_SERVER['HTTPS'] == 'on' )
    54         $mce_css = str_replace('http://', 'https://', $mce_css);
    55 
    56     $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
     269       
     270    putFileContents( $cache_file, $cache_data );
     271}
    57272?>
    58 
    59 initArray = {
    60     mode : "none",
    61     onpageload : "wpEditorInit",
    62     width : "100%",
    63     theme : "advanced",
    64     skin : "wp_theme",
    65     theme_advanced_buttons1 : "<?php echo $mce_buttons; ?>",
    66     theme_advanced_buttons2 : "<?php echo $mce_buttons_2; ?>",
    67     theme_advanced_buttons3 : "<?php echo $mce_buttons_3; ?>",
    68     theme_advanced_buttons4 : "<?php echo $mce_buttons_4; ?>",
    69     language : "<?php echo $mce_locale; ?>",
    70     theme_advanced_toolbar_location : "top",
    71     theme_advanced_toolbar_align : "left",
    72     theme_advanced_statusbar_location : "bottom",
    73     theme_advanced_resizing : true,
    74     browsers : "<?php echo $mce_browsers; ?>",
    75     dialog_type : "modal",
    76     theme_advanced_resize_horizontal : false,
    77     convert_urls : false,
    78     relative_urls : false,
    79     remove_script_host : false,
    80     fix_list_elements : true,
    81     fix_table_elements : true,
    82     gecko_spellcheck : true,
    83     entities : "38,amp,60,lt,62,gt",
    84     accessibility_focus : false,
    85     tab_focus : ":next",
    86     content_css : "<?php echo $mce_css; ?>",
    87     <?php if ( $valid_elements ) echo 'valid_elements : "' . $valid_elements . '",' . "\n"; ?>
    88     <?php if ( $invalid_elements ) echo 'invalid_elements : "' . $invalid_elements . '",' . "\n"; ?>
    89     save_callback : "switchEditors.saveCallback",
    90 <?php do_action('mce_options'); ?>
    91     plugins : "<?php echo $plugins; ?>"
    92 };
    93 
    94 <?php
    95     // For people who really REALLY know what they're doing with TinyMCE
    96     // You can modify initArray to add, remove, change elements of the config before tinyMCE.init
    97     do_action('tinymce_before_init');
    98 ?>
    99 
    100 tinyMCE_GZ.init(initArray);
  • trunk/wp-includes/js/tinymce/tiny_mce_gzip.php

    r6765 r6789  
    1 <?php
    2 /** Based on:
    3  * $Id: tiny_mce_gzip.php 315 2007-10-25 14:03:43Z spocke $
    4  *
    5  * @author Moxiecode
    6  * @copyright Copyright © 2005-2006, Moxiecode Systems AB, All rights reserved.
    7  *
    8  * This file compresses the TinyMCE JavaScript using GZip and
    9  * enables the browser to do two requests instead of one for each .js file.
    10  * Notice: This script defaults the button_tile_map option to true for extra performance.
    11  */
    12 
    13 @require_once('../../../wp-config.php');  // For get_bloginfo().
    14 cache_javascript_headers();
    15 
    16 if ( isset($_GET['load']) ) {
    17 
    18     function getParam( $name, $def = false ) {
    19         if ( ! isset($_GET[$name]) )
    20             return $def;
    21 
    22         return preg_replace( "/[^0-9a-z\-_,]+/i", "", $_GET[$name] ); // Remove anything but 0-9,a-z,-_
    23     }
    24 
    25     function getFileContents($path) {
    26         $path = realpath($path);
    27 
    28         if ( ! $path || !@is_file($path) )
    29             return '';
    30 
    31         if ( function_exists('file_get_contents') )
    32             return @file_get_contents($path);
    33 
    34         $content = '';
    35         $fp = @fopen( $path, 'r' );
    36         if (!$fp)
    37             return '';
    38 
    39         while ( ! feof($fp) )
    40             $content .= fgets($fp);
    41 
    42         fclose($fp);
    43 
    44         return $content;
    45     }
    46 
    47     function putFileContents( $path, $content ) {
    48         if ( function_exists('file_put_contents') )
    49             return @file_put_contents( $path, $content );
    50 
    51         $fp = @fopen($path, 'wb');
    52         if ($fp) {
    53             fwrite($fp, $content);
    54             fclose($fp);
    55         }
    56     }
    57 
    58     // WP defaults
    59     $themes = explode( ',', getParam('themes', 'advanced') );
    60 
    61     $language = getParam( 'languages', 'en' );
    62     $language = strtolower( substr($language, 0, 2) ); // only ISO 639-1
    63 
    64     $plugins = explode( ',', getParam('plugins', '') );
    65     $cachePath = realpath('.'); // Cache path, this is where the .gz files will be stored
    66 
    67     $encodings = array();
    68     $supportsGzip = $diskCache = false;
    69     $compress = $core = true;
    70     $suffix = $content = $enc = $cacheKey = '';
    71 
    72     // Custom extra javascripts to pack
    73     // WP - add a hook for external plugins to be compressed too?
    74     $custom = array(/*
    75         'some custom .js file',
    76         'some custom .js file'
    77     */);
    78 
    79     // Setup cache info
    80     if ( $diskCache ) {
    81         if ( ! $cachePath )
    82             die('Real path failed.');
    83 
    84         $cacheKey = getParam( 'plugins', '' ) . getParam( 'languages', '' ) . getParam( 'themes', '' ) . $suffix;
    85 
    86         foreach ( $custom as $file )
    87             $cacheKey .= $file;
    88 
    89         $cacheKey = md5($cacheKey);
    90 
    91         if ( $compress )
    92             $cacheFile = $cachePath . '/tiny_mce_' . $cacheKey . '.gz';
    93         else
    94             $cacheFile = $cachePath . '/tiny_mce_' . $cacheKey . '.js';
    95     }
    96 
    97     // Check if it supports gzip
    98     if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) )
    99         $encodings = explode(',', strtolower(preg_replace( '/\s+/', '', $_SERVER['HTTP_ACCEPT_ENCODING']) ) );
    100 
    101     if ( ( in_array('gzip', $encodings ) || in_array( 'x-gzip', $encodings ) || isset($_SERVER['---------------']) ) && function_exists( 'ob_gzhandler' ) && ! ini_get('zlib.output_compression') ) {
    102         $enc = in_array( 'x-gzip', $encodings ) ? 'x-gzip' : 'gzip';
    103         $supportsGzip = true;
    104     }
    105 
    106     // Use cached file disk cache
    107     if ( $diskCache && $supportsGzip && file_exists($cacheFile) ) {
    108         if ( $compress )
    109             header('Content-Encoding: ' . $enc);
    110 
    111         echo getFileContents( $cacheFile );
    112         die();
    113     }
    114 
    115     // Add core
    116     if ( $core == 'true' ) {
    117         $content .= getFileContents( 'tiny_mce' . $suffix . '.js' );
    118 
    119         // Patch loading functions
    120         $content .= 'tinyMCE_GZ.start();';
    121     }
    122 
    123     // Add all languages (WP)
    124     include_once( dirname(__file__).'/langs/wp-langs.php' );
    125     $content .= $strings;
    126 
    127     // Add themes
    128     foreach ( $themes as $theme )
    129         $content .= getFileContents( 'themes/' . $theme . '/editor_template' . $suffix . '.js' );
    130    
    131     // Add plugins
    132     foreach ( $plugins as $plugin )
    133         $content .= getFileContents( 'plugins/' . $plugin . '/editor_plugin' . $suffix . '.js' );
    134 
    135     // Add custom files
    136     foreach ( $custom as $file )
    137         $content .= getFileContents($file);
    138 
    139     // Restore loading functions
    140     if ( $core == 'true' )
    141         $content .= 'tinyMCE_GZ.end();';
    142 
    143     // Generate GZIP'd content
    144     if ( $supportsGzip ) {
    145         if ( $compress ) {
    146             header('Content-Encoding: ' . $enc);
    147             $cacheData = gzencode( $content, 9, FORCE_GZIP );
    148         } else
    149             $cacheData = $content;
    150 
    151         // Write gz file
    152         if ( $diskCache && '' != $cacheKey )
    153             putFileContents( $cacheFile, $cacheData );
    154 
    155         // Stream to client
    156         echo $cacheData;
    157     } else {
    158         // Stream uncompressed content
    159         echo $content;
    160     }
    161 
    162     exit;
    163 }
    164 ?>
    165 
    166 var tinyMCEPreInit = {suffix : ''};
    167 
    168 var tinyMCE_GZ = {
    169     settings : {
    170         themes : '',
    171         plugins : '',
    172         languages : '',
    173         disk_cache : false,
    174         page_name : 'tiny_mce_gzip.php',
    175         debug : false,
    176         suffix : ''
    177     },
    178 
    179     opt : {},
    180 
    181     init : function(o, cb) {
    182         var t = this, n, s = t.settings, nl = document.getElementsByTagName('script');
    183 
    184         t.opt = o;
    185 
    186         s.themes = o.theme;
    187         s.plugins = o.plugins;
    188         s.languages = o.language;
    189         t.settings = s;
    190 
    191         t.cb = cb || '';
    192 
    193         for (i=0; i<nl.length; i++) {
    194             n = nl[i];
    195 
    196             if (n.src && n.src.indexOf('tiny_mce') != -1)
    197                 t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
    198         }
    199         tinyMCEPreInit.base = t.baseURL;
    200        
    201         if (!t.coreLoaded)
    202             t.loadScripts(1, s.themes, s.plugins, s.languages);
    203     },
    204 
    205     loadScripts : function(co, th, pl, la, cb, sc) {
    206         var t = this, x, w = window, q, c = 0, ti, s = t.settings;
    207 
    208         function get(s) {
    209             x = 0;
    210 
    211             try {
    212                 x = new ActiveXObject(s);
    213             } catch (s) {
    214             }
    215 
    216             return x;
    217         };
    218 
    219         // Build query string
    220         q = 'load=true&js=true&diskcache=' + (s.disk_cache ? 'true' : 'false') + '&core=' + (co ? 'true' : 'false') + '&suffix=' + escape(s.suffix) + '&themes=' + escape(th) + '&plugins=' + escape(pl) + '&languages=' + escape(la);
    221 
    222         if (co)
    223             t.coreLoaded = 1;
    224 
    225     //  document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + t.baseURL + '/' + s.page_name + '?' + q + '"></script>');
    226 
    227         // Send request
    228         x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Msxml2.XMLHTTP') || get('Microsoft.XMLHTTP');
    229         x.overrideMimeType && x.overrideMimeType('text/javascript');
    230         x.open('GET', t.baseURL + '/' + s.page_name + '?' + q, !!cb);
    231 //      x.setRequestHeader('Content-Type', 'text/javascript');
    232         x.send('');
    233 
    234         // Handle asyncronous loading
    235         if (cb) {
    236             // Wait for response
    237             ti = w.setInterval(function() {
    238                 if (x.readyState == 4 || c++ > 10000) {
    239                     w.clearInterval(ti);
    240 
    241                     if (c < 10000 && x.status == 200) {
    242                         t.loaded = 1;
    243                         t.eval(x.responseText);
    244                         tinymce.dom.Event.domLoaded = true;
    245                     //  cb.call(sc || t, x);
    246                     }
    247 
    248                     ti = x = null;
    249                 }
    250             }, 10);
    251         } else
    252             t.eval(x.responseText);
    253     },
    254 
    255     start : function() {
    256         var t = this, each = tinymce.each, s = t.settings, sl, ln = s.languages.split(',');
    257 
    258         tinymce.suffix = s.suffix;
    259 
    260         // Extend script loader
    261         tinymce.create('tinymce.compressor.ScriptLoader:tinymce.dom.ScriptLoader', {
    262             loadScripts : function(sc, cb, s) {
    263                 var ti = this, th = [], pl = [], la = [];
    264 
    265                 each(sc, function(o) {
    266                     var u = o.url;
    267 
    268                     if ((!ti.lookup[u] || ti.lookup[u].state != 2) && u.indexOf(t.baseURL) === 0) {
    269                         // Collect theme
    270                         if (u.indexOf('editor_template') != -1) {
    271                             th.push(/\/themes\/([^\/]+)/.exec(u)[1]);
    272                             load(u, 1);
    273                         }
    274 
    275                         // Collect plugin
    276                         if (u.indexOf('editor_plugin') != -1) {
    277                             pl.push(/\/plugins\/([^\/]+)/.exec(u)[1]);
    278                             load(u, 1);
    279                         }
    280 
    281                         // Collect language
    282                         if (u.indexOf('/langs/') != -1) {
    283                             la.push(/\/langs\/([^.]+)/.exec(u)[1]);
    284                             load(u, 1);
    285                         }
    286                     }
    287                 });
    288 
    289                 if (th.length + pl.length + la.length > 0) {
    290                     if (sl.settings.strict_mode) {
    291                         // Async
    292                         t.loadScripts(0, th.join(','), pl.join(','), la.join(','), cb, s);
    293                         return;
    294                     } else
    295                         t.loadScripts(0, th.join(','), pl.join(','), la.join(','), cb, s);
    296                 }
    297 
    298                 return ti.parent(sc, cb, s);
    299             }
    300         });
    301 
    302         sl = tinymce.ScriptLoader = new tinymce.compressor.ScriptLoader();
    303 
    304         function load(u, sp) {
    305             var o;
    306 
    307             if (!sp)
    308                 u = t.baseURL + u;
    309 
    310             o = {url : u, state : 2};
    311             sl.queue.push(o);
    312             sl.lookup[o.url] = o;
    313         };
    314 
    315         // Add core languages
    316         each (ln, function(c) {
    317             if (c)
    318                 load('/langs/' + c + '.js');
    319         });
    320 
    321         // Add themes with languages
    322         each(s.themes.split(','), function(n) {
    323             if (n) {
    324                 load('/themes/' + n + '/editor_template' + s.suffix + '.js');
    325 
    326                 each (ln, function(c) {
    327                     if (c)
    328                         load('/themes/' + n + '/langs/' + c + '.js');
    329                 });
    330             }
    331         });
    332 
    333         // Add plugins with languages
    334         each(s.plugins.split(','), function(n) {
    335             if (n) {
    336                 load('/plugins/' + n + '/editor_plugin' + s.suffix + '.js');
    337 
    338                 each (ln, function(c) {
    339                     if (c)
    340                         load('/plugins/' + n + '/langs/' + c + '.js');
    341                 });
    342             }
    343         });
    344     },
    345 
    346     end : function() {
    347        tinyMCE.init(this.opt);
    348     },
    349 
    350     eval : function(co) {
    351         var w = window;
    352 
    353         // Evaluate script
    354         if (!w.execScript) {
    355             try {
    356                 eval.call(w, co);
    357             } catch (ex) {
    358                 eval(co, w); // Firefox 3.0a8
    359             }
    360         } else
    361             w.execScript(co); // IE
    362     }
    363 };
  • trunk/wp-includes/script-loader.php

    r6770 r6789  
    3131
    3232        // Modify this version when tinyMCE plugins are changed
    33         $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_gzip.php', false, '20080208' );
    34 
    3533        $mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
    36         $this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20080208' );
     34        $this->add( 'tiny_mce', $mce_config, false, '20080209' );
    3735       
    3836        $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
     
    479477// These localizations require information that may not be loaded even by init
    480478function wp_just_in_time_script_localization() {
    481     wp_localize_script( 'wp_tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
     479    wp_localize_script( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
    482480}
    483481
Note: See TracChangeset for help on using the changeset viewer.