2014-12-25 20:31:01 +00:00
|
|
|
<?php
|
2015-05-08 19:03:15 +00:00
|
|
|
|
2015-05-24 15:24:03 +00:00
|
|
|
if(php_sapi_name() == "cli")
|
|
|
|
{
|
|
|
|
echo("Beginning build...\n");
|
|
|
|
echo("Reading in module index...\n");
|
|
|
|
}
|
|
|
|
|
2015-05-08 19:03:15 +00:00
|
|
|
$module_index = json_decode(file_get_contents("module_index.json"));
|
|
|
|
$module_list = [];
|
|
|
|
foreach($module_index as $module)
|
|
|
|
{
|
|
|
|
$module_list[] = $module->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($_GET["modules"]))
|
|
|
|
{
|
|
|
|
$module_list = explode(",", $_GET["modules"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(php_sapi_name() != "cli")
|
|
|
|
{
|
|
|
|
header("content-type: text/php");
|
|
|
|
}
|
|
|
|
|
2015-05-24 15:24:03 +00:00
|
|
|
if(php_sapi_name() == "cli") echo("Reading in core files...");
|
|
|
|
|
2015-05-08 19:03:15 +00:00
|
|
|
$core = file_get_contents("core.php");
|
|
|
|
$settings = file_get_contents("settings.fragment.php");
|
|
|
|
$settings = str_replace([ "<?php", "?>" ], "", $settings);
|
|
|
|
$core = str_replace("{settings}", $settings, $core);
|
|
|
|
|
|
|
|
$result = $core;
|
|
|
|
|
|
|
|
foreach($module_list as $module_id)
|
|
|
|
{
|
|
|
|
if($module_id == "") continue;
|
|
|
|
|
2015-05-24 15:24:03 +00:00
|
|
|
if(php_sapi_name() == "cli") echo("Adding $module_id\n");
|
|
|
|
|
2015-05-08 19:03:15 +00:00
|
|
|
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module_id) . ".php";
|
|
|
|
|
|
|
|
//echo("id: $module_id | filepath: $module_filepath\n");
|
|
|
|
|
|
|
|
if(!file_exists($module_filepath))
|
|
|
|
{
|
|
|
|
http_response_code(400);
|
|
|
|
exit("Failed to load module with name: $module_filepath");
|
|
|
|
}
|
|
|
|
|
|
|
|
$modulecode = file_get_contents($module_filepath);
|
|
|
|
$modulecode = str_replace([ "<?php", "?>" ], "", $modulecode);
|
|
|
|
$result = str_replace(
|
|
|
|
"// %next_module% //",
|
|
|
|
"$modulecode\n// %next_module% //",
|
|
|
|
$result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(php_sapi_name() == "cli")
|
|
|
|
{
|
|
|
|
if(file_exists("index.php"))
|
|
|
|
{
|
2015-05-24 15:24:03 +00:00
|
|
|
echo("index.php already exists, exiting\n");
|
2015-05-08 19:03:15 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-24 15:24:03 +00:00
|
|
|
echo("Done. Saving to disk...");
|
2015-05-08 19:03:15 +00:00
|
|
|
file_put_contents("index.php", $result);
|
2015-05-24 15:24:03 +00:00
|
|
|
echo("complete!\n");
|
|
|
|
echo("*** Build Completed ***\n");
|
2015-05-08 19:03:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exit($result);
|
|
|
|
}
|
|
|
|
|
2015-04-25 13:18:03 +00:00
|
|
|
?>
|