author | Dan |
Mon, 05 May 2008 20:28:13 -0400 | |
changeset 544 | 81b4499a963e |
child 545 | e4c8e706f167 |
permissions | -rw-r--r-- |
544
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
1 |
<?php |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
2 |
/** |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
3 |
* $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
|
4 |
* |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
5 |
* @author Moxiecode |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
6 |
* @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
|
7 |
* |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
8 |
* 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
|
9 |
* 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
|
10 |
* 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
|
11 |
*/ |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
12 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
13 |
// Set the error reporting to minimal. |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
14 |
@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
|
15 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
16 |
// load Enano |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
17 |
define('ENANO_COMMON_ROOTONLY', 1); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
18 |
require('../../common.php'); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
19 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
20 |
// Get input |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
21 |
$plugins = explode(',', getParam("plugins", "")); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
22 |
$languages = explode(',', getParam("languages", "")); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
23 |
$themes = explode(',', getParam("themes", "")); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
24 |
$diskCache = getParam("diskcache", "") == "true"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
25 |
$isJS = getParam("js", "") == "true"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
26 |
$compress = getParam("compress", "true") == "true"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
27 |
$core = getParam("core", "true") == "true"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
28 |
$suffix = getParam("suffix", "_src") == "_src" ? "_src" : ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
29 |
$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
|
30 |
$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
|
31 |
$content = ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
32 |
$encodings = array(); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
33 |
$supportsGzip = false; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
34 |
$enc = ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
35 |
$cacheKey = ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
36 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
37 |
// Custom extra javascripts to pack |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
38 |
$custom = array(/* |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
39 |
"some custom .js file", |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
40 |
"some custom .js file" |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
41 |
*/); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
42 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
43 |
// Headers |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
44 |
header("Content-type: text/javascript"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
45 |
header("Vary: Accept-Encoding"); // Handle proxies |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
46 |
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
|
47 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
48 |
// 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
|
49 |
if (!$isJS) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
50 |
echo getFileContents("tiny_mce_gzip.js"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
51 |
echo "tinyMCE_GZ.init({});"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
52 |
die(); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
53 |
} |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
54 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
55 |
// Setup cache info |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
56 |
if ($diskCache) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
57 |
if (!$cachePath) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
58 |
die("alert('Real path failed.');"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
59 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
60 |
$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
|
61 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
62 |
foreach ($custom as $file) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
63 |
$cacheKey .= $file; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
64 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
65 |
$cacheKey = md5($cacheKey); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
66 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
67 |
if ($compress) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
68 |
$cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".gz"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
69 |
else |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
70 |
$cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".js"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
71 |
} |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
72 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
73 |
// Check if it supports gzip |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
74 |
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
75 |
$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
|
76 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
77 |
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
|
78 |
$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
|
79 |
$supportsGzip = true; |
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 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
82 |
// Use cached file disk cache |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
83 |
if ($diskCache && $supportsGzip && file_exists($cacheFile)) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
84 |
if ($compress) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
85 |
header("Content-Encoding: " . $enc); |
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 |
echo getFileContents($cacheFile); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
88 |
die(); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
89 |
} |
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 |
// Add core |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
92 |
if ($core == "true") { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
93 |
$content .= getFileContents("tiny_mce" . $suffix . ".js"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
94 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
95 |
// Patch loading functions |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
96 |
$content .= "tinyMCE_GZ.start();"; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
97 |
} |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
98 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
99 |
// Add core languages |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
100 |
foreach ($languages as $lang) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
101 |
$content .= getFileContents("langs/" . $lang . ".js"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
102 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
103 |
// Add themes |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
104 |
foreach ($themes as $theme) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
105 |
$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
|
106 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
107 |
foreach ($languages as $lang) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
108 |
$content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
109 |
} |
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 |
// Add plugins |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
112 |
foreach ($plugins as $plugin) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
113 |
$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
|
114 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
115 |
foreach ($languages as $lang) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
116 |
$content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
117 |
} |
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 |
// Add custom files |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
120 |
foreach ($custom as $file) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
121 |
$content .= getFileContents($file); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
122 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
123 |
// Restore loading functions |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
124 |
if ($core == "true") |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
125 |
$content .= "tinyMCE_GZ.end();"; |
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 |
// Generate GZIP'd content |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
128 |
if ($supportsGzip) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
129 |
if ($compress) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
130 |
header("Content-Encoding: " . $enc); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
131 |
$cacheData = gzencode($content, 9, FORCE_GZIP); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
132 |
} else |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
133 |
$cacheData = $content; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
134 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
135 |
// Write gz file |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
136 |
if ($diskCache && $cacheKey != "") |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
137 |
putFileContents($cacheFile, $cacheData); |
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 |
// Stream to client |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
140 |
echo $cacheData; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
141 |
} else { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
142 |
// Stream uncompressed content |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
143 |
echo $content; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
144 |
} |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
145 |
|
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 |
function getParam($name, $def = false) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
149 |
if (!isset($_GET[$name])) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
150 |
return $def; |
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 |
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
|
153 |
} |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
154 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
155 |
function getFileContents($path) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
156 |
$path = realpath($path); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
157 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
158 |
if (!$path || !@is_file($path)) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
159 |
return ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
160 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
161 |
if (function_exists("file_get_contents")) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
162 |
return @file_get_contents($path); |
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 |
$content = ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
165 |
$fp = @fopen($path, "r"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
166 |
if (!$fp) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
167 |
return ""; |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
168 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
169 |
while (!feof($fp)) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
170 |
$content .= fgets($fp); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
171 |
|
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
172 |
fclose($fp); |
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 |
return $content; |
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 putFileContents($path, $content) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
178 |
if (function_exists("file_put_contents")) |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
179 |
return @file_put_contents($path, $content); |
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 |
$fp = @fopen($path, "wb"); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
182 |
if ($fp) { |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
183 |
fwrite($fp, $content); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
184 |
fclose($fp); |
81b4499a963e
Added TinyMCE compression support and made some supporting modifications to common.php
Dan
parents:
diff
changeset
|
185 |
} |
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 |
?> |