-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.php
More file actions
64 lines (44 loc) · 1.67 KB
/
build.php
File metadata and controls
64 lines (44 loc) · 1.67 KB
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
<?php
// Base64 encode function
function base64_encode_image ($filename=string, $filetype=string) {
if ($filename) {
$imgbinary = file_get_contents($filename);
return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
}
}
// Open PHP File
$php = file_get_contents("index.php");
// Include init.php
$php_init = file_get_contents("core/init.php");
$php_init = str_replace(array("<?", "?>"), "", $php_init);
$php = str_replace('include("core/init.php");', $php_init, $php);
// Minify
// TODO: Minification.
$exploded = explode("\n", $php);
$newphp = array();
foreach ($exploded as $line)
if (substr(trim($line),0,2) != "//") $newphp[] = $line;
$php = implode("", $newphp);
$php = str_replace(array("\t", " "), array(" "), $php);
// Open CSS File, then minify
$css = file_get_contents("assets/css/main.css");
$css = str_replace(array("\n", "\t", ": ", "; ", " "), array(" ", "", ":", ";", ""), $css);
// Replace images with base64 data.
$index = 0;
$images_found = false;
while(!$images_found)
{
if(strpos($css, 'url(', $index) === false)
{ $images_found = true; continue; }
$index = $url_start = strpos($css, 'url(', $index) + 4;
$index = $url_end = strpos($css, ')', $index);
$url = substr($css, $url_start, $url_end - $url_start);
$path = str_replace("../", "assets/", $url);
$img = base64_encode_image($path, substr($path, strpos($path, ".")+1, 3));
$css = str_replace($url, $img, $css);
}
$php = str_replace('@import "<?=R; ?>assets/css/main.css";', $css, $php);
// Write compiled file
file_put_contents("build/index.php", $php);
echo 'New "Delivery" Compiled - '.@date("H:i:s");
?>