2021-04-14 21:01:49 +02:00
|
|
|
<?php
|
2021-06-14 21:22:35 +02:00
|
|
|
use function _\filter;
|
2021-04-14 21:01:49 +02:00
|
|
|
|
|
|
|
class PagesAPI
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:04:04 +02:00
|
|
|
public static function getPageContent($request, $args)
|
|
|
|
{
|
|
|
|
$task = $args["fourth"];
|
2021-06-14 21:22:35 +02:00
|
|
|
$content = (new Book("../content/pages"))->getContents();
|
2021-06-02 19:04:04 +02:00
|
|
|
switch ($task) {
|
|
|
|
case "published":
|
2021-06-14 21:22:35 +02:00
|
|
|
//$pageNum = $args["fifth"]; not not needed but gonna keep remnant in case it becomes useful/needed
|
|
|
|
$published = filter($content, function ($item) {
|
|
|
|
return $item["published"] == true && $item["deleted"] == false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$result = ["pages" => $published, "totalPages" => count($published)];
|
|
|
|
//$result = (new Book("../content/pages"))->getPages($pageNum, 4, $task);
|
2021-06-02 19:04:04 +02:00
|
|
|
break;
|
|
|
|
case "single":
|
|
|
|
$uuid = $args["fifth"];
|
|
|
|
$result = (new Book("../content/pages"))->findPageById($uuid);
|
|
|
|
break;
|
2021-06-14 21:22:35 +02:00
|
|
|
case "tags":
|
|
|
|
$result = Settings::getTags();
|
|
|
|
break;
|
2021-06-02 19:04:04 +02:00
|
|
|
default:
|
|
|
|
$result = [
|
|
|
|
"message" => "Hm, no task. That's unfortunate",
|
|
|
|
"type" => "TASK_NONE",
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2021-04-14 21:01:49 +02:00
|
|
|
public static function handlePageTask($request, $args)
|
|
|
|
{
|
|
|
|
$task = $args["fourth"];
|
|
|
|
switch ($task) {
|
|
|
|
case "delete":
|
|
|
|
case "create":
|
|
|
|
case "write":
|
|
|
|
$result = (new Book("../content/pages"))->editPage($task, $request);
|
|
|
|
break;
|
|
|
|
case "add-entry-image":
|
|
|
|
$result = ImagesAPI::uploadImage($request);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$result = [
|
|
|
|
"message" => "Hm, no task. That's unfortunate",
|
|
|
|
"type" => "TASK_NONE",
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|