00001 <?php
00016
00017 $suffix = "";
00018 $expiresOffset = 3600 * 24 * 10;
00019 $diskCache = false;
00020 $cacheDir = realpath(".");
00021 $debug = false;
00022
00023
00024 header("Content-type: text/javascript; charset: UTF-8");
00025
00026 header("Vary: Accept-Encoding");
00027 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
00028
00029
00030 $theme = isset($_GET['theme']) ? TinyMCE_cleanInput($_GET['theme']) : "";
00031 $language = isset($_GET['language']) ? TinyMCE_cleanInput($_GET['language']) : "";
00032 $plugins = isset($_GET['plugins']) ? TinyMCE_cleanInput($_GET['plugins']) : "";
00033 $lang = isset($_GET['lang']) ? TinyMCE_cleanInput($_GET['lang']) : "en";
00034 $index = isset($_GET['index']) ? TinyMCE_cleanInput($_GET['index']) : -1;
00035 $cacheKey = md5($theme . $language . $plugins . $lang . $index . $debug);
00036 $cacheFile = $cacheDir == "" ? "" : $cacheDir . "/" . "tinymce_" . $cacheKey . ".gz";
00037 $cacheData = "";
00038
00039
00040 if (!function_exists('file_get_contents')) {
00041 function file_get_contents($filename) {
00042 $fd = fopen($filename, 'rb');
00043 $content = fread($fd, filesize($filename));
00044 fclose($fd);
00045 return $content;
00046 }
00047 }
00048
00049
00050 function TinyMCE_cleanInput($str) {
00051 return preg_replace("/[^0-9a-z\-_,]+/i", "", $str);
00052 }
00053
00054 function TinyMCE_echo($str) {
00055 global $cacheData, $diskCache;
00056
00057 if ($diskCache)
00058 $cacheData .= $str;
00059 else
00060 echo $str;
00061 }
00062
00063
00064 $encodings = array();
00065
00066 if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
00067 $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
00068
00069
00070 if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
00071 $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
00072
00073
00074 if (file_exists($cacheFile) && !$debug) {
00075 header("Content-Encoding: " . $enc);
00076 echo file_get_contents($cacheFile);
00077 die;
00078 }
00079
00080 if (!$diskCache)
00081 ob_start("ob_gzhandler");
00082 } else
00083 $diskCache = false;
00084
00085 if ($index > -1) {
00086
00087 if ($index == 0) {
00088 TinyMCE_echo(file_get_contents(realpath("tiny_mce" . $suffix . ".js")));
00089 TinyMCE_echo('TinyMCE.prototype.orgLoadScript = TinyMCE.prototype.loadScript;');
00090 TinyMCE_echo('TinyMCE.prototype.loadScript = function() {};var realTinyMCE = tinyMCE;');
00091 } else
00092 TinyMCE_echo('tinyMCE = realTinyMCE;');
00093
00094
00095 TinyMCE_echo("tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);");
00096
00097
00098 if ($index == 0)
00099 TinyMCE_echo("tinyMCECompressed.loadPlugins();");
00100
00101
00102 if ($theme) {
00103 TinyMCE_echo(file_get_contents(realpath("themes/" . $theme . "/editor_template" . $suffix . ".js")));
00104 TinyMCE_echo(file_get_contents(realpath("themes/" . $theme . "/langs/" . $lang . ".js")));
00105 }
00106
00107 if ($language)
00108 TinyMCE_echo(file_get_contents(realpath("langs/" . $language . ".js")));
00109
00110
00111 $plugins = explode(",", $plugins);
00112 foreach ($plugins as $plugin) {
00113 $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
00114 $languageFile = realpath("plugins/" . $plugin . "/langs/" . $lang . ".js");
00115
00116 if ($pluginFile)
00117 TinyMCE_echo(file_get_contents($pluginFile));
00118
00119 if ($languageFile)
00120 TinyMCE_echo(file_get_contents($languageFile));
00121 }
00122
00123
00124 TinyMCE_echo("tinyMCE = tinyMCECompressed;");
00125
00126
00127 if ($diskCache) {
00128
00129 if ($debug) {
00130 $ratio = round(100 - strlen(gzencode($cacheData, 9, FORCE_GZIP)) / strlen($cacheData) * 100.0);
00131 TinyMCE_echo("alert('TinyMCE was compressed by " . $ratio . "%.\\nOutput cache file: " . $cacheFile . "');");
00132 }
00133
00134 $cacheData = gzencode($cacheData, 9, FORCE_GZIP);
00135
00136
00137 $fp = @fopen($cacheFile, "wb");
00138 if ($fp) {
00139 fwrite($fp, $cacheData);
00140 fclose($fp);
00141 }
00142
00143
00144 header("Content-Encoding: " . $enc);
00145 echo $cacheData;
00146 }
00147
00148 die;
00149 }
00150 ?>
00151
00152 function TinyMCECompressed() {
00153 this.configs = new Array();
00154 this.loadedFiles = new Array();
00155 this.externalPlugins = new Array();
00156 this.loadAdded = false;
00157 this.isLoaded = false;
00158 }
00159
00160 TinyMCECompressed.prototype.init = function(settings) {
00161 var elements = document.getElementsByTagName('script');
00162 var scriptURL = "";
00163
00164 for (var i=0; i<elements.length; i++) {
00165 if (elements[i].src && elements[i].src.indexOf("tiny_mce_gzip.php") != -1) {
00166 scriptURL = elements[i].src;
00167 break;
00168 }
00169 }
00170
00171 settings["theme"] = typeof(settings["theme"]) != "undefined" ? settings["theme"] : "default";
00172 settings["plugins"] = typeof(settings["plugins"]) != "undefined" ? settings["plugins"] : "";
00173 settings["language"] = typeof(settings["language"]) != "undefined" ? settings["language"] : "en";
00174 settings["button_tile_map"] = typeof(settings["button_tile_map"]) != "undefined" ? settings["button_tile_map"] : true;
00175 this.configs[this.configs.length] = settings;
00176 this.settings = settings;
00177
00178 scriptURL += "?theme=" + escape(this.getOnce(settings["theme"])) + "&language=" + escape(this.getOnce(settings["language"])) + "&plugins=" + escape(this.getOnce(settings["plugins"])) + "&lang=" + settings["language"] + "&index=" + escape(this.configs.length-1);
00179 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + scriptURL + '"></script>');
00180
00181 if (!this.loadAdded) {
00182 tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCECompressed.prototype.onLoad);
00183 tinyMCE.addEvent(window, "load", TinyMCECompressed.prototype.onLoad);
00184 this.loadAdded = true;
00185 }
00186 }
00187
00188 TinyMCECompressed.prototype.onLoad = function() {
00189 if (tinyMCE.isLoaded)
00190 return true;
00191
00192 tinyMCE = realTinyMCE;
00193 TinyMCE_Engine.prototype.onLoad();
00194 tinyMCE._addUnloadEvents();
00195
00196 tinyMCE.isLoaded = true;
00197 }
00198
00199 TinyMCECompressed.prototype.addEvent = function(o, n, h) {
00200 if (o.attachEvent)
00201 o.attachEvent("on" + n, h);
00202 else
00203 o.addEventListener(n, h, false);
00204 }
00205
00206 TinyMCECompressed.prototype.getOnce = function(str) {
00207 var ar = str.replace(/\s+/g, '').split(',');
00208
00209 for (var i=0; i<ar.length; i++) {
00210 if (ar[i] == '' || ar[i].charAt(0) == '-') {
00211 ar[i] = null;
00212 continue;
00213 }
00214
00215
00216 for (var x=0; x<this.loadedFiles.length; x++) {
00217 if (this.loadedFiles[x] == ar[i])
00218 ar[i] = null;
00219 }
00220
00221 this.loadedFiles[this.loadedFiles.length] = ar[i];
00222 }
00223
00224
00225 str = "";
00226 for (var i=0; i<ar.length; i++) {
00227 if (ar[i] == null)
00228 continue;
00229
00230 str += ar[i];
00231
00232 if (i != ar.length-1)
00233 str += ",";
00234 }
00235
00236 return str;
00237 };
00238
00239 TinyMCECompressed.prototype.loadPlugins = function() {
00240 var i, ar;
00241
00242 TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript;
00243 tinyMCE = realTinyMCE;
00244
00245 ar = tinyMCECompressed.externalPlugins;
00246 for (i=0; i<ar.length; i++)
00247 tinyMCE.loadPlugin(ar[i].name, ar[i].url);
00248
00249 TinyMCE.prototype.loadScript = function() {};
00250 };
00251
00252 TinyMCECompressed.prototype.loadPlugin = function(n, u) {
00253 this.externalPlugins[this.externalPlugins.length] = {name : n, url : u};
00254 };
00255
00256 TinyMCECompressed.prototype.importPluginLanguagePack = function(n, v) {
00257 tinyMCE = realTinyMCE;
00258 TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript;
00259 tinyMCE.importPluginLanguagePack(n, v);
00260 };
00261
00262 TinyMCECompressed.prototype.addPlugin = function(n, p) {
00263 tinyMCE = realTinyMCE;
00264 tinyMCE.addPlugin(n, p);
00265 };
00266
00267 var tinyMCE = new TinyMCECompressed();
00268 var tinyMCECompressed = tinyMCE;