[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/mambots/editors/tinymce/jscripts/tiny_mce/ -> tiny_mce_gzip.php (source)

   1  <?php
   2  /**
   3   * $Id: tiny_mce_gzip.php 121 2006-10-20 12:08:03Z spocke $
   4   *
   5   * @author Moxiecode
   6   * @copyright Copyright © 2005-2006, Moxiecode Systems AB, All rights reserved.
   7   *
   8   * This file compresses the TinyMCE JavaScript using GZip and
   9   * enables the browser to do two requests instead of one for each .js file.
  10   * Notice: This script defaults the button_tile_map option to true for extra performance.
  11   */
  12  
  13      // Get input
  14      $plugins = explode(',', getParam("plugins", ""));
  15      $languages = explode(',', getParam("languages", ""));
  16      $themes = explode(',', getParam("themes", ""));
  17      $diskCache = getParam("diskcache", "") == "true";
  18      $isJS = getParam("js", "") == "true";
  19      $compress = getParam("compress", "true") == "true";
  20      $suffix = getParam("suffix", "") == "_src" ? "_src" : "";
  21      $cachePath = realpath("."); // Cache path, this is where the .gz files will be stored
  22      $expiresOffset = 3600 * 24 * 10; // Cache for 10 days in browser cache
  23      $content = "";
  24  
  25  
  26      // Custom extra javascripts to pack
  27      $custom = array(/*
  28          "some custom .js file",
  29          "some custom .js file"
  30      */);
  31  
  32      // Headers
  33      header("Content-type: text/javascript");
  34      header("Vary: Accept-Encoding");  // Handle proxies
  35      header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
  36  
  37      // Is called directly then auto init with default settings
  38      if (!$isJS) {
  39          echo getFileContents("tiny_mce_gzip.js");
  40          echo "tinyMCE_GZ.init({});";
  41          die();
  42      }
  43  
  44      // Setup cache info
  45      if ($diskCache) {
  46          if (!$cachePath)
  47              die("alert('Real path failed.');");
  48  
  49          $cacheKey = getParam("plugins", "") . getParam("languages", "") . getParam("themes", "");
  50  
  51          foreach ($custom as $file)
  52              $cacheKey .= $file;
  53  
  54          $cacheKey = md5($cacheKey);
  55  
  56          if ($compress)
  57              $cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".gz";
  58          else
  59              $cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".js";
  60      }
  61  
  62      // Check if it supports gzip
  63      $encodings = array();
  64      $supportsGzip = false;
  65      if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
  66          $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
  67  
  68      if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
  69          $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
  70          $supportsGzip = true;
  71      }
  72  
  73      // Use cached file disk cache
  74      if ($diskCache && $supportsGzip && file_exists($cacheFile)) {
  75          if ($compress)
  76              header("Content-Encoding: " . $enc);
  77  
  78          echo getFileContents($cacheFile);
  79          die();
  80      }
  81  
  82      // Add core
  83      $content .= getFileContents("tiny_mce" . $suffix . ".js");
  84  
  85      // Patch loading functions
  86      $content .= "tinyMCE_GZ.start();";
  87  
  88      // Add core languages
  89      foreach ($languages as $lang)
  90          $content .= getFileContents("langs/" . $lang . ".js");
  91  
  92      // Add themes
  93      foreach ($themes as $theme) {
  94          $content .= getFileContents( "themes/" . $theme . "/editor_template" . $suffix . ".js");
  95  
  96          foreach ($languages as $lang)
  97              $content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js");
  98      }
  99  
 100      // Add plugins
 101      foreach ($plugins as $plugin) {
 102          $content .= getFileContents("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
 103  
 104          foreach ($languages as $lang)
 105              $content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js");
 106      }
 107  
 108      // Add custom files
 109      foreach ($custom as $file)
 110          $content .= getFileContents($file);
 111  
 112      // Restore loading functions
 113      $content .= "tinyMCE_GZ.end();";
 114  
 115      // Generate GZIP'd content
 116      if ($supportsGzip) {
 117          if ($compress) {
 118              header("Content-Encoding: " . $enc);
 119              $cacheData = gzencode($content, 9, FORCE_GZIP);
 120          } else
 121              $cacheData = $content;
 122  
 123          // Write gz file
 124          if ($diskCache && $cacheKey != "")
 125              putFileContents($cacheFile, $cacheData);
 126  
 127          // Stream to client
 128          echo $cacheData;
 129      } else {
 130          // Stream uncompressed content
 131          echo $content;
 132      }
 133  
 134      /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 135  
 136  	function getParam($name, $def = false) {
 137          if (!isset($_GET[$name]))
 138              return $def;
 139  
 140          return preg_replace("/[^0-9a-z\-_,]+/i", "", $_GET[$name]); // Remove anything but 0-9,a-z,-_
 141      }
 142  
 143  	function getFileContents($path) {
 144          $path = realpath($path);
 145  
 146          if (!$path)
 147              return "";
 148  
 149          if (function_exists("file_get_contents"))
 150              return file_get_contents($path);
 151  
 152          $content = "";
 153          $fp = fopen($path, "r");
 154          if (!$fp)
 155              return "";
 156  
 157          while (!feof($fp))
 158              $content .= fgets($fp);
 159  
 160          fclose($fp);
 161  
 162          return $content;
 163      }
 164  
 165  	function putFileContents($path, $content) {
 166          if (function_exists("file_put_contents"))
 167              return file_put_contents($path, $content);
 168  
 169          $fp = @fopen($path, "wb");
 170          if ($fp) {
 171              fwrite($fp, $content);
 172              fclose($fp);
 173          }
 174      }
 175  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics