-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrake.php
95 lines (88 loc) · 1.88 KB
/
rake.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
function ctype_var($s)
{
return ctype_alnum($s) || $s == "_";
}
function parse_php( $filename, $minify = true, $include = false )
{
$file = file($filename);
$out = "";
foreach($file as $v)
{
if ($minify)
{
$v = trim($v);
}
else
{
$v = rtrim($v);
}
$v = preg_replace_callback("/\/\/.*/",function($i){ return strstr($i[0],'"')===false ? "" : $i[0]; },$v);
if ($v == "<?" || $v == "<?php")
{
if ($include) $v = "";
else $v = "<?php ";
}
else if ($v == "?>")
{
if ($include) $v = "";
}
else if (preg_match("/(include|require|include_once|require_once)\((.*)\);/",$v,$m))
{
if (preg_match("/^['\"].*['\"]$/",trim($m[2])))
{
$includeFile = trim($m[2],"'\"");
$v = parse_php($includeFile, $minify, true);
}
}
if ($minify)
{
$out .= $v." ";
}
else
{
$out .= $v."\n";
}
}
$out = preg_replace("/\/\*.*?\*\//ims","",$out);
if ($minify)
{
$out = preg_replace("/\s+/"," ",$out);
}
else
{
$out = preg_replace("/\n+/","\n",$out);
}
if ($minify)
{
$inString = false;
for($x=0;$x<strlen($out);$x++)
{
if ($x && $out[$x]=='"' && $out[$x-1]!="\\")
{
$inString = !$inString;
continue;
}
if ($inString)
{
continue;
}
if ($x && $out[$x]==" " && !(ctype_var($out[$x-1]) && ctype_var($out[$x+1])) )
{
$out = substr($out,0,$x) . substr($out,$x+1);
$x--;
}
}
//$out = preg_replace("/\"\.\"/","",$out);
}
return $out;
}
chdir("contentifier");
header("Content-type: text/plain; charset=utf-8");
$out = parse_php( "contentifier.php", true );
echo $out;
file_put_contents("../contentifier.min.php",$out);
$out = parse_php( "contentifier.php", false );
//echo $out;
file_put_contents("../contentifier.php",$out);
?>