1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 05:22:59 +00:00

Use a clever hack to get the file descriptor of the ZipArchive and peel the data out.

Not sure if it'll work yet though, as we've run into a bit of a snag 
with the module loading.....
This commit is contained in:
Starbeamrainbowlabs 2019-03-02 12:24:11 +00:00
parent 969deef567
commit 7cd57c894f
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
5 changed files with 55 additions and 9976 deletions

View file

@ -21,6 +21,7 @@ $module_index = [];
// Defined just in case a module needs to reference them when we require() them
// to gain information
$env = $paths = new stdClass();
$paths->extra_data_directory = "._extra_data";
function register_module($settings)
{

File diff suppressed because it is too large Load diff

View file

@ -66,6 +66,8 @@ foreach ($paths as &$path) {
/** The master settings file @var string */
$paths->settings_file = $settingsFilename;
/** The directory to which the extra bundled data is extracted to @var string */
$paths->extra_data_directory = "._extra_data";
/** The prefix to add to uploaded files */
$paths->upload_file_prefix = "Files/";
@ -1696,7 +1698,7 @@ $actions = new stdClass();
* Registers a new action handler.
* @package core
* @param string $action_name The action to register.
* @param function $func The function to call when the specified
* @param callable $func The function to call when the specified
* action is requested.
*/
function add_action($action_name, $func)
@ -1709,7 +1711,7 @@ function add_action($action_name, $func)
* Only guaranteed to be accurate in inside an existing action function
* @package core
* @param string $action_name The name of the action to search for
* @return boolean Whether an action with the specified name exists.
* @return bool Whether an action with the specified name exists.
*/
function has_action($action_name)
{
@ -1731,8 +1733,8 @@ $parsers = [
* Registers a new parser.
* @package core
* @param string $name The name of the new parser to register.
* @param function $parser_code The function to register as a new parser.
* @param function $hash_generator A function that should take a single argument of the input source text, and return a unique hash for that content. The return value is used as the filename for cache entries, so should be safe to use as such.
* @param callable $parser_code The function to register as a new parser.
* @param callable $hash_generator A function that should take a single argument of the input source text, and return a unique hash for that content. The return value is used as the filename for cache entries, so should be safe to use as such.
*/
function add_parser($name, $parser_code, $hash_generator) {
global $parsers;
@ -1794,7 +1796,7 @@ $save_preprocessors = [];
* Register a new proprocessor that will be executed just before
* an edit is saved.
* @package core
* @param function $func The function to register.
* @param callable $func The function to register.
*/
function register_save_preprocessor($func)
{
@ -1839,7 +1841,7 @@ function statistic_add($stat_data) {
* Checks whether a specified statistic has been registered.
* @package core
* @param string $stat_id The id of the statistic to check the existence of.
* @return boolean Whether the specified statistic has been registered.
* @return bool Whether the specified statistic has been registered.
*/
function has_statistic($stat_id) {
global $statistic_calculators;
@ -1909,4 +1911,4 @@ else
exit(page_renderer::render_main("Error - $settings->sitename", "<p>No action called " . strtolower($_GET["action"]) ." has been registered. Perhaps you are missing a module?</p>"));
}
?>
__halt_compiler();

View file

@ -215,8 +215,10 @@ register_module([
}
]);
require_once("./Parsedown.php");
require_once("./ParsedownExtra.php");
if(file_exists($paths->extra_data_directory)) {
require_once("$paths->extra_data_directory/Parsedown.php");
require_once("$paths->extra_data_directory/ParsedownExtra.php");
}
/**
* Attempts to 'auto-correct' a page name by trying different capitalisation

View file

@ -1,10 +1,18 @@
<?php
if(php_sapi_name() == "cli") {
echo("*** Beginning main build sequence ***\n");
echo("Reading in module index...\n");
/**
* Logs a string to stdout, but only on the CLI.
* @param string $line The line to log.
*/
function log(string $line) {
if(php_sapi_name() == "cli")
echo($line);
//else error_log($line);
}
log("*** Beginning main build sequence ***\n");
log("Reading in module index...\n");
$module_index = json_decode(file_get_contents("module_index.json"));
$module_list = [];
foreach($module_index as $module)
@ -24,15 +32,15 @@ foreach($module_index as $module)
if(isset($_GET["modules"]))
$module_list = explode(",", $_GET["modules"]);
if(php_sapi_name() != "cli")
{
if(php_sapi_name() != "cli") {
header("content-type: text/php");
header("content-disposition: attachment; filename=\"index.php\"");
}
if(php_sapi_name() == "cli") echo("Reading in core files...\n");
log("Reading in core files...\n");
$core = file_get_contents("core.php");
// We trim from the end here because of the __halt_compiler() directive
$core = rtrim(file_get_contents("core.php"));
$settings = file_get_contents("settings.fragment.php");
$settings = str_replace([ "<?php", "?>" ], "", $settings);
$core = str_replace([
@ -57,18 +65,22 @@ if($extra_data_archive->open("php://temp/maxmemory:".(5*1024*1024), ZipArchive::
exit("Error: Failed to create temporary stream to store packing information");
}
// HACK! Determine the file descriptor of the ZipArchvie
$temp = fopen("php://memory", "w");
$archive_file_descriptor = $temp - 1;
fclose($temp);
$module_list_count = count($module_list);
$i = 1;
foreach($module_list as $module)
{
if($module->id == "") continue;
if(php_sapi_name() == "cli")
echo("[$i / $module_list_count] Adding $module->id \r");
log("[$i / $module_list_count] Adding $module->id \r");
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module->id) . ".php";
//echo("id: $module->id | filepath: $module_filepath\n");
//log("id: $module->id | filepath: $module_filepath\n");
if(!file_exists($module_filepath)) {
http_response_code(400);
@ -95,23 +107,27 @@ foreach($module_list as $module)
$i++;
}
echo("\n");
log("\n");
if(php_sapi_name() == "cli")
{
$archive_stream = fopen("php://fd/$archive_file_descriptor", "r");
$output_stream = null;
if(php_sapi_name() == "cli") {
if(file_exists("build/index.php")) {
echo("index.php already exists in the build folder, exiting\n");
log("index.php already exists in the build folder, exiting\n");
exit(1);
}
else {
echo("Done. Saving to disk...");
file_put_contents("build/index.php", $result);
echo("complete!\n");
echo("*** Build completed! ***\n");
}
log("Done. Saving to disk...");
$output_stream = fopen("build/index.php", "w");
log("complete!\n");
log("*** Build completed! ***\n");
}
else {
exit($result);
$output_stream = fopen("php://output", "w");
}
fwrite($output_stream, $result);
stream_copy_to_stream($archive_stream, $output_stream);
?>