forked from promatik/PHP-JS-CSS-Minifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minifier.php
43 lines (38 loc) · 1.36 KB
/
minifier.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
<?php
/*
* JS and CSS Minifier
* version: 1.0 (2013-08-26)
*
* This document is licensed as free software under the terms of the
* MIT License: http://www.opensource.org/licenses/mit-license.php
*
* Toni Almeida wrote this plugin, which proclaims:
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK."
*
* This plugin uses online webservices from javascript-minifier.com and cssminifier.com
* This services are property of Andy Chilton, http://chilts.org/
*
* Copyrighted 2013 by Toni Almeida, promatik.
*/
function minifyJS($arr){
minify($arr, 'https://javascript-minifier.com/raw');
}
function minifyCSS($arr){
minify($arr, 'https://cssminifier.com/raw');
}
function minify($arr, $url) {
foreach ($arr as $key => $value) {
$handler = fopen($value, 'w') or die("File <a href='" . $value . "'>" . $value . "</a> error!<br />");
fwrite($handler, getMinified($url, file_get_contents($key)));
fclose($handler);
echo "File <a href='" . $value . "'>" . $value . "</a> done!<br />";
}
}
function getMinified($url, $content) {
$postdata = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( array('input' => $content) ) ) );
return file_get_contents($url, false, stream_context_create($postdata));
}
?>