1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17:
18: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
19:
20:
21: @error_reporting(E_ERROR | E_WARNING | E_PARSE);
22:
23:
24: $plugins = explode(',', getParam("plugins", ""));
25: $languages = explode(',', getParam("languages", ""));
26: $themes = explode(',', getParam("themes", ""));
27: $diskCache = getParam("diskcache", "") == "true";
28: $isJS = getParam("js", "") == "true";
29: $compress = getParam("compress", "true") == "true";
30: $core = getParam("core", "true") == "true";
31: $suffix = getParam("suffix", "_src") == "_src" ? "_src" : "";
32: $cachePath = realpath(".");
33: $expiresOffset = 3600 * 24 * 10;
34: $content = "";
35: $encodings = array();
36: $supportsGzip = false;
37: $enc = "";
38: $cacheKey = "";
39:
40:
41: $custom = array( 42: 43: 44: );
45:
46:
47: header("Content-type: text/javascript");
48: header("Vary: Accept-Encoding");
49: header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
50:
51:
52: if (!$isJS) {
53: echo getFileContents("tiny_mce_gzip.js");
54: echo "tinyMCE_GZ.init({});";
55: die();
56: }
57:
58:
59: if ($diskCache) {
60: if (!$cachePath)
61: die("alert('Real path failed.');");
62:
63: $cacheKey = getParam("plugins", "") . getParam("languages", "") . getParam("themes", "") . $suffix;
64:
65: foreach ($custom as $file)
66: $cacheKey .= $file;
67:
68: $cacheKey = md5($cacheKey);
69:
70: if ($compress)
71: $cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".gz";
72: else
73: $cacheFile = $cachePath . "/tiny_mce_" . $cacheKey . ".js";
74: }
75:
76:
77: if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
78: $encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
79:
80: if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
81: $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
82: $supportsGzip = true;
83: }
84:
85:
86: if ($diskCache && $supportsGzip && file_exists($cacheFile)) {
87: if ($compress)
88: header("Content-Encoding: " . $enc);
89:
90: echo getFileContents($cacheFile);
91: die();
92: }
93:
94:
95: if ($core == "true") {
96: $content .= getFileContents("tiny_mce" . $suffix . ".js");
97:
98:
99: $content .= "tinyMCE_GZ.start();";
100: }
101:
102:
103: foreach ($languages as $lang)
104: $content .= getFileContents("langs/" . $lang . ".js");
105:
106:
107: foreach ($themes as $theme) {
108: $content .= getFileContents( "themes/" . $theme . "/editor_template" . $suffix . ".js");
109:
110: foreach ($languages as $lang)
111: $content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js");
112: }
113:
114:
115: foreach ($plugins as $plugin) {
116: $content .= getFileContents("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
117:
118: foreach ($languages as $lang)
119: $content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js");
120: }
121:
122:
123: foreach ($custom as $file)
124: $content .= getFileContents($file);
125:
126:
127: if ($core == "true")
128: $content .= "tinyMCE_GZ.end();";
129:
130:
131: if ($supportsGzip) {
132: if ($compress) {
133: header("Content-Encoding: " . $enc);
134: $cacheData = gzencode($content, 9, FORCE_GZIP);
135: } else
136: $cacheData = $content;
137:
138:
139: if ($diskCache && $cacheKey != "")
140: putFileContents($cacheFile, $cacheData);
141:
142:
143: echo $cacheData;
144: } else {
145:
146: echo $content;
147: }
148:
149:
150:
151: function getParam($name, $def = false) {
152: if (!isset($_GET[$name]))
153: return $def;
154:
155: return preg_replace("/[^0-9a-z\-_,]+/i", "", $_GET[$name]);
156: }
157:
158: function getFileContents($path) {
159: $path = realpath($path);
160:
161: if (!$path || !@is_file($path))
162: return "";
163:
164: if (function_exists("file_get_contents"))
165: return @file_get_contents($path);
166:
167: $content = "";
168: $fp = @fopen($path, "r");
169: if (!$fp)
170: return "";
171:
172: while (!feof($fp))
173: $content .= fgets($fp);
174:
175: fclose($fp);
176:
177: return $content;
178: }
179:
180: function putFileContents($path, $content) {
181: if (function_exists("file_put_contents"))
182: return @file_put_contents($path, $content);
183:
184: $fp = @fopen($path, "wb");
185: if ($fp) {
186: fwrite($fp, $content);
187: fclose($fp);
188: }
189: }
190: ?>