includes/clientside/tinymce/tiny_mce_gzip.php
author Dan
Wed, 26 Aug 2009 13:04:26 -0400
changeset 1104 299d7e6e328b
parent 1081 745200a9cc2a
permissions -rw-r--r--
Tutorial: improved Creating & Editing page a little bit with respect to wiki formatting stuff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
544
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
     1
<?php
545
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     2
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     3
/*
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 801
diff changeset
     5
 * Copyright (C) 2006-2009 Dan Fuhry
545
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     6
 * tiny_mce_gzip.php - TinyMCE gzip and caching script, stock from MoxieCode with one modification
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     7
 *
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    10
 *
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    13
 */
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    14
544
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    15
/**
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    16
 * $Id: tiny_mce_gzip.php 315 2007-10-25 14:03:43Z spocke $
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    17
 *
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    18
 * @author Moxiecode
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    19
 * @copyright Copyright © 2005-2006, Moxiecode Systems AB, All rights reserved.
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    20
 *
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    21
 * This file compresses the TinyMCE JavaScript using GZip and
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    22
 * enables the browser to do two requests instead of one for each .js file.
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    23
 * Notice: This script defaults the button_tile_map option to true for extra performance.
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    24
 */
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    25
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    26
	// Set the error reporting to minimal.
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    27
	@error_reporting(E_ERROR | E_WARNING | E_PARSE);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    28
  
545
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    29
  // 5/5/2008 - load Enano, but only get the root directory
544
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    30
  define('ENANO_COMMON_ROOTONLY', 1);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    31
  require('../../common.php');
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    32
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    33
	// Get input
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    34
	$plugins = explode(',', getParam("plugins", ""));
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    35
	$languages = explode(',', getParam("languages", ""));
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    36
	$themes = explode(',', getParam("themes", ""));
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    37
	$diskCache = getParam("diskcache", "") == "true";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    38
	$isJS = getParam("js", "") == "true";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    39
	$compress = getParam("compress", "true") == "true";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    40
	$core = getParam("core", "true") == "true";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    41
	$suffix = getParam("suffix", "_src") == "_src" ? "_src" : "";
545
e4c8e706f167 Add standard header comment block and date of changes to tiny_mce_gzip to conform to GPL/LGPL
Dan
parents: 544
diff changeset
    42
  // 5/5/2008 - set cache path to Enano's usual directory
544
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    43
	$cachePath = realpath(ENANO_ROOT . "/cache"); // Cache path, this is where the .gz files will be stored
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    44
	$expiresOffset = 3600 * 24 * 10; // Cache for 10 days in browser cache
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    45
	$content = "";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    46
	$encodings = array();
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    47
	$supportsGzip = false;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    48
	$enc = "";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    49
	$cacheKey = "";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    50
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    51
	// Custom extra javascripts to pack
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    52
	$custom = array(/*
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    53
		"some custom .js file",
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    54
		"some custom .js file"
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    55
	*/);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    56
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    57
	// Headers
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    58
	header("Content-type: text/javascript");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    59
	header("Vary: Accept-Encoding");  // Handle proxies
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    60
	header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    61
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    62
	// Is called directly then auto init with default settings
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    63
	if (!$isJS) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    64
		echo getFileContents("tiny_mce_gzip.js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    65
		echo "tinyMCE_GZ.init({});";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    66
		die();
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    67
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    68
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    69
	// Setup cache info
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    70
	if ($diskCache) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    71
		if (!$cachePath)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    72
			die("alert('Real path failed.');");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    73
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    74
		$cacheKey = getParam("plugins", "") . getParam("languages", "") . getParam("themes", "") . $suffix;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    75
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    76
		foreach ($custom as $file)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    77
			$cacheKey .= $file;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    78
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    79
		$cacheKey = md5($cacheKey);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    80
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    81
		if ($compress)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    82
			$cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".gz";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    83
		else
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    84
			$cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".js";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    85
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    86
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    87
	// Check if it supports gzip
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    88
	if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    89
		$encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    90
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    91
	if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    92
		$enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    93
		$supportsGzip = true;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
    94
	}
547
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
    95
  
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
    96
  // Send an ETag (Enano modification 5/5/2008)
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
    97
  if ( isset($cacheKey) )
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
    98
  {
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
    99
    $etag =& $cacheKey;
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   100
    header("ETag: \"$etag\"");
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   101
    if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) )
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   102
    {
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   103
      if ( "\"$etag\"" == $_SERVER['HTTP_IF_NONE_MATCH'] )
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   104
      {
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   105
        header('HTTP/1.1 304 Not Modified');
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   106
        exit();
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   107
      }
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   108
    }
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   109
  }
544
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   110
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   111
	// Use cached file disk cache
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   112
	if ($diskCache && $supportsGzip && file_exists($cacheFile)) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   113
		if ($compress)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   114
			header("Content-Encoding: " . $enc);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   115
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   116
		echo getFileContents($cacheFile);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   117
		die();
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   118
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   119
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   120
	// Add core
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   121
	if ($core == "true") {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   122
		$content .= getFileContents("tiny_mce" . $suffix . ".js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   123
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   124
		// Patch loading functions
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   125
		$content .= "tinyMCE_GZ.start();";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   126
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   127
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   128
	// Add core languages
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   129
	foreach ($languages as $lang)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   130
		$content .= getFileContents("langs/" . $lang . ".js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   131
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   132
	// Add themes
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   133
	foreach ($themes as $theme) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   134
		$content .= getFileContents( "themes/" . $theme . "/editor_template" . $suffix . ".js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   135
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   136
		foreach ($languages as $lang)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   137
			$content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   138
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   139
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   140
	// Add plugins
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   141
	foreach ($plugins as $plugin) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   142
		$content .= getFileContents("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   143
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   144
		foreach ($languages as $lang)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   145
			$content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   146
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   147
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   148
	// Add custom files
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   149
	foreach ($custom as $file)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   150
		$content .= getFileContents($file);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   151
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   152
	// Restore loading functions
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   153
	if ($core == "true")
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   154
		$content .= "tinyMCE_GZ.end();";
547
0a2c1ce32d91 Added ETag on TinyMCE gzip; changed ETag format for standard pages so as to include user and login info to control caching when logged in or out
Dan
parents: 545
diff changeset
   155
  
544
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   156
	// Generate GZIP'd content
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   157
	if ($supportsGzip) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   158
		if ($compress) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   159
			header("Content-Encoding: " . $enc);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   160
			$cacheData = gzencode($content, 9, FORCE_GZIP);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   161
		} else
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   162
			$cacheData = $content;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   163
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   164
		// Write gz file
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   165
		if ($diskCache && $cacheKey != "")
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   166
			putFileContents($cacheFile, $cacheData);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   167
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   168
		// Stream to client
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   169
		echo $cacheData;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   170
	} else {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   171
		// Stream uncompressed content
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   172
		echo $content;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   173
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   174
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   175
	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   176
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   177
	function getParam($name, $def = false) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   178
		if (!isset($_GET[$name]))
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   179
			return $def;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   180
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   181
		return preg_replace("/[^0-9a-z\-_,]+/i", "", $_GET[$name]); // Remove anything but 0-9,a-z,-_
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   182
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   183
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   184
	function getFileContents($path) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   185
		$path = realpath($path);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   186
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   187
		if (!$path || !@is_file($path))
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   188
			return "";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   189
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   190
		if (function_exists("file_get_contents"))
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   191
			return @file_get_contents($path);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   192
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   193
		$content = "";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   194
		$fp = @fopen($path, "r");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   195
		if (!$fp)
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   196
			return "";
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   197
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   198
		while (!feof($fp))
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   199
			$content .= fgets($fp);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   200
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   201
		fclose($fp);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   202
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   203
		return $content;
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   204
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   205
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   206
	function putFileContents($path, $content) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   207
		if (function_exists("file_put_contents"))
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   208
			return @file_put_contents($path, $content);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   209
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   210
		$fp = @fopen($path, "wb");
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   211
		if ($fp) {
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   212
			fwrite($fp, $content);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   213
			fclose($fp);
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   214
		}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   215
	}
81b4499a963e Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff changeset
   216
?>