-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-assets.php
executable file
·57 lines (51 loc) · 1.67 KB
/
build-assets.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
48
49
50
51
52
53
54
55
56
57
<?php
define('CACHE', true);
define('COMPRESS', true);
if (empty($_GET['type']) or empty($_GET['filename'])) {
header('Status: 406 Not acceptable');
throw new Exception('Missing vital parameters');
}
$assets = array(
'css' => array(
'content-type' => 'text/css',
'files' => array(
'assets/style.css',
'assets/form.css',
'assets/form-elements.css',
'assets/collapsable.css',
'assets/tooltip.css',
),
),
'js' => array(
'content-type' => 'text/javascript',
'files' => array(
'assets/storage.js',
'assets/collapsable.js',
'assets/script.js',
),
)
);
$type = $_GET['type'];
if (!isset($assets[$type])) {
header('Status: 406 Not acceptable');
throw new Exception('Invalid assets type "'.$type.'" defined');
}
$asset = $assets[$type];
$result = implode("\n", array_map('file_get_contents', $asset['files']));
if (COMPRESS) {
if ($type === 'css') {
require 'classes/vendor/cssmin.class.php';
$result = cssmin::minify($result);
} elseif ($type === 'js') {
require 'classes/vendor/JSMinPlus.class.php';
$result = JSMinPlus::minify($result);
}
}
if (CACHE) {
file_put_contents($_GET['filename'], $result);
chmod($_REQUEST['filename'], 0666);
header('Location: '.$_SERVER['REQUEST_URI']);
} else {
header('Content-Type: '.$asset['content-type']);
echo $result;
}