-
Notifications
You must be signed in to change notification settings - Fork 59
/
minifier.php
47 lines (41 loc) · 1.51 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
44
45
46
47
<?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
*
* António 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 António Almeida, promatik.
*/
function minifyJS($arr)
{
minify($arr, 'https://www.toptal.com/developers/javascript-minifier/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 = ['http' => [
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(['input' => $content]), ]];
return file_get_contents($url, false, stream_context_create($postdata));
}