forked from sciactive/pnotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildcustom.php
47 lines (41 loc) · 1.5 KB
/
buildcustom.php
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
<?php
$type = (false ? 'inline' : 'attachment');
$ext = ($_REQUEST['mode'] !== "css" ? "js" : "css");
$mime = ($_REQUEST['mode'] !== "css" ? "text/javascript" : "text/css");
$min = !empty($_REQUEST['min']) ? 'min.' : '';
$files = explode('-', preg_replace("/[^a-z0-9-]/", '', substr($_REQUEST['modules'], 0, 256)));
if (!$files || $files === array('')) {
$content = file_get_contents('pnotify.core.'.$min.$ext);
header("Content-Disposition: $type; filename=pnotify.custom.$min$ext");
header("Content-Length: ".strlen($content));
header("Content-Type: $mime");
echo $content;
exit;
}
sort($files);
$cache_file = 'build-cache/pnotify.custom.'.implode('-', $files).'.'.$min.$ext;
if (file_exists($cache_file)) {
$content = file_get_contents($cache_file);
header("Content-Disposition: $type; filename=pnotify.custom.$min$ext");
header("Content-Length: ".strlen($content));
header("Content-Type: $mime");
echo $content;
exit;
}
$content = file_get_contents("pnotify.core.$min$ext");
foreach ($files as $cur_file) {
$filename = "pnotify.$cur_file.$min$ext";
if (!file_exists($filename)) {
if ($ext === "css")
continue;
header('HTTP/1.1 400 Bad Request', true, 400);
echo "Your request could not be completed because a file you requested is invalid.";
exit;
}
$content .= file_get_contents($filename);
}
header("Content-Disposition: $type; filename=pnotify.custom.$min$ext");
header("Content-Length: ".strlen($content));
header("Content-Type: $mime");
echo $content;
file_put_contents($cache_file, $content);