[ Index ]
 

Code source de WordPress 2.1.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/wp-includes/js/tinymce/ -> tiny_mce_gzip.php (source)

   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  @require_once('../../../wp-config.php');
  17  
  18  // gzip_compression();
  19  
  20  function 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      $file = realpath(sprintf($path, 'en'));
  39      if ( empty($text) && file_exists($file) )
  40          $text = file_get_contents($file);
  41  
  42      // Send lang file through gettext
  43      if ( function_exists('__') && strtolower(substr($language, 0, 2)) != 'en' ) {
  44          $search1 = "/^tinyMCELang\\[(['\"])(.*)\\1\]( ?= ?)(['\"])(.*)\\4/Uem";
  45          $replace1 = "'tinyMCELang[\\1\\2\\1]\\3'.stripslashes('\\4').__('\\5').stripslashes('\\4')";
  46  
  47          $search2 = "/\\s:\\s(['\"])(.*)\\1(,|\\s*})/Uem";
  48          $replace2 = "' : '.stripslashes('\\1').__('\\2').stripslashes('\\1').'\\3'";
  49  
  50          $search = array($search1, $search2);
  51          $replace = array($replace1, $replace2);
  52  
  53          $text = preg_replace($search, $replace, $text);
  54  
  55          return $text;
  56      }
  57  
  58      return $text;
  59  }
  60  
  61  function wp_compact_tinymce_js($text) {
  62      // This function was custom-made for TinyMCE 2.0, not expected to work with any other JS.
  63  
  64      // Strip comments
  65      $text = preg_replace("!(^|\s+)//.*$!m", '', $text);
  66      $text = preg_replace("!/\*.*?\*/!s", '', $text);
  67  
  68      // Strip leading tabs, carriage returns and unnecessary line breaks.
  69      $text = preg_replace("!^\t+!m", '', $text);
  70      $text = str_replace("\r", '', $text);
  71      $text = preg_replace("!(^|{|}|;|:|\))\n!m", '\\1', $text);
  72  
  73      return "$text\n";
  74  }
  75  
  76  
  77  // General options
  78  $suffix = "";                            // Set to "_src" to use source version
  79  $expiresOffset = 3600 * 24 * 10;        // 10 days util client cache expires
  80  $diskCache = false;                        // If you enable this option gzip files will be cached on disk.
  81  $cacheDir = realpath(".");                // Absolute directory path to where cached gz files will be stored
  82  $debug = false;                            // Enable this option if you need debuging info
  83  
  84  // Headers
  85  header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
  86  // header("Cache-Control: must-revalidate");
  87  header("Vary: Accept-Encoding"); // Handle proxies
  88  header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
  89  
  90  // Get data to load
  91  $theme = isset($_GET['theme']) ? TinyMCE_cleanInput($_GET['theme']) : "";
  92  $language = isset($_GET['language']) ? TinyMCE_cleanInput($_GET['language']) : "";
  93  $plugins = isset($_GET['plugins']) ? TinyMCE_cleanInput($_GET['plugins']) : "";
  94  $lang = isset($_GET['lang']) ? TinyMCE_cleanInput($_GET['lang']) : "en";
  95  $index = isset($_GET['index']) ? TinyMCE_cleanInput($_GET['index']) : -1;
  96  $cacheKey = md5($theme . $language . $plugins . $lang . $index . $debug);
  97  $cacheFile = $cacheDir == "" ? "" : $cacheDir . "/" . "tinymce_" .  $cacheKey . ".gz";
  98  $cacheData = "";
  99  
 100  // Patch older versions of PHP < 4.3.0
 101  if (!function_exists('file_get_contents')) {
 102  	function file_get_contents($filename) {
 103          $fd = fopen($filename, 'rb');
 104          $content = fread($fd, filesize($filename));
 105          fclose($fd);
 106          return $content;
 107      }
 108  }
 109  
 110  // Security check function, can only contain a-z 0-9 , _ - and whitespace.
 111  function TinyMCE_cleanInput($str) {
 112      return preg_replace("/[^0-9a-z\-_,]+/i", "", $str); // Remove anything but 0-9,a-z,-_
 113  }
 114  
 115  function TinyMCE_echo($str) {
 116      global $cacheData, $diskCache;
 117  
 118      if ($diskCache)
 119          $cacheData .= $str;
 120      else
 121          echo $str;
 122  }
 123  
 124  // Only gzip the contents if clients and server support it
 125  $encodings = array();
 126  
 127  if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
 128      $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
 129  
 130  // Check for gzip header or northon internet securities
 131  if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
 132      $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
 133  
 134      // Use cached file if it exists but not in debug mode
 135      if (file_exists($cacheFile) && !$debug) {
 136          header("Content-Encoding: " . $enc);
 137          echo file_get_contents($cacheFile);
 138          die;
 139      }
 140  
 141      if (!$diskCache)
 142          ob_start("ob_gzhandler");
 143  } else
 144      $diskCache = false;
 145  
 146  if ($index > -1) {
 147      // Write main script and patch some things
 148      if ($index == 0) {
 149          TinyMCE_echo(wp_compact_tinymce_js(file_get_contents(realpath("tiny_mce" . $suffix . ".js")))); // WP
 150          TinyMCE_echo('TinyMCE.prototype.orgLoadScript = TinyMCE.prototype.loadScript;');
 151          TinyMCE_echo('TinyMCE.prototype.loadScript = function() {};var realTinyMCE = tinyMCE;');
 152      } else
 153          TinyMCE_echo('tinyMCE = realTinyMCE;');
 154  
 155      // Do init based on index
 156      TinyMCE_echo("tinyMCE.init(tinyMCECompressed.configs[" . $index . "]);");
 157  
 158      // Load external plugins
 159      if ($index == 0)
 160          TinyMCE_echo("tinyMCECompressed.loadPlugins();");
 161  
 162      // Load theme, language pack and theme language packs
 163      if ($theme) {
 164          TinyMCE_echo(wp_compact_tinymce_js(file_get_contents(realpath("themes/" . $theme . "/editor_template" . $suffix . ".js")))); // WP
 165          TinyMCE_echo(wp_tinymce_lang("themes/" . $theme . "/langs/%s.js")); // WP
 166      }
 167  
 168      /* WP if ($language) WP */
 169          TinyMCE_echo(wp_tinymce_lang("langs/%s.js")); // WP
 170  
 171      // Load all plugins and their language packs
 172      $plugins = explode(",", $plugins);
 173      foreach ($plugins as $plugin) {
 174          $pluginFile = realpath("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
 175          /* WP $languageFile = realpath("plugins/" . $plugin . "/langs/" . $lang . ".js"); WP */
 176  
 177          if ($pluginFile)
 178              TinyMCE_echo(file_get_contents($pluginFile));
 179  
 180          /* WP if ($languageFile) WP */
 181              TinyMCE_echo(wp_tinymce_lang("plugins/" . $plugin . "/langs/%s.js")); // WP
 182      }
 183  
 184      // Reset tinyMCE compressor engine
 185      TinyMCE_echo("tinyMCE = tinyMCECompressed;");
 186  
 187      // Write to cache
 188      if ($diskCache) {
 189          // Calculate compression ratio and debug target output path
 190          if ($debug) {
 191              $ratio = round(100 - strlen(gzencode($cacheData, 9, FORCE_GZIP)) / strlen($cacheData) * 100.0);
 192              TinyMCE_echo("alert('TinyMCE was compressed by " . $ratio . "%.\\nOutput cache file: " . $cacheFile . "');");
 193          }
 194  
 195          $cacheData = gzencode($cacheData, 9, FORCE_GZIP);
 196  
 197          // Write to file if possible
 198          $fp = @fopen($cacheFile, "wb");
 199          if ($fp) {
 200              fwrite($fp, $cacheData);
 201              fclose($fp);
 202          }
 203  
 204          // Output
 205          header("Content-Encoding: " . $enc);
 206          echo $cacheData;
 207      }
 208  
 209      die;
 210  }
 211  ?>
 212  
 213  function TinyMCECompressed() {
 214      this.configs = new Array();
 215      this.loadedFiles = new Array();
 216      this.externalPlugins = new Array();
 217      this.loadAdded = false;
 218      this.isLoaded = false;
 219  }
 220  
 221  TinyMCECompressed.prototype.init = function(settings) {
 222      var elements = document.getElementsByTagName('script');
 223      var scriptURL = "";
 224  
 225      for (var i=0; i<elements.length; i++) {
 226          if (elements[i].src && elements[i].src.indexOf("tiny_mce_gzip.php") != -1) {
 227              scriptURL = elements[i].src;
 228              break;
 229          }
 230      }
 231  
 232      settings["theme"] = typeof(settings["theme"]) != "undefined" ? settings["theme"] : "default";
 233      settings["plugins"] = typeof(settings["plugins"]) != "undefined" ? settings["plugins"] : "";
 234      settings["language"] = typeof(settings["language"]) != "undefined" ? settings["language"] : "en";
 235      settings["button_tile_map"] = typeof(settings["button_tile_map"]) != "undefined" ? settings["button_tile_map"] : true;
 236      this.configs[this.configs.length] = settings;
 237      this.settings = settings;
 238  
 239      scriptURL += (scriptURL.indexOf('?') == -1) ? '?' : '&';
 240      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);
 241      document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + scriptURL + '"></script>');
 242  
 243      if (!this.loadAdded) {
 244          tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCECompressed.prototype.onLoad);
 245          tinyMCE.addEvent(window, "load", TinyMCECompressed.prototype.onLoad);
 246          this.loadAdded = true;
 247      }
 248  }
 249  
 250  TinyMCECompressed.prototype.onLoad = function() {
 251      if (tinyMCE.isLoaded)
 252          return true;
 253  
 254      tinyMCE = realTinyMCE;
 255      TinyMCE_Engine.prototype.onLoad();
 256      tinyMCE._addUnloadEvents();
 257  
 258      tinyMCE.isLoaded = true;
 259  }
 260  
 261  TinyMCECompressed.prototype.addEvent = function(o, n, h) {
 262      if (o.attachEvent)
 263          o.attachEvent("on" + n, h);
 264      else
 265          o.addEventListener(n, h, false);
 266  }
 267  
 268  TinyMCECompressed.prototype.getOnce = function(str) {
 269      var ar = str.replace(/\s+/g, '').split(',');
 270  
 271      for (var i=0; i<ar.length; i++) {
 272          if (ar[i] == '' || ar[i].charAt(0) == '-') {
 273              ar[i] = null;
 274              continue;
 275          }
 276  
 277          // Skip load
 278          for (var x=0; x<this.loadedFiles.length; x++) {
 279              if (this.loadedFiles[x] == ar[i])
 280                  ar[i] = null;
 281          }
 282  
 283          this.loadedFiles[this.loadedFiles.length] = ar[i];
 284      }
 285  
 286      // Glue
 287      str = "";
 288      for (var i=0; i<ar.length; i++) {
 289          if (ar[i] == null)
 290              continue;
 291  
 292          str += ar[i];
 293  
 294          if (i != ar.length-1)
 295              str += ",";
 296      }
 297  
 298      return str;
 299  };
 300  
 301  TinyMCECompressed.prototype.loadPlugins = function() {
 302      var i, ar;
 303  
 304      TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript;
 305      tinyMCE = realTinyMCE;
 306  
 307      ar = tinyMCECompressed.externalPlugins;
 308      for (i=0; i<ar.length; i++)
 309          tinyMCE.loadPlugin(ar[i].name, ar[i].url);
 310  
 311      TinyMCE.prototype.loadScript = function() {};
 312  };
 313  
 314  TinyMCECompressed.prototype.loadPlugin = function(n, u) {
 315      this.externalPlugins[this.externalPlugins.length] = {name : n, url : u};
 316  };
 317  
 318  TinyMCECompressed.prototype.importPluginLanguagePack = function(n, v) {
 319      tinyMCE = realTinyMCE;
 320      TinyMCE.prototype.loadScript = TinyMCE.prototype.orgLoadScript;
 321      tinyMCE.importPluginLanguagePack(n, v);
 322  };
 323  
 324  TinyMCECompressed.prototype.addPlugin = function(n, p) {
 325      tinyMCE = realTinyMCE;
 326      tinyMCE.addPlugin(n, p);
 327  };
 328  
 329  var tinyMCE = new TinyMCECompressed();
 330  var tinyMCECompressed = tinyMCE;


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7