2015-09-20 11:37:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
echo("*** Preparing environment ***\n");
|
|
|
|
|
2019-03-02 21:13:41 +00:00
|
|
|
ini_set("user_agent", "Pepperminty-Wiki-Downloader PHP/" . phpversion() . "; +https://github.com/sbrl/Pepperminty-Wiki/ Pepperminty-Wiki/" . file_get_contents("version"));
|
|
|
|
|
2015-09-20 11:37:21 +00:00
|
|
|
$build_env = new stdClass();
|
|
|
|
$build_env->target = "build/index.php";
|
|
|
|
|
2019-03-02 21:13:41 +00:00
|
|
|
if(file_exists($build_env->target)) {
|
2015-09-20 11:37:21 +00:00
|
|
|
echo("Deleting old target...\n");
|
|
|
|
unlink($build_env->target);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////// Rebuild Module Index ////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
echo("*** Rebuilding module index ***\n");
|
|
|
|
$modules = glob("modules/*.php");
|
|
|
|
$module_index = [];
|
2016-03-12 15:26:30 +00:00
|
|
|
// Defined just in case a module needs to reference them when we require() them
|
|
|
|
// to gain information
|
|
|
|
$env = $paths = new stdClass();
|
2019-03-02 13:32:12 +00:00
|
|
|
$paths->extra_data_directory = "build/._extra_data";
|
2015-09-20 11:37:21 +00:00
|
|
|
|
2019-03-02 13:49:12 +00:00
|
|
|
/**
|
|
|
|
* Registers a new Pepperminty Wiki module. All module files should call this first.
|
|
|
|
* @param array $settings An associative array defining the module.
|
|
|
|
*/
|
2015-09-20 11:37:21 +00:00
|
|
|
function register_module($settings)
|
|
|
|
{
|
2019-03-02 13:32:12 +00:00
|
|
|
global $module_index, $paths;
|
2015-09-21 14:18:55 +00:00
|
|
|
|
2019-03-02 13:32:12 +00:00
|
|
|
// Prepare any extra files
|
|
|
|
if(!file_exists($paths->extra_data_directory))
|
|
|
|
mkdir($paths->extra_data_directory, 0750);
|
|
|
|
|
|
|
|
foreach($settings["extra_data"] ?? [] as $filename => $file_def) {
|
|
|
|
$destination_filename = "$paths->extra_data_directory/{$settings["id"]}/$filename";
|
|
|
|
if(!file_exists(dirname($destination_filename)))
|
|
|
|
mkdir(dirname($destination_filename), 0750, true);
|
|
|
|
|
|
|
|
$source = fopen($file_def, "r");
|
|
|
|
$destination = fopen($destination_filename, "w");
|
|
|
|
|
|
|
|
stream_copy_to_stream($source, $destination);
|
|
|
|
fclose($source);
|
|
|
|
fclose($destination);
|
|
|
|
}
|
2015-09-21 14:18:55 +00:00
|
|
|
|
2015-09-20 11:37:21 +00:00
|
|
|
$newmodule = [
|
2019-03-02 13:32:12 +00:00
|
|
|
"id" => $settings["id"],
|
2015-09-20 11:37:21 +00:00
|
|
|
"name" => $settings["name"],
|
|
|
|
"version" => $settings["version"],
|
|
|
|
"author" => $settings["author"],
|
|
|
|
"description" => $settings["description"],
|
2015-09-22 13:51:38 +00:00
|
|
|
"lastupdate" => filemtime("modules/" . $settings["id"] . ".php"),
|
2019-03-02 13:32:12 +00:00
|
|
|
// May not be set. Defaults to false
|
|
|
|
"optional" => $settings["optional"] ?? false,
|
2019-02-26 23:01:09 +00:00
|
|
|
"extra_data" => $settings["extra_data"] ?? []
|
2015-09-20 11:37:21 +00:00
|
|
|
];
|
|
|
|
$module_index[] = $newmodule;
|
|
|
|
}
|
|
|
|
|
2019-02-26 19:48:04 +00:00
|
|
|
$module_count = count($modules);
|
|
|
|
$i = 1;
|
2015-09-20 11:37:21 +00:00
|
|
|
foreach($modules as $filename)
|
|
|
|
{
|
2019-02-26 19:48:04 +00:00
|
|
|
echo("[$i / $module_count] Processing $filename \r");
|
2015-09-20 11:37:21 +00:00
|
|
|
require($filename);
|
2019-02-26 19:48:04 +00:00
|
|
|
$i++;
|
2015-09-20 11:37:21 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 19:48:04 +00:00
|
|
|
echo("\n*** Processing complete ***\n");
|
2015-09-20 11:37:21 +00:00
|
|
|
|
|
|
|
echo("Writing new module index to disk...");
|
|
|
|
file_put_contents("module_index.json", json_encode($module_index, JSON_PRETTY_PRINT));
|
|
|
|
echo("done\n");
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////// Build New Target //////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
require("pack.php");
|
|
|
|
|
|
|
|
?>
|