-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. // 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() { this.configs = new Array(); this.loadedFiles = new Array(); this.externalPlugins = new Array(); this.loadAdded = false; this.isLoaded = false; } TinyMCECompressed.prototype.init = function(settings) { var elements = document.getElementsByTagName('script'); var scriptURL = ""; for (var i=0; i'); if (!this.loadAdded) { tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCECompressed.prototype.onLoad); tinyMCE.addEvent(window, "load", TinyMCECompressed.prototype.onLoad); this.loadAdded = true; } } TinyMCECompressed.prototype.onLoad = function() { if (tinyMCE.isLoaded) return true; tinyMCE = realTinyMCE; TinyMCE_Engine.prototype.onLoad(); tinyMCE._addUnloadEvents(); tinyMCE.isLoaded = true; } TinyMCECompressed.prototype.addEvent = function(o, n, h) { if (o.attachEvent) o.attachEvent("on" + n, h); else o.addEventListener(n, h, false); } TinyMCECompressed.prototype.getOnce = function(str) { var ar = str.replace(/\s+/g, '').split(','); for (var i=0; i