-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.php
More file actions
executable file
·280 lines (221 loc) · 9.75 KB
/
Copy pathloader.php
File metadata and controls
executable file
·280 lines (221 loc) · 9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
require_once dirname(__FILE__) . "/library/session.php";
require_once dirname(__FILE__) . "/config/debug.php";
require_once dirname(__FILE__) . "/library/functions.php";
require_once dirname(__FILE__) . "/library/constants.core.php";
require_once dirname(__FILE__) . "/library/functions.variables.php";
require_once LIBRARY . "functions.core.php";
require_once LIBRARY . "constants.time.php";
require_once LIBRARY . "variables.time.php";
require_once LIBRARY . "functions.time.php";
require_once CONFIG . "settings.php";
require_once LIBRARY . "outputbuffer.php";
// Use memcache if it's available
require_once LIBRARY . "memcache.php";
require_once LIBRARY . "functions.presentation.php";
require_once LIBRARY . "functions.media.php";
define("LOCATION", get_location(!is_admin()));
$_GET['file'] = str_replace_once(LOCATION, '', $_SERVER['REQUEST_URI']);
if (($_GET['file'] != $_SERVER['REQUEST_URI']) && (($pos = strpos($_SERVER['REQUEST_URI'], $_GET['file'])) !== false)) {
// might need to do some adjusting to the file name...
//RewriteRule ^(.*)/(.+)\.([0-9]{10,})\.(js|css|gif|jpg|png)$ $1/$2.$4 [L,QSA]
$full = substr($_SERVER['REQUEST_URI'], $pos);
$full = preg_replace('/\.([0-9]{10,})\./', '.', $full);
if ($full != $_GET['file']) {
$_GET['file'] = $full;
}
}
// experimental way of handling images...
if (isset($_GET['file']) && strpos($_GET['file'], '/images/') !== false) {
//$file = trim_explode('/images/', $_GET['file']);
//$_GET['file'] = current($file) . '/images/' . end($file);
$urls = trim_explode('/', $_GET['file']);
$pre = $post = array();
$imagesFound = false;
foreach ($urls as $url) {
if (!$imagesFound) {
if ($url == 'images') {
$imagesFound = true;
} else {
$pre[] = $url;
}
} else {
$post[] = $url;
}
}
foreach ($pre as $p) {
if (is_dir(ABSPATH . 'sites/' . $p)) {
set_var('site', $p);
} else if (is_dir(ABSPATH . 'sites/' . get_folder() . '/' . $p)) {
set_var('theme', $p);
}
}
$filename = 'images/' . join($post);//end($urls);
$path = "sites/" . get_folder() . "/" . get_theme() . "/";//substr($_GET['file'], 0, strpos($_GET['file'], $filename));
$_GET['file'] = $path . $filename;
} else if (strpos($_GET['file'], 'uploads/') !== false) {
$_GET['file'] = substr($_GET['file'], strpos($_GET['file'], 'uploads/'));
}
if (isset($_GET['file']) && ((strpos($_GET['file'], '/files/') !== false))) {
$_GET['file'] = substr($_GET['file'], strpos($_GET['file'], "/files/"));
}
if (isset($_GET['file']) && !is_file($_GET['file'])) {
$_GET['file'] = str_replace("sites/main/default/", "sites/" . get_folder() . "/" . get_theme() . "/", $_GET['file']);
}
if (isset($_GET['file']) && substr($_GET['file'], 0, strlen("sites/")) != "sites/") {
$_GET['file'] = "sites/" . get_folder() . "/" . get_theme() . "/" . $_GET['file'];
}
// GET TO THE MEAT OF THINGS
if (isset($_GET['file']) && is_file($_GET['file']) && (!isset($_GET['width']) && !isset($_GET['height']) && !isset($_GET['cropratio']))) :
$ext = get_ext($_GET['file']);
if ($ext == 'js') :
$mime = 'application/x-javascript';
elseif ($ext == 'css') :
$mime = 'text/css';
elseif ($ext == 'gif') :
$mime = 'image/gif';
elseif (in_array($ext, array('jpg', 'jpeg'))) :
$mime = 'image/jpeg';
elseif ($ext == 'png') :
$mime = 'image/png';
else :
$mime = mime_content_type($_GET['file']);
endif;
header("Content-type: " . $mime);
if (true){//PRODUCTION) {
$expires = 60*60*24*7; // 1 week
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
}
readfile($_GET['file']);
elseif (isset($_GET['file'])) :
// DYNAMIC LINK TO A JS|CSS|IMAGE
$fileName = $originalFile = $_GET['file'];
$type = (isset($_GET['type'])) ? $_GET['type'] : 'uploads';
// Once we've figured out where the file is located, now lets handle it according to its type
if (in_array($type, array('javascripts', 'stylesheets'))) :
// Stylesheets and Javascripts
$file = get_presentation_file($fileName);
// Get mime type...
$mime = false;
if ($type == 'javascripts') :
$mime = 'application/x-javascript';
elseif ($type == 'stylesheets') :
$mime = 'text/css';
else :
// If it gets this far, usually that's a bad sign... leave commented to just use text/plain
//$mime = mime_content_type($file['path'] . $file['name'] . '.' . $file['ext']);
endif;
if ($file['found']) :
if ($mime) header("Content-type: " . $mime);
include(($file['path'] . $file['name'] . '.' . $file['ext']));
endif;
elseif (in_array($type, array('images', 'uploads'))) :
// Images
// A little tougher... need to read image...
//require_once LIBRARY . "class.img.php";
if ($type == 'uploads')
$fileName = str_replace("sites/" . get_folder() . "/" . get_theme() . "/", '', $fileName);
if (strpos($_SERVER['REQUEST_URI'], '/plugins/') !== false) {
$plugin = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '/plugins/')+1);
$plugin = substr($plugin, 0, strpos($plugin, '/', strlen('plugins/')));
$fileName = str_replace("sites/" . get_folder() . "/" . get_theme() . "/", $plugin . "/", $fileName);
}
$ext = get_ext($fileName);
$fileName = strip_ext($fileName);
$w = false;
$h = false;
$c = false;
// explode by _, then check for w**, h** c** then put the filename back together
$parts = trim_explode('_', $fileName);
for ($i=count($parts)-1; $i>=0; $i--) {
if (substr($parts[$i], 0, 2) == 'cr') {
$c = substr($parts[$i], 2);
unset($parts[$i]);
} else if (substr($parts[$i], 0, 2) == 'he') {
$h = substr($parts[$i], 2);
unset($parts[$i]);
} else if (substr($parts[$i], 0, 2) == 'wi') {
$w = substr($parts[$i], 2);
unset($parts[$i]);
} else {
break;
}
}
$fileName = join("_", $parts) . '.' . $ext;
$errors = create_image($fileName, false, $w, $h, $c);
// if create_image returns errors
if (is_string($errors))
echo $errors;
endif;
elseif (isset($_GET['flinturl']) && isset($_GET['type'])) :
// LOADER FOR ALL JS|CSS FILES FOR GIVEN ROUTE
$q = $_GET['flinturl'];
$type = $_GET['type'];
// Include all variables and functions allowing for routes to work
require_once CONFIG . "defaults.php";
require_once CONFIG . "routes.php";
require_once LIBRARY . "functions.routes.php";
// Get all the variables as assigned from the routes and assign them to the global Flint variable
set_vars(get_route_vars($q));
// Get all the files of requested type to load in this one file...
if ($type == 'javascripts') :
$files = get_javascripts();
$ext = 'js';
header("Content-type: application/x-javascript");
elseif ($type == 'stylesheets') :
$files = get_stylesheets();
$ext = 'css';
header("Content-type: text/css");
endif;
foreach ($files as $orig_file) :
clearstatcache();
$file = get_presentation_file($orig_file, $ext);
if ($file['found']) :
#if the file doesn't exist or the time stamp time of both compressed and uncompressed files are not near
$cache_file = CACHE . "{$type}/" . str_replace("/", '__', $file['path'] . $file['name'] . '.' . $file['ext']);
if (!file_exists($cache_file) || ((filemtime($file['path'] . $file['name'] . '.' . $file['ext']) - filemtime($cache_file)) > 3)) {
$code = file_get_contents($file['path'] . $file['name'] . '.' . $file['ext']); # get code
if ($type == 'javascripts') { # if a JS file
if (strpos($code, "/** DON'T PACK **/") !== false) {
$packed = $code;
} else if ((strpos($code, "/** PACKER **/") !== false) && is_file(LIBRARY . "class.JavascriptPacker.php")) {
require_once LIBRARY . "class.JavascriptPacker.php"; # include Packer class
$script = str_replace(';;;', '//', $code); # the ;;; comment feature in the packer beta
$packer = new JavaScriptPacker($script, 62, 1, 0); # using Dean Edwards ’s Packer, check documentations on the class file for the best compression level
$packed = $packer->pack(); # JS code compressed
} else {
$packed = compress_javascript($code);
}
} else { # if CSS file
$packed = compress_stylesheet($code);
while (strpos($packed, '@import url(') !== false) :
$import = scrape($packed, '@import url(', ');');
$pre_packed = substr($packed, 0, strpos($packed, '@import url('));
$post_packed = substr($packed, strpos($packed, $import . ');') + strlen($import . ');'));
//$compressed_contents = preg_replace("/@import url\((.+)\);/", '', $compressed_contents);
$import = str_replace("'", '', str_replace('"', '', $import));
$import_file = get_presentation_file($import, $ext);
//include_once($file['path'] . $file['name'] . '.' . $file['ext']);
$file_contents = file_get_contents($import_file['path'] . $import_file['name'] . '.' . $import_file['ext']);
$packed = $pre_packed . compress_stylesheet($file_contents) . "\n" . $post_packed;
unset($pre_packed);
unset($post_packed);
endwhile;
}
file_put_contents($cache_file, trim($packed)); # inserting compressed code into files
//touch($file); # change the time stamp time for original scripts
#$GLOBALS['debuger'][] = "$js generated, diff was $diff"; # Global array to let you see results
}
$compressed_contents = file_get_contents($cache_file) . "\n";
if (!PRODUCTION)
echo "\n/* " . $file['path'] . $file['name'] . "." . $file['ext'] . " */\n";
echo $compressed_contents;
else :
echo "\n/* Could not load file: " . $orig_file . " */\n";
endif;
endforeach;
endif;
stop_outputBuffer();
?>