diff --git a/wp-includes/js/tinymce/tiny_mce_gzip.php b/wp-includes/js/tinymce/tiny_mce_gzip.php index 0de8f4294..d3d7c7949 100644 --- a/wp-includes/js/tinymce/tiny_mce_gzip.php +++ b/wp-includes/js/tinymce/tiny_mce_gzip.php @@ -1,10 +1,7 @@ -1) { // Write main script and patch some things - if ($index == 0) { - TinyMCE_echo(wp_compact_tinymce_js(file_get_contents(realpath("tiny_mce" . $suffix . ".js")))); // WP - TinyMCE_echo('TinyMCE.prototype.orgLoadScript = TinyMCE.prototype.loadScript;'); - TinyMCE_echo('TinyMCE.prototype.loadScript = function() {};var realTinyMCE = tinyMCE;'); + if ( $index == 0 ) { + // Add core + $content .= wp_compact_tinymce_js(getFileContents("tiny_mce" . $suffix . ".js")); + $content .= 'TinyMCE.prototype.orgLoadScript = TinyMCE.prototype.loadScript;'; + $content .= 'TinyMCE.prototype.loadScript = function() {};var realTinyMCE = tinyMCE;'; } else - TinyMCE_echo('tinyMCE = realTinyMCE;'); + $content .= 'tinyMCE = realTinyMCE;'; + // Patch loading functions + //$content .= "tinyMCE_GZ.start();"; + // Do init based on index - TinyMCE_echo("tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);"); + $content .= "tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);"; // Load external plugins - if ($index == 0) - TinyMCE_echo("tinyMCECompressed.loadPlugins();"); + if ( $index == 0 ) + $content .= "tinyMCECompressed.loadPlugins();"; - // Load theme, language pack and theme language packs - if ($theme) { - TinyMCE_echo(wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme . "/editor_template" . $suffix . ".js")))); // WP - TinyMCE_echo(wp_tinymce_lang("themes/" . $theme . "/langs/%s.js")); // WP + // Add core languages + foreach ($languages as $lang) + $content .= getFileContents("langs/" . $lang . ".js"); + + // Add themes + foreach ($themes as $theme) { + $content .= wp_compact_tinymce_js(getFileContents( "themes/" . $theme . "/editor_template" . $suffix . ".js")); + + foreach ($languages as $lang) + $content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js"); } - /* WP if ($language) WP */ - TinyMCE_echo(wp_tinymce_lang("langs/%s.js")); // WP - - // Load all plugins and their language packs - $plugins = explode(",", $plugins); + // Add plugins foreach ($plugins as $plugin) { - $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js"); - /* WP $languageFile = realpath("plugins/" . $plugin . "/langs/" . $lang . ".js"); WP */ + $content .= getFileContents("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js"); - if ($pluginFile) - TinyMCE_echo(file_get_contents($pluginFile)); - - /* WP if ($languageFile) WP */ - TinyMCE_echo(wp_tinymce_lang("plugins/" . $plugin . "/langs/%s.js")); // WP + foreach ($languages as $lang) + $content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js"); } + // Add custom files + foreach ($custom as $file) + $content .= getFileContents($file); + // Reset tinyMCE compressor engine - TinyMCE_echo("tinyMCE = tinyMCECompressed;"); + $content .= "tinyMCE = tinyMCECompressed;"; - // Write to cache - if ($diskCache) { - // Calculate compression ratio and debug target output path - if ($debug) { - $ratio = round(100 - strlen(gzencode($cacheData, 9, FORCE_GZIP)) / strlen($cacheData) * 100.0); - TinyMCE_echo("alert('TinyMCE was compressed by " . $ratio . "%.\\nOutput cache file: " . $cacheFile . "');"); - } + // Restore loading functions + //$content .= "tinyMCE_GZ.end();"; - $cacheData = gzencode($cacheData, 9, FORCE_GZIP); + // Generate GZIP'd content + if ($supportsGzip) { + if ($compress) { + header("Content-Encoding: " . $enc); + $cacheData = gzencode($content, 9, FORCE_GZIP); + } else + $cacheData = $content; - // Write to file if possible - $fp = @fopen($cacheFile, "wb"); - if ($fp) { - fwrite($fp, $cacheData); - fclose($fp); - } + // Write gz file + if ($diskCache && $cacheKey != "") + putFileContents($cacheFile, $cacheData); - // Output - header("Content-Encoding: " . $enc); + // Stream to client echo $cacheData; + } else { + // Stream uncompressed content + echo $content; } die; } + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + function getParam($name, $def = false) { + if (!isset($_GET[$name])) + return $def; + + return preg_replace("/[^0-9a-z\-_,]+/i", "", $_GET[$name]); // Remove anything but 0-9,a-z,-_ + } + + function getFileContents($path) { + $path = realpath($path); + + if (!$path || !@is_file($path)) + return ""; + + if (function_exists("file_get_contents")) + return @file_get_contents($path); + + $content = ""; + $fp = @fopen($path, "r"); + if (!$fp) + return ""; + + while (!feof($fp)) + $content .= fgets($fp); + + fclose($fp); + + return $content; + } + + function putFileContents($path, $content) { + if (function_exists("file_put_contents")) + return @file_put_contents($path, $content); + + $fp = @fopen($path, "wb"); + if ($fp) { + fwrite($fp, $content); + fclose($fp); + } + } + + // WP specific + function wp_compact_tinymce_js($text) { + // This function was custom-made for TinyMCE 2.0, not expected to work with any other JS. + + // Strip comments + $text = preg_replace("!(^|\s+)//.*$!m", '', $text); + $text = preg_replace("!/\*.*?\*/!s", '', $text); + + // Strip leading tabs, carriage returns and unnecessary line breaks. + $text = preg_replace("!^\t+!m", '', $text); + $text = str_replace("\r", '', $text); + $text = preg_replace("!(^|{|}|;|:|\))\n!m", '\\1', $text); + + return "$text\n"; + } ?> function TinyMCECompressed() { diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index cd3dfbc8e..625ec296c 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -15,7 +15,7 @@ class WP_Scripts { $this->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' ); $this->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '3517' ); $this->add( 'colorpicker', '/wp-includes/js/colorpicker.js', false, '3517' ); - $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_gzip.php', false, '20070124' ); + $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_gzip.php', false, '20070325' ); $mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php'); $this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20070225' ); $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0-0');