-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_minify.php
68 lines (45 loc) · 1.67 KB
/
r_minify.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
58
59
60
61
62
63
64
65
66
67
68
<?php
class minify{
public $file_types;
public $minify_path;
public $curr_path;
private $edit;
public function __construct(){
include "r_editor.php";
$this->edit = new r_editor();
$curr_path = getcwd();
}
function minify($download=false, $file_types=array('js','txt','css'), $minify_path='minify' ){
$this->file_types = $file_types;
$this->minify_path = $minify_path;
@mkdir($this->minify_path);
$files = array();
foreach($file_types as $file_type){
$files[] = glob("*.".$file_type);
}
foreach($files as $file){
foreach($file as $filename){
$filename_ = explode(".", $filename);
$filename_[count($filename_) - 1] = "min.".$filename_[count($filename_) - 1];
$filename_ = implode(".", $filename_);
$filepath = $this->curr_path.$filename;
$minifile = $this->minify_path."/".$filename_;
@unlink(str_replace("\\","/",$minifile));
$string = file_get_contents(str_replace("\\","/",$filepath));
$string = $this->edit->uncomment($string);
$string = preg_replace('/\s+/',' ',$string);
$string = str_replace('<?php','<?php ',$string);
file_put_contents(str_replace("\\","/",$minifile),$string);
if($download == true):
@header('Content-Type: application/octet-stream');
@header("Content-Transfer-Encoding: Binary");
@header("Content-disposition: attachment; filename=\"" . basename($minifile) );
@readfile($minifile);
endif;
}
}
/*print_r($file);*/
die;
}
}
?>