mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
Add comments-fetch action for #138
This commit is contained in:
parent
3b43493bcd
commit
46d520644a
4 changed files with 86 additions and 1 deletions
|
@ -9,6 +9,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
|
|||
- Hyperlinked image preview on file pages to the original image (#153)
|
||||
- [Rest API] Added support for the `mode` parameter to the `random` action
|
||||
- [Rest API] Added `format` parameter to `recentchanges` action
|
||||
- [Rest API] Added `comments-fetch` action to return a page's comments as JSON
|
||||
|
||||
### Fixed
|
||||
- Fixed various issues with both the module api & the rest api docs.
|
||||
|
|
|
@ -2696,6 +2696,48 @@ register_module([
|
|||
|
||||
exit(page_renderer::render_main("Comment Deleted - $settings->sitename", "<p>The comment with the id <code>" . htmlentities($target_id) . "</code> on the page <em>$env->page</em> has been deleted successfully. <a href='?page=" . rawurlencode($env->page) . "&redirect=no'>Go back</a> to " . htmlentities($env->page) . ".</p>"));
|
||||
});
|
||||
/**
|
||||
* @api {post} ?action=comments-fetch&page={page_name} Fetch the comments for a page
|
||||
* @apiName CommentsFetch
|
||||
* @apiGroup Comment
|
||||
* @apiPermission Anonymous
|
||||
* @apiDescription Fetches the comments for the specified page. Returns them in a nested JSON structure.
|
||||
*
|
||||
* @apiUse PageParameter
|
||||
* @apiError PageNoteFound The page to fetch the comments for was not found.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ██████ ██████ ███ ███ ███ ███ ███████ ███ ██ ████████
|
||||
* ██ ██ ██ ████ ████ ████ ████ ██ ████ ██ ██
|
||||
* ██ ██ ██ ██ ████ ██ ██ ████ ██ █████ ██ ██ ██ ██ █████
|
||||
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
* ██████ ██████ ██ ██ ██ ██ ███████ ██ ████ ██
|
||||
*
|
||||
* ███████ ███████ ████████ ██████ ██ ██
|
||||
* ██ ██ ██ ██ ██ ██
|
||||
* █████ █████ ██ ██ ███████
|
||||
* ██ ██ ██ ██ ██ ██
|
||||
* ██ ███████ ██ ██████ ██ ██
|
||||
*/
|
||||
add_action("comments-fetch", function() {
|
||||
global $env;
|
||||
|
||||
$comments_filename = get_comment_filename($env->page);
|
||||
if(!file_exists($comments_filename)) {
|
||||
http_response_code(404);
|
||||
header("content-type: text/plain");
|
||||
exit("Error: No comments file was found for the page '$env->page'.");
|
||||
}
|
||||
|
||||
$comments_data = json_decode(file_get_contents($comments_filename));
|
||||
|
||||
$result = json_encode($comments_data);
|
||||
header("content-type: application/json");
|
||||
header("content-length: " . strlen($result));
|
||||
exit($result);
|
||||
});
|
||||
|
||||
|
||||
if($env->action == "view") {
|
||||
page_renderer::register_part_preprocessor(function(&$parts) {
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
"author": "Starbeamrainbowlabs",
|
||||
"description": "Adds threaded comments to the bottom of every page.",
|
||||
"id": "feature-comments",
|
||||
"lastupdate": 1511450038,
|
||||
"lastupdate": 1523989232,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
|
|
@ -192,6 +192,48 @@ register_module([
|
|||
|
||||
exit(page_renderer::render_main("Comment Deleted - $settings->sitename", "<p>The comment with the id <code>" . htmlentities($target_id) . "</code> on the page <em>$env->page</em> has been deleted successfully. <a href='?page=" . rawurlencode($env->page) . "&redirect=no'>Go back</a> to " . htmlentities($env->page) . ".</p>"));
|
||||
});
|
||||
/**
|
||||
* @api {post} ?action=comments-fetch&page={page_name} Fetch the comments for a page
|
||||
* @apiName CommentsFetch
|
||||
* @apiGroup Comment
|
||||
* @apiPermission Anonymous
|
||||
* @apiDescription Fetches the comments for the specified page. Returns them in a nested JSON structure.
|
||||
*
|
||||
* @apiUse PageParameter
|
||||
* @apiError PageNoteFound The page to fetch the comments for was not found.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ██████ ██████ ███ ███ ███ ███ ███████ ███ ██ ████████
|
||||
* ██ ██ ██ ████ ████ ████ ████ ██ ████ ██ ██
|
||||
* ██ ██ ██ ██ ████ ██ ██ ████ ██ █████ ██ ██ ██ ██ █████
|
||||
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
* ██████ ██████ ██ ██ ██ ██ ███████ ██ ████ ██
|
||||
*
|
||||
* ███████ ███████ ████████ ██████ ██ ██
|
||||
* ██ ██ ██ ██ ██ ██
|
||||
* █████ █████ ██ ██ ███████
|
||||
* ██ ██ ██ ██ ██ ██
|
||||
* ██ ███████ ██ ██████ ██ ██
|
||||
*/
|
||||
add_action("comments-fetch", function() {
|
||||
global $env;
|
||||
|
||||
$comments_filename = get_comment_filename($env->page);
|
||||
if(!file_exists($comments_filename)) {
|
||||
http_response_code(404);
|
||||
header("content-type: text/plain");
|
||||
exit("Error: No comments file was found for the page '$env->page'.");
|
||||
}
|
||||
|
||||
$comments_data = json_decode(file_get_contents($comments_filename));
|
||||
|
||||
$result = json_encode($comments_data);
|
||||
header("content-type: application/json");
|
||||
header("content-length: " . strlen($result));
|
||||
exit($result);
|
||||
});
|
||||
|
||||
|
||||
if($env->action == "view") {
|
||||
page_renderer::register_part_preprocessor(function(&$parts) {
|
||||
|
|
Loading…
Reference in a new issue