Make WordPress Core


Ignore:
Timestamp:
03/30/2006 07:50:33 AM (20 years ago)
Author:
ryan
Message:

tinyMCE 2.0.5 coming at you live. fixes #2598

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/tiny_mce_gzip.php

    r3623 r3664  
    11<?php
    2         /**
    3          * $RCSfile: tiny_mce_gzip.php,v $
    4          * $Revision: $
    5          * $Date: $
    6          *
    7          * @version 1.02
    8          * @author Moxiecode
    9          * @copyright Copyright © 2005, 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          * Todo:
    16          *  - Add local file cache for the GZip:ed version.
    17          */
    18 
    19         /* Heavily edited to add flexibilty in WordPress */
    20         @ require('../../../wp-config.php');
    21 
    22         function wp_translate_tinymce_lang($text) {
    23                 if ( ! function_exists('__') ) {
    24                         return $text;
    25                 } else {
    26                         $search1 = "/^tinyMCELang\\[(['\"])(.*)\\1\]( ?= ?)(['\"])(.*)\\4/Uem";
    27                         $replace1 = "'tinyMCELang[\\1\\2\\1]\\3'.stripslashes('\\4').__('\\5').stripslashes('\\4')";
    28 
    29                         $search2 = "/ : (['\"])(.*)\\1/Uem";
    30                         $replace2 = "' : '.stripslashes('\\1').__('\\2').stripslashes('\\1')";
    31 
    32                         $search = array($search1, $search2);
    33                         $replace = array($replace1, $replace2);
    34 
    35                         $text = preg_replace($search, $replace, $text);
    36 
    37                         return $text;
    38                 }
    39         }
    40 
    41         function wp_compact_tinymce_js($text) {
    42                 // This function was custom-made for TinyMCE 2.0, not expected to work with any other JS.
    43 
    44                 // Strip comments
    45                 $text = preg_replace("!(^|\s+)//.*$!m", '', $text);
    46                 $text = preg_replace("!/\*.*?\*/!s", '', $text);
    47 
    48                 // Strip leading tabs, carriage returns and unnecessary line breaks.
    49                 $text = preg_replace("!^\t+!m", '', $text);
    50                 $text = str_replace("\r", '', $text);
    51                 $text = preg_replace("!(^|{|}|;|:|\))\n!m", '\\1', $text);
     2/**
     3 * $RCSfile: tiny_mce_gzip.php,v $
     4 * $Revision: $
     5 * $Date: $
     6 *
     7 * @version 1.07
     8 * @author Moxiecode
     9 * @copyright Copyright © 20052006, 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@require_once('../../../wp-config.php');
     17
     18gzip_compression();
     19
     20function wp_tinymce_lang($path) {
     21        global $language;
     22
     23        $text = '';
     24
     25        // Look for xx_YY.js, xx_yy.js, xx.js
     26        $file = realpath(sprintf($path, $language));
     27        if ( file_exists($file) )
     28                $text = file_get_contents($file);
     29        $file = realpath(sprintf($path, strtolower($language)));
     30        if ( file_exists($file) )
     31                $text = file_get_contents($file);
     32        $file = realpath(sprintf($path, substr($language, 0, 2)));
     33        if ( file_exists($file) )
     34                $text = file_get_contents($file);
     35
     36
     37        // Fall back on en.js
     38        if ( empty($text) )
     39                $text = file_get_contents(realpath(sprintf($path, 'en')));
     40
     41        // Send lang file through gettext
     42        if ( function_exists('__') && strtolower(substr($language, 0, 2)) != 'en' ) {
     43                $search1 = "/^tinyMCELang\\[(['\"])(.*)\\1\]( ?= ?)(['\"])(.*)\\4/Uem";
     44                $replace1 = "'tinyMCELang[\\1\\2\\1]\\3'.stripslashes('\\4').__('\\5').stripslashes('\\4')";
     45
     46                $search2 = "/\\s:\\s(['\"])(.*)\\1(,|\\s*})/Uem";
     47                $replace2 = "' : '.stripslashes('\\1').__('\\2foo').stripslashes('\\1').'\\3'";
     48
     49                $search = array($search1, $search2);
     50                $replace = array($replace1, $replace2);
     51
     52                $text = preg_replace($search, $replace, $text);
    5253
    5354                return $text;
    5455        }
    5556
    56         // General options
    57         $expiresOffset = 3600 * 24 * 30; // 30 days util client cache expires
    58 
    59         gzip_compression();
    60 
    61         // Output rest of headers
    62         header("Content-type: text/javascript; charset: UTF-8");
    63         header("Vary: Accept-Encoding"); // Handle proxies
    64         header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
    65 
    66         // Write main script
    67         $tinymce = file_get_contents(realpath("tiny_mce.js"));
    68         echo wp_compact_tinymce_js($tinymce);
    69         echo "\n\n";
    70 
    71         // Remove some functions
    72         echo "\n/* WP cancels all TinyMCE language and import handling */\n";
    73         echo "TinyMCE.prototype.importThemeLanguagePack = function() {};\n";
    74         echo "TinyMCE.prototype.importPluginLanguagePack = function() {};\n\n";
    75         echo "TinyMCE.prototype.loadScript = function() {};\n";
     57        return $text;
     58}
     59
     60function wp_compact_tinymce_js($text) {
     61        // This function was custom-made for TinyMCE 2.0, not expected to work with any other JS.
     62
     63        // Strip comments
     64        $text = preg_replace("!(^|\s+)//.*$!m", '', $text);
     65        $text = preg_replace("!/\*.*?\*/!s", '', $text);
     66
     67        // Strip leading tabs, carriage returns and unnecessary line breaks.
     68        $text = preg_replace("!^\t+!m", '', $text);
     69        $text = str_replace("\r", '', $text);
     70        $text = preg_replace("!(^|{|}|;|:|\))\n!m", '\\1', $text);
     71
     72        return "$text\n";
     73}
     74
     75
     76// General options
     77$suffix = "";                                                   // Set to "_src" to use source version
     78$expiresOffset = 3600 * 24 * 10;                // 10 days util client cache expires
     79$diskCache = false;                                             // If you enable this option gzip files will be cached on disk.
     80$cacheDir = realpath(".");                              // Absolute directory path to where cached gz files will be stored
     81$debug = false;                                                 // Enable this option if you need debuging info
     82
     83// Headers
     84header("Content-type: text/javascript; charset: UTF-8");
     85// header("Cache-Control: must-revalidate");
     86header("Vary: Accept-Encoding"); // Handle proxies
     87header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
     88
     89// Get data to load
     90$theme = isset($_GET['theme']) ? TinyMCE_cleanInput($_GET['theme']) : "";
     91$language = isset($_GET['language']) ? TinyMCE_cleanInput($_GET['language']) : "";
     92$plugins = isset($_GET['plugins']) ? TinyMCE_cleanInput($_GET['plugins']) : "";
     93$lang = isset($_GET['lang']) ? TinyMCE_cleanInput($_GET['lang']) : "en";
     94$index = isset($_GET['index']) ? TinyMCE_cleanInput($_GET['index']) : -1;
     95$cacheKey = md5($theme . $language . $plugins . $lang . $index . $debug);
     96$cacheFile = $cacheDir == "" ? "" : $cacheDir . "/" . "tinymce_" .  $cacheKey . ".gz";
     97$cacheData = "";
     98
     99// Patch older versions of PHP < 4.3.0
     100if (!function_exists('file_get_contents')) {
     101        function file_get_contents($filename) {
     102                $fd = fopen($filename, 'rb');
     103                $content = fread($fd, filesize($filename));
     104                fclose($fd);
     105                return $content;
     106        }
     107}
     108
     109// Security check function, can only contain a-z 0-9 , _ - and whitespace.
     110function TinyMCE_cleanInput($str) {
     111        return preg_replace("/[^0-9a-z\-_,]+/i", "", $str); // Remove anything but 0-9,a-z,-_
     112}
     113
     114function TinyMCE_echo($str) {
     115        global $cacheData, $diskCache;
     116
     117        if ($diskCache)
     118                $cacheData .= $str;
     119        else
     120                echo $str;
     121}
     122/* WP
     123// Only gzip the contents if clients and server support it
     124$encodings = array();
     125
     126if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
     127        $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
     128
     129// Check for gzip header or northon internet securities
     130if ((in_array('gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
     131        // Use cached file if it exists but not in debug mode
     132        if (file_exists($cacheFile) && !$debug) {
     133                header("Content-Encoding: gzip");
     134                echo file_get_contents($cacheFile);
     135                die;
     136        }
     137
     138        if (!$diskCache)
     139                ob_start("ob_gzhandler");
     140} else
     141        $diskCache = false;
     142WP */
     143if ($index > -1) {
     144        // Write main script and patch some things
     145        if ($index == 0) {
     146                TinyMCE_echo(wp_compact_tinymce_js(file_get_contents(realpath("tiny_mce" . $suffix . ".js")))); // WP
     147                TinyMCE_echo('TinyMCE.prototype.loadScript = function() {};var realTinyMCE = tinyMCE;');
     148        } else
     149                TinyMCE_echo('tinyMCE = realTinyMCE;');
     150
     151        // Do init based on index
     152        TinyMCE_echo("tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);");
    76153
    77154        // Load theme, language pack and theme language packs
    78         $theme = apply_filters('mce_theme', 'advanced');
    79 
    80         echo wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme . "/editor_template.js")));
    81 
    82         // Get the WordPress locale
    83         $locale = get_locale();
    84 
    85         $themeLanguageFile = realpath("themes/" . $theme . "/langs/" . $locale . ".js");
    86 
    87         if (!file_exists($themeLanguageFile))
    88                 $themeLanguageFile = realpath("themes/" . $theme . "/langs/en.js");
    89         echo wp_translate_tinymce_lang(file_get_contents($themeLanguageFile));
    90 
    91         $tinymceLanguageFile = realpath("langs/" . $locale . ".js");
    92 
    93         if (!file_exists($tinymceLanguageFile))
    94                 $tinymceLanguageFile = realpath("langs/en.js");
    95         echo wp_translate_tinymce_lang(file_get_contents($tinymceLanguageFile));
     155        if ($theme) {
     156                TinyMCE_echo(wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme . "/editor_template" . $suffix . ".js"))));
     157                TinyMCE_echo(wp_tinymce_lang("themes/" . $theme . "/langs/%s.js")); // WP
     158        }
     159
     160        /* WP if ($language) WP */
     161                TinyMCE_echo(wp_tinymce_lang("langs/%s.js"));
    96162
    97163        // Load all plugins and their language packs
    98         $plugins = apply_filters('mce_plugins', array('wordpress', 'autosave','wphelp'));
    99 
     164        $plugins = explode(",", $plugins);
    100165        foreach ($plugins as $plugin) {
    101                 $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin.js");
    102                 $languageFile = realpath("plugins/" . $plugin . "/langs/" . $locale . ".js");
    103                 if (!file_exists($languageFile))
    104                         $languageFile = realpath("plugins/" . $plugin . "/langs/en.js");
     166                $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
     167                /* WP $languageFile = realpath("plugins/" . $plugin . "/langs/" . $lang . ".js"); WP */
    105168
    106169                if ($pluginFile)
    107                         echo file_get_contents($pluginFile);
    108 
    109                 if ($languageFile)
    110                         echo wp_translate_tinymce_lang(file_get_contents($languageFile));
    111         }
    112 
    113         // Set up init variables
    114         if ( current_user_can('unfiltered_html') ) // Use the full XHTML set provided in the docs
    115                 $valid_elements = 'a[accesskey|charset|class|coords|dir<ltr?rtl|href|hreflang|id|lang|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rel|rev|shape<circle?default?poly?rect|style|tabindex|title|target|type],abbr[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],acronym[class|dir<ltr?rtl|id|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],address[class|align|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],applet[align<bottom?left?middle?right?top|alt|archive|class|code|codebase|height|hspace|id|name|object|style|title|vspace|width],area[accesskey|alt|class|coords|dir<ltr?rtl|href|id|lang|nohref<nohref|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|shape<circle?default?poly?rect|style|tabindex|title|target],base[href|target],basefont[color|face|id|size],bdo[class|dir<ltr?rtl|id|lang|style|title],big[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],blockquote[dir|style|cite|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],body[alink|background|bgcolor|class|dir<ltr?rtl|id|lang|link|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onunload|style|title|text|vlink],br[class|clear<all?left?none?right|id|style|title],button[accesskey|class|dir<ltr?rtl|disabled<disabled|id|lang|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|tabindex|title|type|value],caption[align<bottom?left?right?top|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],center[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],'
    116                         . 'cite[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],code[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],col[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|span|style|title|valign<baseline?bottom?middle?top|width],colgroup[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|span|style|title|valign<baseline?bottom?middle?top|width],dd[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],del[cite|class|datetime|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],dfn[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],dir[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],div[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],dl[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],dt[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],em/i[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],'
    117                         . 'fieldset[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],font[class|color|dir<ltr?rtl|face|id|lang|size|style|title],form[accept|accept-charset|action|class|dir<ltr?rtl|enctype|id|lang|method<get?post|name|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onreset|onsubmit|style|title|target],frame[class|frameborder|id|longdesc|marginheight|marginwidth|name|noresize<noresize|scrolling<auto?no?yes|src|style|title],frameset[class|cols|id|onload|onunload|rows|style|title],h1[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],h2[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],h3[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],h4[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],h5[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],h6[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],head[dir<ltr?rtl|lang|profile],hr[align<center?left?right|class|dir<ltr?rtl|id|lang|noshade<noshade|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|size|style|title|width],html[dir<ltr?rtl|lang|version],'
    118                         . 'iframe[align<bottom?left?middle?right?top|class|frameborder|height|id|longdesc|marginheight|marginwidth|name|scrolling<auto?no?yes|src|style|title|width],img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height|hspace|id|ismap<ismap|lang|longdesc|name|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|src|style|title|usemap|vspace|width],input[accept|accesskey|align<bottom?left?middle?right?top|alt|checked<checked|class|dir<ltr?rtl|disabled<disabled|id|ismap<ismap|lang|maxlength|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onselect|readonly<readonly|size|src|style|tabindex|title|type<button?checkbox?file?hidden?image?password?radio?reset?submit?text|usemap|value],ins[cite|class|datetime|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],isindex[class|dir<ltr?rtl|id|lang|prompt|style|title],kbd[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],label[accesskey|class|dir<ltr?rtl|for|id|lang|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],legend[align<bottom?left?right?top|accesskey|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],li[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|type|value],link[charset|class|dir<ltr?rtl|href|hreflang|id|lang|media|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rel|rev|style|title|target|type],map[class|dir<ltr?rtl|id|lang|name|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],'
    119                         . 'menu[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],meta[content|dir<ltr?rtl|http-equiv|lang|name|scheme],noframes[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],noscript[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],object[align<bottom?left?middle?right?top|archive|border|class|classid|codebase|codetype|data|declare|dir<ltr?rtl|height|hspace|id|lang|name|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|standby|style|tabindex|title|type|usemap|vspace|width],ol[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|start|style|title|type],optgroup[class|dir<ltr?rtl|disabled<disabled|id|label|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],option[class|dir<ltr?rtl|disabled<disabled|id|label|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|selected<selected|style|title|value],p[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],param[id|name|type|value|valuetype<DATA?OBJECT?REF],pre/listing/plaintext/xmp[align|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|width],q[cite|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],'
    120                         . 's[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],samp[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],script[charset|defer|language|src|type],select[class|dir<ltr?rtl|disabled<disabled|id|lang|multiple<multiple|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|size|style|tabindex|title],small[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],span[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],strike[class|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],strong/b[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],style[dir<ltr?rtl|lang|media|title|type],sub[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],sup[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],table[align<center?left?right|bgcolor|border|cellpadding|cellspacing|class|dir<ltr?rtl|frame|height|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rules|style|summary|title|width],'
    121                         . 'tbody[align<center?char?justify?left?right|char|class|charoff|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|valign<baseline?bottom?middle?top],td[abbr|align<center?char?justify?left?right|axis|bgcolor|char|charoff|class|colspan|dir<ltr?rtl|headers|height|id|lang|nowrap<nowrap|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rowspan|scope<col?colgroup?row?rowgroup|style|title|valign<baseline?bottom?middle?top|width],textarea[accesskey|class|cols|dir<ltr?rtl|disabled<disabled|id|lang|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onselect|readonly<readonly|rows|style|tabindex|title],tfoot[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|valign<baseline?bottom?middle?top],th[abbr|align<center?char?justify?left?right|axis|bgcolor|char|charoff|class|colspan|dir<ltr?rtl|headers|height|id|lang|nowrap<nowrap|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rowspan|scope<col?colgroup?row?rowgroup|style|title|valign<baseline?bottom?middle?top|width],thead[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|valign<baseline?bottom?middle?top],'
    122                         . 'title[dir<ltr?rtl|lang],tr[abbr|align<center?char?justify?left?right|bgcolor|char|charoff|class|rowspan|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|valign<baseline?bottom?middle?top],tt[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],u[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],ul[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|type],var[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title]';
    123         else // Use a much smaller set
    124                 $valid_elements = '-a[id|href|title|rel],-strong/b,-em/i,-strike,-del,-u,p[class|align|dir],-ol,-ul,-li,br,img[class|src|alt|title|width|height|align],-sub,-sup,-blockquote[dir],-table[border|cellspacing|cellpadding|width|height|class|align|dir],thead[class|rowspan|width|height|align|valign|dir],tr[class|rowspan|width|height|align|valign|dir],th[dir|class|colspan|rowspan|width|height|align|valign|scope],td[dir|class|colspan|rowspan|width|height|align|valign],-div[dir|class|align],-span[class|align],-pre[class],-code[class],-address,-h1[class|align|dir],-h2[class|align|dir],-h3[class|align|dir],-h4[class|align|dir],-h5[class|align|dir],-h6[class|align|dir],hr';
    125         $valid_elements = apply_filters('mce_valid_elements', $valid_elements);
    126         $plugins = implode($plugins, ',');
    127         $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'separator', 'bullist', 'numlist', 'outdent', 'indent', 'separator', 'justifyleft', 'justifycenter', 'justifyright' ,'separator', 'link', 'unlink', 'image', 'wordpress', 'separator', 'undo', 'redo', 'code', 'wphelp'));
    128         $mce_buttons = implode($mce_buttons, ',');
    129         $mce_buttons_2 = apply_filters('mce_buttons_2', array());
    130         $mce_buttons_2 = implode($mce_buttons_2, ',');
    131         $mce_buttons_3 = apply_filters('mce_buttons_3', array());
    132         $mce_buttons_3 = implode($mce_buttons_3, ',');
    133         $mce_browsers = apply_filters('mce_browsers', array('msie', 'gecko', 'opera'));
    134         $mce_browsers = implode($mce_browsers, ',');
     170                        TinyMCE_echo(file_get_contents($pluginFile));
     171
     172                /* WP if ($languageFile) WP */
     173                        TinyMCE_echo(wp_tinymce_lang("plugins/" . $plugin . "/langs/%s.js")); // WP
     174        }
     175
     176        // Reset tinyMCE compressor engine
     177        TinyMCE_echo("tinyMCE = tinyMCECompressed;");
     178
     179        // Write to cache
     180        if ($diskCache) {
     181                // Calculate compression ratio and debug target output path
     182                if ($debug) {
     183                        $ratio = round(100 - strlen(gzencode($cacheData, 9, FORCE_GZIP)) / strlen($cacheData) * 100.0);
     184                        TinyMCE_echo("alert('TinyMCE was compressed by " . $ratio . "%.\\nOutput cache file: " . $cacheFile . "');");
     185                }
     186
     187                $cacheData = gzencode($cacheData, 9, FORCE_GZIP);
     188
     189                // Write to file if possible
     190                $fp = @fopen($cacheFile, "wb");
     191                if ($fp) {
     192                        fwrite($fp, $cacheData);
     193                        fclose($fp);
     194                }
     195
     196                // Output
     197                header("Content-Encoding: gzip");
     198                echo $cacheData;
     199        }
     200
     201        die;
     202}
    135203?>
    136204
    137 initArray = {
    138         mode : "specific_textareas",
    139         textarea_trigger : "title",
    140         width : "100%",
    141         theme : "advanced",
    142         theme_advanced_buttons1 : "<?php echo $mce_buttons; ?>",
    143         theme_advanced_buttons2 : "<?php echo $mce_buttons_2; ?>",
    144         theme_advanced_buttons3 : "<?php echo $mce_buttons_3; ?>",
    145         theme_advanced_toolbar_location : "top",
    146         theme_advanced_toolbar_align : "left",
    147         theme_advanced_path_location : "bottom",
    148         theme_advanced_resizing : true,
    149         browsers : "<?php echo $mce_browsers; ?>",
    150         dialog_type : "modal",
    151         theme_advanced_resize_horizontal : false,
    152         entity_encoding : "raw",
    153         relative_urls : false,
    154         remove_script_host : false,
    155         force_p_newlines : true,
    156         force_br_newlines : false,
    157         convert_newlines_to_brs : false,
    158         remove_linebreaks : true,
    159         save_callback : "wp_save_callback",
    160         document_base_url : "<?php echo trailingslashit(get_bloginfo('home')); ?>",
    161         valid_elements : "<?php echo $valid_elements; ?>",
    162 <?php do_action('mce_options'); ?>
    163         plugins : "<?php echo $plugins; ?>"
    164 };
    165 
    166 <?php
    167         // For people who really REALLY know what they're doing with TinyMCE
    168         do_action('tinymce_before_init');
    169 ?>
    170 
    171 tinyMCE.init(initArray);
    172 
     205function TinyMCECompressed() {
     206        this.configs = new Array();
     207        this.loadedFiles = new Array();
     208        this.loadAdded = false;
     209        this.isLoaded = false;
     210}
     211
     212TinyMCECompressed.prototype.init = function(settings) {
     213        var elements = document.getElementsByTagName('script');
     214        var scriptURL = "";
     215
     216        for (var i=0; i<elements.length; i++) {
     217                if (elements[i].src && elements[i].src.indexOf("tiny_mce_gzip.php") != -1) {
     218                        scriptURL = elements[i].src;
     219                        break;
     220                }
     221        }
     222
     223        settings["theme"] = typeof(settings["theme"]) != "undefined" ? settings["theme"] : "default";
     224        settings["plugins"] = typeof(settings["plugins"]) != "undefined" ? settings["plugins"] : "";
     225        settings["language"] = typeof(settings["language"]) != "undefined" ? settings["language"] : "en";
     226        settings["button_tile_map"] = typeof(settings["button_tile_map"]) != "undefined" ? settings["button_tile_map"] : true;
     227        this.configs[this.configs.length] = settings;
     228        this.settings = settings;
     229
     230        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);
     231        document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + scriptURL + '"></script>');
     232
     233        if (!this.loadAdded) {
     234                tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCECompressed.prototype.onLoad);
     235                tinyMCE.addEvent(window, "load", TinyMCECompressed.prototype.onLoad);
     236                this.loadAdded = true;
     237        }
     238}
     239
     240TinyMCECompressed.prototype.onLoad = function() {
     241        if (tinyMCE.isLoaded)
     242                return true;
     243
     244        tinyMCE = realTinyMCE;
     245        TinyMCE_Engine.prototype.onLoad();
     246        tinyMCE._addUnloadEvents();
     247        tinyMCE.isLoaded = true;
     248}
     249
     250TinyMCECompressed.prototype.addEvent = function(o, n, h) {
     251        if (o.attachEvent)
     252                o.attachEvent("on" + n, h);
     253        else
     254                o.addEventListener(n, h, false);
     255}
     256
     257TinyMCECompressed.prototype.getOnce = function(str) {
     258        var ar = str.split(',');
     259
     260        for (var i=0; i<ar.length; i++) {
     261                if (ar[i] == '')
     262                        continue;
     263
     264                // Skip load
     265                for (var x=0; x<this.loadedFiles.length; x++) {
     266                        if (this.loadedFiles[x] == ar[i])
     267                                ar[i] = null;
     268                }
     269
     270                this.loadedFiles[this.loadedFiles.length] = ar[i];
     271        }
     272
     273        // Glue
     274        str = "";
     275        for (var i=0; i<ar.length; i++) {
     276                if (ar[i] == null)
     277                        continue;
     278
     279                str += ar[i];
     280
     281                if (i != ar.length-1)
     282                        str += ",";
     283        }
     284
     285        return str;
     286}
     287
     288var tinyMCE = new TinyMCECompressed();
     289var tinyMCECompressed = tinyMCE;
Note: See TracChangeset for help on using the changeset viewer.