2005-08-23 03:33:52 +02:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* $RCSfile: tiny_mce_gzip.php,v $
|
2005-11-06 04:30:11 +01:00
|
|
|
|
* $Revision: $
|
|
|
|
|
* $Date: $
|
2005-08-23 03:33:52 +02:00
|
|
|
|
*
|
2005-11-06 04:30:11 +01:00
|
|
|
|
* @version 1.02
|
2005-08-23 03:33:52 +02:00
|
|
|
|
* @author Moxiecode
|
2005-11-06 04:30:11 +01:00
|
|
|
|
* @copyright Copyright <EFBFBD> 2005, Moxiecode Systems AB, All rights reserved.
|
2005-08-23 03:33:52 +02:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Todo:
|
|
|
|
|
* - Add local file cache for the GZip:ed version.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-11-06 04:30:11 +01:00
|
|
|
|
@ include('../../../wp-config.php');
|
|
|
|
|
|
|
|
|
|
function wp_translate_tinymce_lang($text) {
|
|
|
|
|
if ( ! function_exists('__') ) {
|
|
|
|
|
return $text;
|
|
|
|
|
} else {
|
2005-11-19 20:11:03 +01:00
|
|
|
|
$search1 = "/^tinyMCELang\\[(['\"])(.*)\\1\]( ?= ?)(['\"])(.*)\\4/Uem";
|
2005-11-06 04:30:11 +01:00
|
|
|
|
$replace1 = "'tinyMCELang[\\1\\2\\1]\\3'.stripslashes('\\4').__('\\5').stripslashes('\\4')";
|
|
|
|
|
|
2005-11-19 20:11:03 +01:00
|
|
|
|
$search2 = "/ : (['\"])(.*)\\1/Uem";
|
2005-11-06 04:30:11 +01:00
|
|
|
|
$replace2 = "' : '.stripslashes('\\1').__('\\2').stripslashes('\\1')";
|
|
|
|
|
|
|
|
|
|
$search = array($search1, $search2);
|
|
|
|
|
$replace = array($replace1, $replace2);
|
|
|
|
|
|
|
|
|
|
$text = preg_replace($search, $replace, $text);
|
|
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-23 03:33:52 +02:00
|
|
|
|
// General options
|
2005-09-26 09:13:48 +02:00
|
|
|
|
$suffix = ""; // Set to "_src" to use source version
|
2005-08-23 03:33:52 +02:00
|
|
|
|
$expiresOffset = 3600 * 24 * 10; // 10 days util client cache expires
|
|
|
|
|
|
|
|
|
|
// Get data to load
|
|
|
|
|
$theme = isset($_REQUEST['theme']) ? $_REQUEST['theme'] : "";
|
|
|
|
|
$language = isset($_REQUEST['language']) ? $_REQUEST['language'] : "";
|
|
|
|
|
$plugins = isset($_REQUEST['plugins']) ? $_REQUEST['plugins'] : "";
|
2005-11-06 04:30:11 +01:00
|
|
|
|
$lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : "en";
|
|
|
|
|
$index = isset($_REQUEST['index']) ? $_REQUEST['index'] : -1;
|
2005-08-23 03:33:52 +02:00
|
|
|
|
|
2005-11-06 04:30:11 +01:00
|
|
|
|
// Only gzip the contents if clients and server support it
|
|
|
|
|
$encodings = explode(',', strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
|
|
|
|
|
if (in_array('gzip', $encodings) && function_exists('ob_gzhandler'))
|
|
|
|
|
ob_start("ob_gzhandler");
|
|
|
|
|
|
|
|
|
|
// Output rest of headers
|
2005-08-23 03:33:52 +02:00
|
|
|
|
header("Content-type: text/javascript; charset: UTF-8");
|
2005-11-06 04:30:11 +01:00
|
|
|
|
// header("Cache-Control: must-revalidate");
|
|
|
|
|
header("Vary: Accept-Encoding"); // Handle proxies
|
2005-08-23 03:33:52 +02:00
|
|
|
|
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
|
|
|
|
|
|
2005-11-06 04:30:11 +01:00
|
|
|
|
if ($index > -1) {
|
2005-08-23 03:33:52 +02:00
|
|
|
|
// Write main script and patch some things
|
2005-11-06 04:30:11 +01:00
|
|
|
|
if ($index == 0) {
|
|
|
|
|
echo file_get_contents(realpath("tiny_mce" . $suffix . ".js"));
|
|
|
|
|
echo "\n\n";
|
|
|
|
|
echo "TinyMCE.prototype.loadScript = function() {};\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WP
|
|
|
|
|
$lang = $language = 'en';
|
|
|
|
|
echo "\n/* WP Cancels all TinyMCE language handling */\n";
|
|
|
|
|
echo "TinyMCE.prototype.importThemeLanguagePack = function() {};\n";
|
|
|
|
|
echo "TinyMCE.prototype.importPluginLanguagePack = function() {};\n\n";
|
|
|
|
|
|
|
|
|
|
// Do init based on index
|
|
|
|
|
// WP echo "tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);\n\n";
|
2005-08-23 03:33:52 +02:00
|
|
|
|
|
|
|
|
|
// Load theme, language pack and theme language packs
|
2005-11-06 04:30:11 +01:00
|
|
|
|
if ($theme) {
|
|
|
|
|
echo file_get_contents(realpath("themes/" . $theme . "/editor_template" . $suffix . ".js"));
|
|
|
|
|
echo wp_translate_tinymce_lang(file_get_contents(realpath("themes/" . $theme . "/langs/" . $lang . ".js")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($language)
|
|
|
|
|
echo wp_translate_tinymce_lang(file_get_contents(realpath("langs/" . $language . ".js")));
|
2005-08-23 03:33:52 +02:00
|
|
|
|
|
|
|
|
|
// Load all plugins and their language packs
|
|
|
|
|
$plugins = explode(",", $plugins);
|
|
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
|
$pluginFile = realpath("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
|
2005-11-06 04:30:11 +01:00
|
|
|
|
$languageFile = realpath("plugins/" . $plugin . "/langs/" . $lang . ".js");
|
2005-08-23 03:33:52 +02:00
|
|
|
|
|
|
|
|
|
if ($pluginFile)
|
|
|
|
|
echo file_get_contents($pluginFile);
|
|
|
|
|
|
|
|
|
|
if ($languageFile)
|
2005-11-06 04:30:11 +01:00
|
|
|
|
echo wp_translate_tinymce_lang(file_get_contents($languageFile));
|
2005-08-23 03:33:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
function TinyMCECompressed() {
|
2005-11-06 04:30:11 +01:00
|
|
|
|
this.configs = new Array();
|
|
|
|
|
this.loadedFiles = new Array();
|
2005-08-23 03:33:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TinyMCECompressed.prototype.init = function(settings) {
|
|
|
|
|
var elements = document.getElementsByTagName('script');
|
|
|
|
|
var scriptURL = "";
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<elements.length; i++) {
|
|
|
|
|
if (elements[i].src && elements[i].src.indexOf("tiny_mce_gzip.php") != -1) {
|
|
|
|
|
scriptURL = elements[i].src;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings["theme"] = typeof(settings["theme"]) != "undefined" ? settings["theme"] : "default";
|
|
|
|
|
settings["plugins"] = typeof(settings["plugins"]) != "undefined" ? settings["plugins"] : "";
|
|
|
|
|
settings["language"] = typeof(settings["language"]) != "undefined" ? settings["language"] : "en";
|
|
|
|
|
settings["button_tile_map"] = typeof(settings["button_tile_map"]) != "undefined" ? settings["button_tile_map"] : true;
|
2005-11-06 04:30:11 +01:00
|
|
|
|
this.configs[this.configs.length] = settings;
|
|
|
|
|
this.settings = settings;
|
2005-08-23 03:33:52 +02:00
|
|
|
|
|
2005-11-06 04:30:11 +01:00
|
|
|
|
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);
|
2005-08-23 03:33:52 +02:00
|
|
|
|
document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + scriptURL + '"></script>');
|
2005-11-06 04:30:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TinyMCECompressed.prototype.getOnce = function(str) {
|
|
|
|
|
var ar = str.split(',');
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<ar.length; i++) {
|
|
|
|
|
if (ar[i] == '')
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Skip load
|
|
|
|
|
for (var x=0; x<this.loadedFiles.length; x++) {
|
|
|
|
|
if (this.loadedFiles[x] == ar[i])
|
|
|
|
|
ar[i] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.loadedFiles[this.loadedFiles.length] = ar[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Glue
|
|
|
|
|
str = "";
|
|
|
|
|
for (var i=0; i<ar.length; i++) {
|
|
|
|
|
if (ar[i] == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
str += ar[i];
|
|
|
|
|
|
|
|
|
|
if (i != ar.length-1)
|
|
|
|
|
str += ",";
|
|
|
|
|
}
|
2005-08-23 03:33:52 +02:00
|
|
|
|
|
2005-11-06 04:30:11 +01:00
|
|
|
|
return str;
|
2005-08-23 03:33:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tinyMCE = new TinyMCECompressed();
|
2005-11-06 04:30:11 +01:00
|
|
|
|
var tinyMCECompressed = tinyMCE;
|