mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Update for page-edit module: allow saving of subpages
This commit is contained in:
parent
b955c1efc0
commit
f8cddda19e
4 changed files with 48 additions and 32 deletions
38
index.php
38
index.php
|
@ -264,7 +264,7 @@ if(!file_exists("./pageindex.json"))
|
|||
|
||||
// Extract the subpage's key
|
||||
$subpage_relative_key = substr($item, $stem_length, -3);
|
||||
// Calculate how many times removed the current subpage is from the current page. 1 = direct descendant.
|
||||
// Calculate how many times removed the current subpage is from the current page. 0 = direct descendant.
|
||||
$times_removed = substr_count($subpage_relative_key, "/");
|
||||
$subpage_full_key = substr($item, 0, -3);
|
||||
// Store the name of the subpage we found in the subpage object of the current page
|
||||
|
@ -700,7 +700,7 @@ register_module([
|
|||
|
||||
register_module([
|
||||
"name" => "Page editor",
|
||||
"version" => "0.6",
|
||||
"version" => "0.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",
|
||||
|
@ -708,12 +708,12 @@ register_module([
|
|||
"code" => function() {
|
||||
|
||||
/*
|
||||
*
|
||||
* ___ __ ___ _____
|
||||
* / __|/ _` \ \ / / _ \
|
||||
* \__ \ (_| |\ V / __/
|
||||
* |___/\__,_| \_/ \___|
|
||||
* %save%
|
||||
* _ _ _
|
||||
* ___ __| (_) |_
|
||||
* / _ \/ _` | | __|
|
||||
* | __/ (_| | | |_
|
||||
* \___|\__,_|_|\__|
|
||||
* %edit%
|
||||
*/
|
||||
add_action("edit", function() {
|
||||
global $pageindex, $settings, $page, $isloggedin;
|
||||
|
@ -761,14 +761,13 @@ register_module([
|
|||
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* _ _ _
|
||||
* ___ __| (_) |_
|
||||
* / _ \/ _` | | __|
|
||||
* | __/ (_| | | |_
|
||||
* \___|\__,_|_|\__|
|
||||
* %edit%
|
||||
*
|
||||
* ___ __ ___ _____
|
||||
* / __|/ _` \ \ / / _ \
|
||||
* \__ \ (_| |\ V / __/
|
||||
* |___/\__,_| \_/ \___|
|
||||
* %save%
|
||||
*/
|
||||
add_action("save", function() {
|
||||
global $pageindex, $settings, $page, $isloggedin, $user;
|
||||
|
@ -789,6 +788,14 @@ register_module([
|
|||
header("refresh: 5; url=index.php?page=$page");
|
||||
exit("Bad request: No content specified.");
|
||||
}
|
||||
|
||||
// Make sure that the directory in which the page needs to be saved exists
|
||||
if(!is_dir(dirname("$page.md")))
|
||||
{
|
||||
// Recursively create the directory if needed
|
||||
mkdir(dirname("$page.md"), null, true);
|
||||
}
|
||||
|
||||
if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false)
|
||||
{
|
||||
//update the page index
|
||||
|
@ -907,6 +914,7 @@ register_module([
|
|||
<th>Last Editor</th>
|
||||
<th>Last Edit Time</th>
|
||||
</tr>\n";
|
||||
// todo list the pages in alphabetical order
|
||||
foreach($pageindex as $pagename => $pagedetails)
|
||||
{
|
||||
$content .= "\t\t<tr>
|
||||
|
|
|
@ -25,11 +25,11 @@
|
|||
},
|
||||
{
|
||||
"name": "Page editor",
|
||||
"version": "0.6",
|
||||
"version": "0.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": 1432497592
|
||||
"lastupdate": 1436797312
|
||||
},
|
||||
{
|
||||
"name": "Help page",
|
||||
|
@ -45,7 +45,7 @@
|
|||
"author": "Starbeamrainbowlabs",
|
||||
"description": "Adds a page that lists all the pages in the index along with their metadata.",
|
||||
"id": "page-list",
|
||||
"lastupdate": 1432497592
|
||||
"lastupdate": 1436796812
|
||||
},
|
||||
{
|
||||
"name": "Login",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "Page editor",
|
||||
"version" => "0.6",
|
||||
"version" => "0.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",
|
||||
|
@ -9,12 +9,12 @@ register_module([
|
|||
"code" => function() {
|
||||
|
||||
/*
|
||||
*
|
||||
* ___ __ ___ _____
|
||||
* / __|/ _` \ \ / / _ \
|
||||
* \__ \ (_| |\ V / __/
|
||||
* |___/\__,_| \_/ \___|
|
||||
* %save%
|
||||
* _ _ _
|
||||
* ___ __| (_) |_
|
||||
* / _ \/ _` | | __|
|
||||
* | __/ (_| | | |_
|
||||
* \___|\__,_|_|\__|
|
||||
* %edit%
|
||||
*/
|
||||
add_action("edit", function() {
|
||||
global $pageindex, $settings, $page, $isloggedin;
|
||||
|
@ -62,14 +62,13 @@ register_module([
|
|||
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* _ _ _
|
||||
* ___ __| (_) |_
|
||||
* / _ \/ _` | | __|
|
||||
* | __/ (_| | | |_
|
||||
* \___|\__,_|_|\__|
|
||||
* %edit%
|
||||
*
|
||||
* ___ __ ___ _____
|
||||
* / __|/ _` \ \ / / _ \
|
||||
* \__ \ (_| |\ V / __/
|
||||
* |___/\__,_| \_/ \___|
|
||||
* %save%
|
||||
*/
|
||||
add_action("save", function() {
|
||||
global $pageindex, $settings, $page, $isloggedin, $user;
|
||||
|
@ -90,6 +89,14 @@ register_module([
|
|||
header("refresh: 5; url=index.php?page=$page");
|
||||
exit("Bad request: No content specified.");
|
||||
}
|
||||
|
||||
// Make sure that the directory in which the page needs to be saved exists
|
||||
if(!is_dir(dirname("$page.md")))
|
||||
{
|
||||
// Recursively create the directory if needed
|
||||
mkdir(dirname("$page.md"), null, true);
|
||||
}
|
||||
|
||||
if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false)
|
||||
{
|
||||
//update the page index
|
||||
|
|
|
@ -17,6 +17,7 @@ register_module([
|
|||
<th>Last Editor</th>
|
||||
<th>Last Edit Time</th>
|
||||
</tr>\n";
|
||||
// todo list the pages in alphabetical order
|
||||
foreach($pageindex as $pagename => $pagedetails)
|
||||
{
|
||||
$content .= "\t\t<tr>
|
||||
|
|
Loading…
Reference in a new issue