X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/ff81ee6e8304a1982a3ec4f5b134764a29d502cf..refs/tags/wordpress-2.3.3:/wp-includes/js/tinymce/tiny_mce_gzip.php?ver=20051211 diff --git a/wp-includes/js/tinymce/tiny_mce_gzip.php b/wp-includes/js/tinymce/tiny_mce_gzip.php index c3af23dd..7c21f480 100644 --- a/wp-includes/js/tinymce/tiny_mce_gzip.php +++ b/wp-includes/js/tinymce/tiny_mce_gzip.php @@ -1,43 +1,230 @@ -1) { + // Write main script and patch some things + 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 + $content .= 'tinyMCE = realTinyMCE;'; + + // Patch loading functions + //$content .= "tinyMCE_GZ.start();"; + + // Do init based on index + $content .= "tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);"; + + // Load external plugins + if ( $index == 0 ) + $content .= "tinyMCECompressed.loadPlugins();"; + + // Add core languages + $lang_content = ''; + foreach ($languages as $lang) + $lang_content .= getFileContents("langs/" . $lang . ".js"); + if ( empty($lang_content) ) + $lang_content .= getFileContents("langs/en.js"); + $content .= $lang_content; + + // Add themes + foreach ($themes as $theme) { + $content .= wp_compact_tinymce_js(getFileContents( "themes/" . $theme . "/editor_template" . $suffix . ".js")); + + $lang_content = ''; + foreach ($languages as $lang) + $lang_content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js"); + if ( empty($lang_content) ) + $lang_content .= getFileContents("themes/" . $theme . "/langs/en.js"); + $content .= $lang_content; + } + + // Add plugins + foreach ($plugins as $plugin) { + $content .= getFileContents("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js"); + + $lang_content = ''; + foreach ($languages as $lang) + $lang_content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js"); + if ( empty($lang_content) ) + $lang_content .= getFileContents("plugins/" . $plugin . "/langs/en.js"); + $content .= $lang_content; + } + + // Add custom files + foreach ($custom as $file) + $content .= getFileContents($file); + + // Reset tinyMCE compressor engine + $content .= "tinyMCE = tinyMCECompressed;"; + + // Restore loading functions + //$content .= "tinyMCE_GZ.end();"; + + // Generate GZIP'd content + if ($supportsGzip) { + if ($compress) { + header("Content-Encoding: " . $enc); + $cacheData = gzencode($content, 9, FORCE_GZIP); + } else + $cacheData = $content; + + // Write gz file + if ($diskCache && $cacheKey != "") + putFileContents($cacheFile, $cacheData); + + // 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. @@ -50,123 +237,125 @@ $text = str_replace("\r", '', $text); $text = preg_replace("!(^|{|}|;|:|\))\n!m", '\\1', $text); - return $text; + return "$text\n"; } +?> - // General options - $expiresOffset = 3600 * 24 * 30; // 30 days util client cache expires +function TinyMCECompressed() { + this.configs = new Array(); + this.loadedFiles = new Array(); + this.externalPlugins = new Array(); + this.loadAdded = false; + this.isLoaded = false; +} - gzip_compression(); +TinyMCECompressed.prototype.init = function(settings) { + var elements = document.getElementsByTagName('script'); + var scriptURL = ""; - // Output rest of headers - header("Content-type: text/javascript; charset: UTF-8"); - header("Vary: Accept-Encoding"); // Handle proxies - header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT"); + for (var i=0; i'); - // Load theme, language pack and theme language packs - $theme = apply_filters('mce_theme', 'advanced'); + if (!this.loadAdded) { + tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCECompressed.prototype.onLoad); + tinyMCE.addEvent(window, "load", TinyMCECompressed.prototype.onLoad); + this.loadAdded = true; + } +} - echo wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme . "/editor_template.js"))); +TinyMCECompressed.prototype.onLoad = function() { + if (tinyMCE.isLoaded) + return true; - // Get the WordPress locale - $locale = get_locale(); + tinyMCE = realTinyMCE; + TinyMCE_Engine.prototype.onLoad(); + tinyMCE._addUnloadEvents(); - $themeLanguageFile = realpath("themes/" . $theme . "/langs/" . $locale . ".js"); + tinyMCE.isLoaded = true; +} - if (!file_exists($themeLanguageFile)) - $themeLanguageFile = realpath("themes/" . $theme . "/langs/en.js"); - echo wp_translate_tinymce_lang(file_get_contents($themeLanguageFile)); +TinyMCECompressed.prototype.addEvent = function(o, n, h) { + if (o.attachEvent) + o.attachEvent("on" + n, h); + else + o.addEventListener(n, h, false); +} - $tinymceLanguageFile = realpath("langs/" . $locale . ".js"); +TinyMCECompressed.prototype.getOnce = function(str) { + var ar = str.replace(/\s+/g, '').split(','); - if (!file_exists($tinymceLanguageFile)) - $tinymceLanguageFile = realpath("langs/en.js"); - echo wp_translate_tinymce_lang(file_get_contents($tinymceLanguageFile)); + for (var i=0; i + return str; +}; -initArray = { - mode : "specific_textareas", - textarea_trigger : "title", - width : "100%", - theme : "advanced", - theme_advanced_buttons1 : "", - theme_advanced_buttons2 : "", - theme_advanced_buttons3 : "", - theme_advanced_toolbar_location : "top", - theme_advanced_toolbar_align : "left", - theme_advanced_path_location : "bottom", - theme_advanced_resizing : true, - browsers : "", - dialog_type : "modal", - theme_advanced_resize_horizontal : false, - entity_encoding : "raw", - relative_urls : false, - remove_script_host : false, - force_p_newlines : true, - force_br_newlines : false, - convert_newlines_to_brs : false, - remove_linebreaks : true, - save_callback : "wp_save_callback", - document_base_url : "", - valid_elements : "", - - plugins : "" +TinyMCECompressed.prototype.loadPlugins = function() { + var i, ar; + + TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript; + tinyMCE = realTinyMCE; + + ar = tinyMCECompressed.externalPlugins; + for (i=0; i +TinyMCECompressed.prototype.loadPlugin = function(n, u) { + this.externalPlugins[this.externalPlugins.length] = {name : n, url : u}; +}; + +TinyMCECompressed.prototype.importPluginLanguagePack = function(n, v) { + tinyMCE = realTinyMCE; + TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript; + tinyMCE.importPluginLanguagePack(n, v); +}; -tinyMCE.init(initArray); +TinyMCECompressed.prototype.addPlugin = function(n, p) { + tinyMCE = realTinyMCE; + tinyMCE.addPlugin(n, p); +}; +var tinyMCE = new TinyMCECompressed(); +var tinyMCECompressed = tinyMCE;