Make WordPress Core


Ignore:
Timestamp:
03/18/2008 06:59:53 AM (17 years ago)
Author:
ryan
Message:

TinyMCE fixes from azaozz. fixes #6272

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/tiny_mce_config.php

    r7270 r7378  
    5454if ( $https ) str_replace('http://', 'https://', $mce_css);
    5555
     56$mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
     57
    5658/*
    5759Setting mce_valid_elements to *[*] skips all of the internal cleanup and can cause problems.
     
    7072The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
    7173By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
    72 The + sign marks the default language.
    73 More information:
     74The + sign marks the default language. More information:
    7475http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
    7576*/
     
    7980
    8081/*
    81 The following filter takes an associative array of external plugins for TinyMCE in the form "name" => "url".
     82The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
    8283It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
    83 The url should be absolute and should include the js file name to be loaded.
    84 Example: array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' ).
     84The url should be absolute and should include the js file name to be loaded. Example:
     85array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
    8586If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
    8687*/
    87 $mce_external_plugins = apply_filters('mce_external_plugins', array()); 
     88$mce_external_plugins = apply_filters('mce_external_plugins', array());
    8889
    8990$ext_plugins = "\n";
    9091if ( ! empty($mce_external_plugins) ) {
     92   
     93    /*
     94    The following filter loads external language files for TinyMCE plugins.
     95    It takes an associative array 'plugin_name' => 'path', where path is the
     96    include path to the file. The language file should follow the same format as
     97    /tinymce/langs/wp-langs.php and should define a variable $strings that
     98    holds all translated strings. Example:
     99    $strings = 'tinyMCE.addI18n("' . $mce_locale . '.mypluginname_dlg",{tab_general:"General", ... })';
     100    */
     101    $mce_external_languages = apply_filters('mce_external_languages', array());
     102   
     103    $loaded_langs = array();
     104    $strings = '';
     105   
     106    if ( ! empty($mce_external_languages) ) {
     107        foreach ( $mce_external_languages as $name => $path ) {
     108            $loaded_langs[] = $name;
     109       
     110            if ( is_file($path) ) include_once($path);
     111            $ext_plugins .= $strings;
     112        }
     113    }
     114
    91115    foreach ( $mce_external_plugins as $name => $url ) {
     116       
    92117        if ( $https ) str_replace('http://', 'https://', $url);
     118       
    93119        $plugins[] = '-' . $name;
     120
     121        if ( in_array($name, $loaded_langs) ) {
     122            $plugurl = dirname($url);
     123            $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
     124        }
    94125        $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
    95126    }
     
    108139$mce_buttons_4 = apply_filters('mce_buttons_4', array());
    109140$mce_buttons_4 = implode($mce_buttons_4, ',');
    110 
    111 $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
    112141
    113142// TinyMCE init settings
     
    146175
    147176if ( $valid_elements ) $initArray['valid_elements'] = $valid_elements;
    148 if ( $extended_valid_elements ) $initArray['extended_valid_elements'] = $extended_valid_elements;
     177//if ( $extended_valid_elements ) $initArray['extended_valid_elements'] = $extended_valid_elements;
    149178if ( $invalid_elements ) $initArray['invalid_elements'] = $invalid_elements;
    150179
     
    179208
    180209$cache_ext = '.js';
    181 
    182210$plugins = explode( ',', $initArray['plugins'] );
    183211$theme = ( 'simple' == $initArray['theme'] ) ? 'simple' : 'advanced';
    184212$language = isset($initArray['language']) ? substr( $initArray['language'], 0, 2 ) : 'en';
    185 $enc = $cacheKey = $suffix = $mce_options = '';
     213$cacheKey = $mce_options = ''; 
    186214
    187215// Check if browser supports gzip
    188216if ( $compress && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
    189     $encodings = explode( ',', strtolower( preg_replace('/\s+/', '', $_SERVER['HTTP_ACCEPT_ENCODING']) ) );
    190 
    191     if ( (in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------']) ) && function_exists('ob_gzhandler') && (ini_get('zlib.output_compression') == false) ) {
    192         $enc = in_array('x-gzip', $encodings) ? 'x-gzip' : 'gzip';
     217    if ( ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') || isset($_SERVER['---------------']) ) && function_exists('gzencode') && ! ini_get('zlib.output_compression') ) {
    193218        $cache_ext = '.gz';
    194219    }
     
    198223if ( $disk_cache ) {
    199224
    200     $ver = isset($_GET['ver']) ? (int) $_GET['ver'] : '';
    201     $cacheKey = $suffix . $ver;
     225    $cacheKey = apply_filters('tiny_mce_version', '20080317');
    202226
    203227    foreach ( $initArray as $v )
    204228        $cacheKey .= $v;
    205229
     230    if ( ! empty($mce_external_plugins) ) {
     231        foreach ( $mce_external_plugins as $n => $v )
     232            $cacheKey .= $n;
     233    }
     234   
    206235    $cacheKey = md5( $cacheKey );
    207236    $cache_file = $cache_path . '/tinymce_' . $cacheKey . $cache_ext;
    208237}
    209238
    210 cache_javascript_headers();
     239$expiresOffset = 864000; // 10 days
     240header( 'Content-Type: application/x-javascript; charset=UTF-8' );
     241header( 'Vary: Accept-Encoding' ); // Handle proxies
     242header( 'Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . ' GMT' );
    211243
    212244// Use cached file if exists
    213 if ( $disk_cache && file_exists($cache_file) ) {
     245if ( $disk_cache && is_file($cache_file) ) {
     246
     247    $mtime = gmdate("D, d M Y H:i:s", filemtime($cache_file)) . " GMT";
     248   
     249    if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $mtime ) {
     250        header('HTTP/1.1 304 Not Modified');
     251        exit;
     252    }
     253    header("Last-Modified: " . $mtime);
     254    header("Cache-Control: must-revalidate", false);
     255
     256    $content = getFileContents( $cache_file );
     257   
    214258    if ( '.gz' == $cache_ext )
    215         header( 'Content-Encoding: ' . $enc );
    216 
    217     echo getFileContents( $cache_file );
     259        header( 'Content-Encoding: gzip' );
     260
     261    header( 'Content-Length: ' . strlen($content) );
     262
     263    echo $content;
    218264    exit;
    219265}
     
    225271$mce_options = rtrim( trim($mce_options), '\n\r,' );
    226272
    227 $content .= 'var tinyMCEPreInit = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false }, base : "' . $baseurl . '", suffix : "' . $suffix . '" };';
     273$content = 'var tinyMCEPreInit = { settings : { themes : "' . $theme . '", plugins : "' . $initArray['plugins'] . '", languages : "' . $language . '", debug : false }, base : "' . $baseurl . '", suffix : "" };';
    228274
    229275// Load patch
     
    231277
    232278// Add core
    233 $content .= getFileContents( 'tiny_mce' . $suffix . '.js' );
     279$content .= getFileContents( 'tiny_mce.js' );
    234280
    235281// Patch loading functions
     
    241287
    242288// Add themes
    243 $content .= getFileContents( 'themes/' . $theme . '/editor_template' . $suffix . '.js' );
     289$content .= getFileContents( 'themes/' . $theme . '/editor_template.js' );
    244290
    245291// Add plugins
    246292foreach ( $plugins as $plugin )
    247     $content .= getFileContents( 'plugins/' . $plugin . '/editor_plugin' . $suffix . '.js' );
     293    $content .= getFileContents( 'plugins/' . $plugin . '/editor_plugin.js' );
    248294
    249295// Add external plugins and init
     
    252298// Generate GZIP'd content
    253299if ( '.gz' == $cache_ext ) {
    254     header('Content-Encoding: ' . $enc);
     300    header('Content-Encoding: gzip');
    255301    $content = gzencode( $content, 9, FORCE_GZIP );
    256302}
    257 
    258 // Stream to client
    259 echo $content;
    260303
    261304// Write file
     
    273316           
    274317        krsort($old_cache);
    275         if ( 1 >= (int) $old_cache_max ) $del_cache = $old_cache;
     318        if ( 1 >= $old_cache_max ) $del_cache = $old_cache;
    276319        else $del_cache = array_slice( $old_cache, ($old_cache_max - 1) );
    277320           
     
    281324
    282325    putFileContents( $cache_file, $content );
    283 }
     326
     327    $mtime = gmdate( "D, d M Y H:i:s", filemtime($cache_file) ) . " GMT";
     328    header( 'Last-Modified: ' . $mtime );
     329}
     330
     331// Stream to client
     332header( 'Cache-Control: must-revalidate', false );
     333header( 'Content-Length: ' . strlen($content) );
     334echo $content;
    284335?>
Note: See TracChangeset for help on using the changeset viewer.