[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 /** 3 * $RCSfile: tiny_mce_gzip.php,v $ 4 * $Revision: $ 5 * $Date: $ 6 * 7 * @version 1.08 8 * @author Moxiecode 9 * @copyright Copyright © 2005-2006, Moxiecode Systems AB, All rights reserved. 10 * 11 * This file compresses the TinyMCE JavaScript using GZip and 12 * enables the browser to do two requests instead of one for each .js file. 13 * Notice: This script defaults the button_tile_map option to true for extra performance. 14 */ 15 16 // General options 17 $suffix = ""; // Set to "_src" to use source version 18 $expiresOffset = 3600 * 24 * 10; // 10 days util client cache expires 19 $diskCache = false; // If you enable this option gzip files will be cached on disk. 20 $cacheDir = realpath("."); // Absolute directory path to where cached gz files will be stored 21 $debug = false; // Enable this option if you need debuging info 22 23 // Headers 24 header("Content-type: text/javascript; charset: UTF-8"); 25 // header("Cache-Control: must-revalidate"); 26 header("Vary: Accept-Encoding"); // Handle proxies 27 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT"); 28 29 // Get data to load 30 $theme = isset($_GET['theme']) ? TinyMCE_cleanInput($_GET['theme']) : ""; 31 $language = isset($_GET['language']) ? TinyMCE_cleanInput($_GET['language']) : ""; 32 $plugins = isset($_GET['plugins']) ? TinyMCE_cleanInput($_GET['plugins']) : ""; 33 $lang = isset($_GET['lang']) ? TinyMCE_cleanInput($_GET['lang']) : "en"; 34 $index = isset($_GET['index']) ? TinyMCE_cleanInput($_GET['index']) : -1; 35 $cacheKey = md5($theme . $language . $plugins . $lang . $index . $debug); 36 $cacheFile = $cacheDir == "" ? "" : $cacheDir . "/" . "tinymce_" . $cacheKey . ".gz"; 37 $cacheData = ""; 38 39 // Patch older versions of PHP < 4.3.0 40 if (!function_exists('file_get_contents')) { 41 function file_get_contents($filename) { 42 $fd = fopen($filename, 'rb'); 43 $content = fread($fd, filesize($filename)); 44 fclose($fd); 45 return $content; 46 } 47 } 48 49 // Security check function, can only contain a-z 0-9 , _ - and whitespace. 50 function TinyMCE_cleanInput($str) { 51 return preg_replace("/[^0-9a-z\-_,]+/i", "", $str); // Remove anything but 0-9,a-z,-_ 52 } 53 54 function TinyMCE_echo($str) { 55 global $cacheData, $diskCache; 56 57 if ($diskCache) 58 $cacheData .= $str; 59 else 60 echo $str; 61 } 62 63 // Only gzip the contents if clients and server support it 64 $encodings = array(); 65 66 if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) 67 $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING']))); 68 69 // Check for gzip header or northon internet securities 70 if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) { 71 $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip"; 72 73 // Use cached file if it exists but not in debug mode 74 if (file_exists($cacheFile) && !$debug) { 75 header("Content-Encoding: " . $enc); 76 echo file_get_contents($cacheFile); 77 die; 78 } 79 80 if (!$diskCache) 81 ob_start("ob_gzhandler"); 82 } else 83 $diskCache = false; 84 85 if ($index > -1) { 86 // Write main script and patch some things 87 if ($index == 0) { 88 TinyMCE_echo(file_get_contents(realpath("tiny_mce" . $suffix . ".js"))); 89 TinyMCE_echo('TinyMCE.prototype.orgLoadScript = TinyMCE.prototype.loadScript;'); 90 TinyMCE_echo('TinyMCE.prototype.loadScript = function() {};var realTinyMCE = tinyMCE;'); 91 } else 92 TinyMCE_echo('tinyMCE = realTinyMCE;'); 93 94 // Do init based on index 95 TinyMCE_echo("tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);"); 96 97 // Load external plugins 98 if ($index == 0) 99 TinyMCE_echo("tinyMCECompressed.loadPlugins();"); 100 101 // Load theme, language pack and theme language packs 102 if ($theme) { 103 TinyMCE_echo(file_get_contents(realpath("themes/" . $theme . "/editor_template" . $suffix . ".js"))); 104 TinyMCE_echo(file_get_contents(realpath("themes/" . $theme . "/langs/" . $lang . ".js"))); 105 } 106 107 if ($language) 108 TinyMCE_echo(file_get_contents(realpath("langs/" . $language . ".js"))); 109 110 // Load all plugins and their language packs 111 $plugins = explode(",", $plugins); 112 foreach ($plugins as $plugin) { 113 $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js"); 114 $languageFile = realpath("plugins/" . $plugin . "/langs/" . $lang . ".js"); 115 116 if ($pluginFile) 117 TinyMCE_echo(file_get_contents($pluginFile)); 118 119 if ($languageFile) 120 TinyMCE_echo(file_get_contents($languageFile)); 121 } 122 123 // Reset tinyMCE compressor engine 124 TinyMCE_echo("tinyMCE = tinyMCECompressed;"); 125 126 // Write to cache 127 if ($diskCache) { 128 // Calculate compression ratio and debug target output path 129 if ($debug) { 130 $ratio = round(100 - strlen(gzencode($cacheData, 9, FORCE_GZIP)) / strlen($cacheData) * 100.0); 131 TinyMCE_echo("alert('TinyMCE was compressed by " . $ratio . "%.\\nOutput cache file: " . $cacheFile . "');"); 132 } 133 134 $cacheData = gzencode($cacheData, 9, FORCE_GZIP); 135 136 // Write to file if possible 137 $fp = @fopen($cacheFile, "wb"); 138 if ($fp) { 139 fwrite($fp, $cacheData); 140 fclose($fp); 141 } 142 143 // Output 144 header("Content-Encoding: " . $enc); 145 echo $cacheData; 146 } 147 148 die; 149 } 150 ?> 151 152 function TinyMCECompressed() { 153 this.configs = new Array(); 154 this.loadedFiles = new Array(); 155 this.externalPlugins = new Array(); 156 this.loadAdded = false; 157 this.isLoaded = false; 158 } 159 160 TinyMCECompressed.prototype.init = function(settings) { 161 var elements = document.getElementsByTagName('script'); 162 var scriptURL = ""; 163 164 for (var i=0; i<elements.length; i++) { 165 if (elements[i].src && elements[i].src.indexOf("tiny_mce_gzip.php") != -1) { 166 scriptURL = elements[i].src; 167 break; 168 } 169 } 170 171 settings["theme"] = typeof(settings["theme"]) != "undefined" ? settings["theme"] : "default"; 172 settings["plugins"] = typeof(settings["plugins"]) != "undefined" ? settings["plugins"] : ""; 173 settings["language"] = typeof(settings["language"]) != "undefined" ? settings["language"] : "en"; 174 settings["button_tile_map"] = typeof(settings["button_tile_map"]) != "undefined" ? settings["button_tile_map"] : true; 175 this.configs[this.configs.length] = settings; 176 this.settings = settings; 177 178 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); 179 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + scriptURL + '"></script>'); 180 181 if (!this.loadAdded) { 182 tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCECompressed.prototype.onLoad); 183 tinyMCE.addEvent(window, "load", TinyMCECompressed.prototype.onLoad); 184 this.loadAdded = true; 185 } 186 } 187 188 TinyMCECompressed.prototype.onLoad = function() { 189 if (tinyMCE.isLoaded) 190 return true; 191 192 tinyMCE = realTinyMCE; 193 TinyMCE_Engine.prototype.onLoad(); 194 tinyMCE._addUnloadEvents(); 195 196 tinyMCE.isLoaded = true; 197 } 198 199 TinyMCECompressed.prototype.addEvent = function(o, n, h) { 200 if (o.attachEvent) 201 o.attachEvent("on" + n, h); 202 else 203 o.addEventListener(n, h, false); 204 } 205 206 TinyMCECompressed.prototype.getOnce = function(str) { 207 var ar = str.replace(/\s+/g, '').split(','); 208 209 for (var i=0; i<ar.length; i++) { 210 if (ar[i] == '' || ar[i].charAt(0) == '-') { 211 ar[i] = null; 212 continue; 213 } 214 215 // Skip load 216 for (var x=0; x<this.loadedFiles.length; x++) { 217 if (this.loadedFiles[x] == ar[i]) 218 ar[i] = null; 219 } 220 221 this.loadedFiles[this.loadedFiles.length] = ar[i]; 222 } 223 224 // Glue 225 str = ""; 226 for (var i=0; i<ar.length; i++) { 227 if (ar[i] == null) 228 continue; 229 230 str += ar[i]; 231 232 if (i != ar.length-1) 233 str += ","; 234 } 235 236 return str; 237 }; 238 239 TinyMCECompressed.prototype.loadPlugins = function() { 240 var i, ar; 241 242 TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript; 243 tinyMCE = realTinyMCE; 244 245 ar = tinyMCECompressed.externalPlugins; 246 for (i=0; i<ar.length; i++) 247 tinyMCE.loadPlugin(ar[i].name, ar[i].url); 248 249 TinyMCE.prototype.loadScript = function() {}; 250 }; 251 252 TinyMCECompressed.prototype.loadPlugin = function(n, u) { 253 this.externalPlugins[this.externalPlugins.length] = {name : n, url : u}; 254 }; 255 256 TinyMCECompressed.prototype.importPluginLanguagePack = function(n, v) { 257 tinyMCE = realTinyMCE; 258 TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript; 259 tinyMCE.importPluginLanguagePack(n, v); 260 }; 261 262 TinyMCECompressed.prototype.addPlugin = function(n, p) { 263 tinyMCE = realTinyMCE; 264 tinyMCE.addPlugin(n, p); 265 }; 266 267 var tinyMCE = new TinyMCECompressed(); 268 var tinyMCECompressed = tinyMCE;
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |