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;
}
// 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%
*/
add_action("save", function() {
global $pageindex, $settings, $env;
global $pageindex, $settings, $env, $save_preprocessors;
if(!$settings->editing)
{
header("location: index.php?page=$env->page");
@ -1248,8 +1257,15 @@ register_module([
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;
// Make sure that this page's parents exist

View File

@ -599,6 +599,15 @@ function add_parser($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",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit",
"lastupdate": 1443591764,
"lastupdate": 1443596864,
"optional": false
},
{

View File

@ -73,7 +73,7 @@ register_module([
* %save%
*/
add_action("save", function() {
global $pageindex, $settings, $env;
global $pageindex, $settings, $env, $save_preprocessors;
if(!$settings->editing)
{
header("location: index.php?page=$env->page");
@ -99,8 +99,15 @@ register_module([
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;
// Make sure that this page's parents exist