1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +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 // Defined just in case a module needs to reference them when we require() them
// to gain information // to gain information
$env = $paths = new stdClass(); $env = $paths = new stdClass();
$paths->extra_data_directory = "._extra_data";
function register_module($settings) 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 */ /** The master settings file @var string */
$paths->settings_file = $settingsFilename; $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 */ /** The prefix to add to uploaded files */
$paths->upload_file_prefix = "Files/"; $paths->upload_file_prefix = "Files/";
@ -1696,7 +1698,7 @@ $actions = new stdClass();
* Registers a new action handler. * Registers a new action handler.
* @package core * @package core
* @param string $action_name The action to register. * @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. * action is requested.
*/ */
function add_action($action_name, $func) 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 * Only guaranteed to be accurate in inside an existing action function
* @package core * @package core
* @param string $action_name The name of the action to search for * @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) function has_action($action_name)
{ {
@ -1731,8 +1733,8 @@ $parsers = [
* Registers a new parser. * Registers a new parser.
* @package core * @package core
* @param string $name The name of the new parser to register. * @param string $name The name of the new parser to register.
* @param function $parser_code The function to register as a new parser. * @param callable $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 $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) { function add_parser($name, $parser_code, $hash_generator) {
global $parsers; global $parsers;
@ -1794,7 +1796,7 @@ $save_preprocessors = [];
* Register a new proprocessor that will be executed just before * Register a new proprocessor that will be executed just before
* an edit is saved. * an edit is saved.
* @package core * @package core
* @param function $func The function to register. * @param callable $func The function to register.
*/ */
function register_save_preprocessor($func) function register_save_preprocessor($func)
{ {
@ -1839,7 +1841,7 @@ function statistic_add($stat_data) {
* Checks whether a specified statistic has been registered. * Checks whether a specified statistic has been registered.
* @package core * @package core
* @param string $stat_id The id of the statistic to check the existence of. * @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) { function has_statistic($stat_id) {
global $statistic_calculators; 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>")); 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"); if(file_exists($paths->extra_data_directory)) {
require_once("./ParsedownExtra.php"); 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 * Attempts to 'auto-correct' a page name by trying different capitalisation

View file

@ -1,10 +1,18 @@
<?php <?php
if(php_sapi_name() == "cli") { /**
echo("*** Beginning main build sequence ***\n"); * Logs a string to stdout, but only on the CLI.
echo("Reading in module index...\n"); * @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_index = json_decode(file_get_contents("module_index.json"));
$module_list = []; $module_list = [];
foreach($module_index as $module) foreach($module_index as $module)
@ -24,15 +32,15 @@ foreach($module_index as $module)
if(isset($_GET["modules"])) if(isset($_GET["modules"]))
$module_list = explode(",", $_GET["modules"]); $module_list = explode(",", $_GET["modules"]);
if(php_sapi_name() != "cli") if(php_sapi_name() != "cli") {
{
header("content-type: text/php"); header("content-type: text/php");
header("content-disposition: attachment; filename=\"index.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 = file_get_contents("settings.fragment.php");
$settings = str_replace([ "<?php", "?>" ], "", $settings); $settings = str_replace([ "<?php", "?>" ], "", $settings);
$core = str_replace([ $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"); 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); $module_list_count = count($module_list);
$i = 1; $i = 1;
foreach($module_list as $module) foreach($module_list as $module)
{ {
if($module->id == "") continue; if($module->id == "") continue;
if(php_sapi_name() == "cli") log("[$i / $module_list_count] Adding $module->id \r");
echo("[$i / $module_list_count] Adding $module->id \r");
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module->id) . ".php"; $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)) { if(!file_exists($module_filepath)) {
http_response_code(400); http_response_code(400);
@ -95,23 +107,27 @@ foreach($module_list as $module)
$i++; $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")) { 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); exit(1);
} }
else {
echo("Done. Saving to disk..."); log("Done. Saving to disk...");
file_put_contents("build/index.php", $result); $output_stream = fopen("build/index.php", "w");
echo("complete!\n"); log("complete!\n");
echo("*** Build completed! ***\n"); log("*** Build completed! ***\n");
}
} }
else { else {
exit($result); $output_stream = fopen("php://output", "w");
} }
fwrite($output_stream, $result);
stream_copy_to_stream($archive_stream, $output_stream);
?> ?>