1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Add (untested) support for save preprocessors.

This commit is contained in:
Starbeamrainbowlabs 2015-09-30 08:08:10 +01:00
parent bba4833688
commit 1f1d1cd685
4 changed files with 37 additions and 5 deletions

View file

@ -832,6 +832,15 @@ function add_parser($parser_code)
$parse_page_source = $parser_code; $parse_page_source = $parser_code;
} }
// Function to register a new proprocessor that will be executed just before
// an edit is saved.
$save_preprocessors = [];
function register_save_preprocessor($func)
{
global $save_preprocessors;
$save_processessors[] = $func;
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -1222,7 +1231,7 @@ register_module([
* %save% * %save%
*/ */
add_action("save", function() { add_action("save", function() {
global $pageindex, $settings, $env; global $pageindex, $settings, $env, $save_preprocessors;
if(!$settings->editing) if(!$settings->editing)
{ {
header("location: index.php?page=$env->page"); header("location: index.php?page=$env->page");
@ -1248,8 +1257,15 @@ register_module([
mkdir(dirname("$env->page.md"), null, true); mkdir(dirname("$env->page.md"), null, true);
} }
$pagedata = htmlentities($_POST["content"], ENT_QUOTES);
if(file_put_contents("$env->page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false) // Execute all the preprocessors
foreach($save_preprocessors as $func)
{
$func($pagedata);
}
if(file_put_contents("$env->page.md", $pagedata) !== false)
{ {
$page = $env->page; $page = $env->page;
// Make sure that this page's parents exist // Make sure that this page's parents exist

View file

@ -599,6 +599,15 @@ function add_parser($parser_code)
$parse_page_source = $parser_code; $parse_page_source = $parser_code;
} }
// Function to register a new proprocessor that will be executed just before
// an edit is saved.
$save_preprocessors = [];
function register_save_preprocessor($func)
{
global $save_preprocessors;
$save_processessors[] = $func;
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -59,7 +59,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.", "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit", "id": "page-edit",
"lastupdate": 1443591764, "lastupdate": 1443596864,
"optional": false "optional": false
}, },
{ {

View file

@ -73,7 +73,7 @@ register_module([
* %save% * %save%
*/ */
add_action("save", function() { add_action("save", function() {
global $pageindex, $settings, $env; global $pageindex, $settings, $env, $save_preprocessors;
if(!$settings->editing) if(!$settings->editing)
{ {
header("location: index.php?page=$env->page"); header("location: index.php?page=$env->page");
@ -99,8 +99,15 @@ register_module([
mkdir(dirname("$env->page.md"), null, true); mkdir(dirname("$env->page.md"), null, true);
} }
$pagedata = htmlentities($_POST["content"], ENT_QUOTES);
if(file_put_contents("$env->page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false) // Execute all the preprocessors
foreach($save_preprocessors as $func)
{
$func($pagedata);
}
if(file_put_contents("$env->page.md", $pagedata) !== false)
{ {
$page = $env->page; $page = $env->page;
// Make sure that this page's parents exist // Make sure that this page's parents exist