Source for file tiny_mce_gzip.php
Documentation is available at tiny_mce_gzip.php
* $Id: tiny_mce_gzip.php,v 1.1 2009/03/21 22:26:32 fplanque Exp $
* @copyright Copyright © 2005-2006, Moxiecode Systems AB, All rights reserved.
* This file compresses the TinyMCE JavaScript using GZip and
* enables the browser to do two requests instead of one for each .js file.
* Notice: This script defaults the button_tile_map option to true for extra performance.
// Set the error reporting to minimal.
$diskCache =
getParam("diskcache", "") ==
"true";
$compress =
getParam("compress", "true") ==
"true";
$core =
getParam("core", "true") ==
"true";
$suffix =
getParam("suffix", "_src") ==
"_src" ?
"_src" :
"";
$cachePath =
dirname(__FILE__
).
'/../../../cache/plugins/tinymce'; // Cache path, this is where the .gz files will be stored
$expiresOffset =
3600 *
24 *
10; // Cache for 10 days in browser cache
// Custom extra javascripts to pack
header("Content-type: text/javascript");
header("Vary: Accept-Encoding"); // Handle proxies
header("Expires: " .
gmdate("D, d M Y H:i:s", time() +
$expiresOffset) .
" GMT");
// Is called directly then auto init with default settings
echo
"tinyMCE_GZ.init({});";
die("alert('Compressor Real path failed. (tiny_mce_gzip.php) $cachePath');");
foreach ($custom as $file)
// Add modification date of core JS file, so that the disk cache expires on
// TinyMCE upgrade/changes:
$last_mod_time =
@filemtime('tiny_mce'.
$suffix.
'.js');
$cacheKey .=
$last_mod_time;
$cacheKey =
md5($cacheKey);
$cacheFile =
$cachePath.
'/tiny_mce_'.
$cacheKey;
// Remove old cache files on every ~1000th request:
foreach( glob($cachePath.
'/tiny_mce_*.{gz,js}', GLOB_NOSORT|
GLOB_BRACE) as $old_cache_file )
if( filectime($old_cache_file) <
$last_mod_time )
// Check if it supports gzip
if (isset
($_SERVER['HTTP_ACCEPT_ENCODING']))
$enc =
in_array('x-gzip', $encodings) ?
"x-gzip" :
"gzip";
// Use cached file disk cache
if ($diskCache &&
$supportsGzip &&
file_exists($cacheFile)) {
header("Content-Encoding: " .
$enc);
// Patch loading functions
$content .=
"tinyMCE_GZ.start();";
foreach ($languages as $lang)
foreach ($themes as $theme) {
$content .=
getFileContents( "themes/" .
$theme .
"/editor_template" .
$suffix .
".js");
foreach ($languages as $lang)
$content .=
getFileContents("themes/" .
$theme .
"/langs/" .
$lang .
".js");
foreach ($plugins as $plugin) {
$content .=
getFileContents("plugins/" .
$plugin .
"/editor_plugin" .
$suffix .
".js");
foreach ($languages as $lang)
$content .=
getFileContents("plugins/" .
$plugin .
"/langs/" .
$lang .
".js");
foreach ($custom as $file)
// Restore loading functions
$content .=
"tinyMCE_GZ.end();";
// Generate GZIP'd content
header("Content-Encoding: " .
$enc);
$cacheData =
gzencode($content, 9, FORCE_GZIP);
if ($diskCache &&
$cacheKey !=
"")
// Stream uncompressed content
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function getParam($name, $def =
false) {
if (!isset
($_GET[$name]))
return preg_replace("/[^0-9a-z\-_,]+/i", "", $_GET[$name]); // Remove anything but 0-9,a-z,-_
$fp =
@fopen($path, "r");
$fp =
@fopen($path, "wb");