forked from vanilla/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.php
executable file
·81 lines (61 loc) · 2.13 KB
/
make.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
#!/opt/local/bin/php
<?php
header('Content-Type: text/plain');
// Make the final vanilla2export.php file from the other sources.
$Path = dirname(__FILE__) . '/vanilla2export.php';
if (file_exists($Path)) {
$r = unlink($Path);
if (!$r) {
echo "Could not delete $Path.\n";
die();
}
}
// Open the file.
echo "Opening $Path\n";
$fp = fopen($Path, 'w');
fwrite($fp, "<?php /* This file was automatically generated by make.php. DO NOT EDIT. */ ?>\n\n");
AddFile($fp, 'index.php');
fclose($fp);
echo "Make Complete.\n";
/// Functions ///
function AddFile($fp, $Filename) {
// Recursively build file
$Contents = GetFile($Filename);
// Include individual software porters (undo MAKESKIP)
$Paths = glob('packages/*.php');
$Exporters = '';
foreach ($Paths as $Path) {
$Exporters .= GetFile($Path);
}
$Contents = str_replace('// [EXPORTERS]', ' ?>' . $Exporters . '<?php ', $Contents);
// Write the all-in-one file
fwrite($fp, $Contents);
}
function GetFile($Filename, $EndPhp = false) {
$Path = dirname(__FILE__) . '/' . $Filename;
echo "Including file $Path\n";
$Contents = file_get_contents($Path);
// MAKESKIP
$Contents = preg_replace('/MAKESKIPSTART(.*)MAKESKIPEND/s', '[EXPORTERS]', $Contents);
// Inline any stylesheet includes.
$Contents = preg_replace_callback('/<link.*?href=[\'"](.*?)[\'"].*?\/>/i', 'ReplaceStyleCallback', $Contents);
// Inline any includes.
$Contents = preg_replace_callback('/include_once [\'"](.*?)[\'"]\;/', 'ReplaceIncludeCallback', $Contents);
// End and begin the php context.
if ($EndPhp) {
$Contents = "\n/* Contents included from $Filename */\n?>" . $Contents . "<?php\n";
}
return $Contents;
}
function ReplaceIncludeCallback($Matches) {
$Path = $Matches[1];
$Contents = GetFile($Path, true);
$Result = $Contents;
return $Result;
}
function ReplaceStyleCallback($Matches) {
$Path = $Matches[1];
$Contents = file_get_contents(dirname(__FILE__) . '/' . $Path);
$Result = "<!-- Contents included from $Path -->\n<style>\n" . $Contents . "\n</style>";
return $Result;
}