|
|
@ -5,286 +5,314 @@ use function _\find;
|
|
|
|
|
|
|
|
|
|
|
|
class Book
|
|
|
|
class Book
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findPageById(string $uuid)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$content = $this->getContents();
|
|
|
|
|
|
|
|
$page = find($content, ["uuid" => $uuid]);
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function findPageBySlug(string $slug = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$content = $this->getContents();
|
|
|
|
|
|
|
|
if (isset($slug)) {
|
|
|
|
|
|
|
|
$page = find($content, ["slug" => $slug]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$page = find($content, ["layout" => "index"]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
public function findPageById(string $uuid)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
$content = $this->getContents();
|
|
|
|
public function editPage($task, $request)
|
|
|
|
$page = find($content, ["uuid" => $uuid]);
|
|
|
|
{
|
|
|
|
return $page;
|
|
|
|
$content = $this->getContents();
|
|
|
|
|
|
|
|
if ($task == "delete") {
|
|
|
|
|
|
|
|
//$parsed = json_decode(file_get_contents("php://input"), true);
|
|
|
|
|
|
|
|
//$body = find($content, ["uuid" => $parsed["id"]]);
|
|
|
|
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$page = find($content, ["uuid" => $body["uuid"]]);
|
|
|
|
public function findPageBySlug(string $slug = null)
|
|
|
|
$files = $request->getUploadedFiles();
|
|
|
|
{
|
|
|
|
|
|
|
|
$content = $this->getContents();
|
|
|
|
$member = Session::get("member");
|
|
|
|
if (isset($slug)) {
|
|
|
|
|
|
|
|
$page = find($content, ["slug" => $slug]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$page = find($content, ["layout" => "index"]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($task != "create") {
|
|
|
|
return $page;
|
|
|
|
$path =
|
|
|
|
|
|
|
|
date("Y", date($page["rawCreated"])) .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
date("m", date($page["rawCreated"]));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$path = date("Y") . "/" . date("m");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($files)) {
|
|
|
|
public function editPage($task, $request)
|
|
|
|
//var_dump($files);
|
|
|
|
{
|
|
|
|
if ($task != "create") {
|
|
|
|
$content = $this->getContents();
|
|
|
|
$imageList = "";
|
|
|
|
if ($task == "delete") {
|
|
|
|
//var_dump($files["page_files"] );
|
|
|
|
//$parsed = json_decode(file_get_contents("php://input"), true);
|
|
|
|
foreach ($files["page_files"] as $file) {
|
|
|
|
//$body = find($content, ["uuid" => $parsed["id"]]);
|
|
|
|
$type = $file->getClientMediaType();
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
switch ($type) {
|
|
|
|
} else {
|
|
|
|
case "image/jpeg":
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
case "image/png":
|
|
|
|
|
|
|
|
case "image/gif":
|
|
|
|
|
|
|
|
case "image/svg":
|
|
|
|
|
|
|
|
$imagesPath = "/assets/images/blog/" . $path . "/";
|
|
|
|
|
|
|
|
$imageList =
|
|
|
|
|
|
|
|
$imageList . $imagesPath . urlencode($file->getClientFileName()). ", ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
|
|
|
"../public/assets/images/blog/" . $path . "/",
|
|
|
|
|
|
|
|
$file
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "video/mp4":
|
|
|
|
|
|
|
|
$videosPath = "/assets/video/blog/" . $path . "/";
|
|
|
|
|
|
|
|
$imageList =
|
|
|
|
|
|
|
|
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
|
|
|
"../public/assets/video/blog/" . $path . "/",
|
|
|
|
|
|
|
|
$file
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$feature = $imageList;
|
|
|
|
|
|
|
|
//var_dump($feature);
|
|
|
|
|
|
|
|
//return ["message" => "JUST DEBUGGING"];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$feature =
|
|
|
|
|
|
|
|
"/assets/images/blog/" .
|
|
|
|
|
|
|
|
$path .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$image["feature_image"]->getClientFileName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (isset($body["feature_image"])) {
|
|
|
|
|
|
|
|
$url = explode("/", $body["feature_image"]);
|
|
|
|
|
|
|
|
$feature =
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[3] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[4] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[5] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[6] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[7] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[8];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$task == "create" ? ($feature = "") : ($feature = $body["feature"]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($task == "delete") {
|
|
|
|
$page = find($content, ["uuid" => $body["uuid"]]);
|
|
|
|
$deleted = "true";
|
|
|
|
$files = $request->getUploadedFiles();
|
|
|
|
$body["menu"] = "false";
|
|
|
|
|
|
|
|
$body["published"] = "false";
|
|
|
|
$member = Session::get("member");
|
|
|
|
$body["featured"] = "false";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if ($task != "create") {
|
|
|
|
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false";
|
|
|
|
$path =
|
|
|
|
}
|
|
|
|
date("Y", date($page["rawCreated"])) .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
date("m", date($page["rawCreated"]));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$path = date("Y") . "/" . date("m");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$created =
|
|
|
|
if (isset($files)) {
|
|
|
|
$task != "create"
|
|
|
|
//var_dump($files);
|
|
|
|
|
|
|
|
if ($task != "create") {
|
|
|
|
|
|
|
|
$imageList = "";
|
|
|
|
|
|
|
|
$fileList = "";
|
|
|
|
|
|
|
|
//var_dump($files["page_files"] );
|
|
|
|
|
|
|
|
foreach ($files["page_files"] as $file) {
|
|
|
|
|
|
|
|
$type = $file->getClientMediaType();
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
|
|
|
|
case "image/jpeg":
|
|
|
|
|
|
|
|
case "image/png":
|
|
|
|
|
|
|
|
case "image/gif":
|
|
|
|
|
|
|
|
case "image/svg":
|
|
|
|
|
|
|
|
$imagesPath = "/assets/images/blog/" . $path . "/";
|
|
|
|
|
|
|
|
$imageList =
|
|
|
|
|
|
|
|
$imageList . $imagesPath . urlencode($file->getClientFileName()). ", ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
|
|
|
"../public/assets/images/blog/" . $path . "/",
|
|
|
|
|
|
|
|
$file
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "video/mp4":
|
|
|
|
|
|
|
|
$videosPath = "/assets/video/blog/" . $path . "/";
|
|
|
|
|
|
|
|
$imageList =
|
|
|
|
|
|
|
|
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
|
|
|
"../public/assets/video/blog/" . $path . "/",
|
|
|
|
|
|
|
|
$file
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "audio/mpeg":
|
|
|
|
|
|
|
|
$soundPath = "/assets/sound/blog/" . $path . "/";
|
|
|
|
|
|
|
|
$fileList = $fileList . $soundPath . urlencode($file->getClientFileName()). ", ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
|
|
|
"../public/assets/sound/blog/" . $path . "/",
|
|
|
|
|
|
|
|
$file
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'application/pdf':
|
|
|
|
|
|
|
|
case 'text/plain':
|
|
|
|
|
|
|
|
case 'text/rtf':
|
|
|
|
|
|
|
|
$docPath = "/assets/docs/blog/" . $path . "/";
|
|
|
|
|
|
|
|
$fileList = $fileList . $docPath . urlencode($file->getClientFileName()). ", ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
|
|
|
"../public/assets/docs/blog/" . $path . "/",
|
|
|
|
|
|
|
|
$file
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$feature = $imageList;
|
|
|
|
|
|
|
|
$files = $fileList;
|
|
|
|
|
|
|
|
//var_dump($feature);
|
|
|
|
|
|
|
|
//return ["message" => "JUST DEBUGGING"];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//if creating a new page, from file payload and set $feature and $files
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
$feature =
|
|
|
|
|
|
|
|
"/assets/images/blog/" .
|
|
|
|
|
|
|
|
$path .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$image["feature_image"]->getClientFileName();
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//if no files, do no file stuff
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
if (isset($body["feature_image"])) {
|
|
|
|
|
|
|
|
$url = explode("/", $body["feature_image"]);
|
|
|
|
|
|
|
|
$feature =
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[3] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[4] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[5] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[6] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[7] .
|
|
|
|
|
|
|
|
"/" .
|
|
|
|
|
|
|
|
$url[8];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//$task == "create" ? ($feature = "") : ($feature = $body["feature"]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($task == "delete") {
|
|
|
|
|
|
|
|
$deleted = "true";
|
|
|
|
|
|
|
|
$body["menu"] = "false";
|
|
|
|
|
|
|
|
$body["published"] = "false";
|
|
|
|
|
|
|
|
$body["featured"] = "false";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$created =
|
|
|
|
|
|
|
|
$task != "create"
|
|
|
|
? new \Moment\Moment($page["rawCreated"])
|
|
|
|
? new \Moment\Moment($page["rawCreated"])
|
|
|
|
: new \Moment\Moment();
|
|
|
|
: new \Moment\Moment();
|
|
|
|
$updated = new \Moment\Moment();
|
|
|
|
$updated = new \Moment\Moment();
|
|
|
|
|
|
|
|
|
|
|
|
//grab current index from settings and update
|
|
|
|
|
|
|
|
$id = $task != "create" ? $body["id"] : Settings::getCurrentIndex();
|
|
|
|
|
|
|
|
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
|
|
|
|
|
|
|
// now that variables are done, set to body object and then convert to markdown to save
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$body["id"] = $id;
|
|
|
|
|
|
|
|
$body["uuid"] = $uuid;
|
|
|
|
|
|
|
|
$body["feature"] = $feature;
|
|
|
|
|
|
|
|
$body["path"] = $path;
|
|
|
|
|
|
|
|
$body["author"] = $member["handle"];
|
|
|
|
|
|
|
|
$body["created"] = $created->format("Y-m-d\TH:i:sP");
|
|
|
|
|
|
|
|
$body["updated"] = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
|
|
|
|
$body["deleted"] = $deleted;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$write = DocTools::objectToMD($body);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if layout is index, change path to file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($body["layout"] == "index") {
|
|
|
|
|
|
|
|
$writePath = "../content/pages/start/index.md";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
|
|
|
//grab current index from settings and update
|
|
|
|
|
|
|
|
$id = $task != "create" ? $body["id"] : Settings::getCurrentIndex();
|
|
|
|
if ($status) {
|
|
|
|
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
|
|
|
$config = new Settings();
|
|
|
|
// now that variables are done, set to body object and then convert to markdown to save
|
|
|
|
$settings = $config->getSettings();
|
|
|
|
|
|
|
|
$message = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
$settings["global"]["renderOnSave"] == "true" &&
|
|
|
|
|
|
|
|
$settings["global"]["dynamicRender"] == "false"
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
$render = new Render();
|
|
|
|
|
|
|
|
$render->renderTags();
|
|
|
|
|
|
|
|
$render->renderArchive();
|
|
|
|
|
|
|
|
$render->renderPages();
|
|
|
|
|
|
|
|
$message = "Filed edited and rendered. NOICE.";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$message = "File edited. Nice work";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
|
|
|
|
"message" => $message,
|
|
|
|
|
|
|
|
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
|
|
|
|
|
|
|
"id" => $uuid,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: When form submission is successful, make new form token
|
|
|
|
|
|
|
|
//Session token doesn't reset on the front end, so turning this off for now
|
|
|
|
|
|
|
|
//$form_token = md5(uniqid(microtime(), true));
|
|
|
|
|
|
|
|
//Session::set("form_token", $form_token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//once saved, update menu
|
|
|
|
|
|
|
|
$body["path"] = $path;
|
|
|
|
|
|
|
|
Settings::updateMenu($body);
|
|
|
|
|
|
|
|
Settings::updateTags();
|
|
|
|
|
|
|
|
//if new page added, update current index in Settings file
|
|
|
|
|
|
|
|
if ($task == "create") {
|
|
|
|
|
|
|
|
Settings::updateIndex();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
|
|
|
|
"message" => "Uh oh. File save problem. Don't panic",
|
|
|
|
|
|
|
|
"type" => "postError",
|
|
|
|
|
|
|
|
"id" => $uuid,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
$body["id"] = $id;
|
|
|
|
}
|
|
|
|
$body["uuid"] = $uuid;
|
|
|
|
|
|
|
|
$body["feature"] = $feature;
|
|
|
|
public function getPages(int $page, int $limit, string $sort = null)
|
|
|
|
$body["files"] = $files;
|
|
|
|
{
|
|
|
|
$body["path"] = $path;
|
|
|
|
$content = $this->getContents();
|
|
|
|
$body["author"] = $member["handle"];
|
|
|
|
|
|
|
|
$body["created"] = $created->format("Y-m-d\TH:i:sP");
|
|
|
|
$published = filter($content, function ($item) {
|
|
|
|
$body["updated"] = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
return $item["published"] == true && $item["deleted"] == false;
|
|
|
|
$body["deleted"] = $deleted;
|
|
|
|
});
|
|
|
|
|
|
|
|
$deleted = filter($content, function ($item) {
|
|
|
|
$write = DocTools::objectToMD($body);
|
|
|
|
return $item["deleted"] == true;
|
|
|
|
|
|
|
|
});
|
|
|
|
// if layout is index, change path to file
|
|
|
|
|
|
|
|
|
|
|
|
//$all = $content;
|
|
|
|
if ($body["layout"] == "index") {
|
|
|
|
$all = filter($content, function ($item) {
|
|
|
|
$writePath = "../content/pages/start/index.md";
|
|
|
|
return $item["deleted"] == false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$filter = isset($sort) ? $sort : "all";
|
|
|
|
|
|
|
|
switch ($filter) {
|
|
|
|
|
|
|
|
case "published":
|
|
|
|
|
|
|
|
$filtered = $published;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "deleted":
|
|
|
|
|
|
|
|
$filtered = $deleted;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
$filtered = $all;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$numOfPages = ceil(count($filtered) / ($limit + 1));
|
|
|
|
|
|
|
|
$folder = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count($filtered) != 0) {
|
|
|
|
|
|
|
|
if (count($filtered) < $limit) {
|
|
|
|
|
|
|
|
$limit = count($filtered) - 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$range = $page * $limit - $limit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($range != 0) {
|
|
|
|
|
|
|
|
$range = $range + 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i = 0; $i <= $limit; $i++) {
|
|
|
|
|
|
|
|
if (isset($filtered[$i + $range])) {
|
|
|
|
|
|
|
|
array_push($folder, $filtered[$i + $range]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//chill out
|
|
|
|
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$prev = $page - 1;
|
|
|
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
|
|
|
if ($prev <= 0) {
|
|
|
|
|
|
|
|
$prev = $numOfPages;
|
|
|
|
if ($status) {
|
|
|
|
}
|
|
|
|
$config = new Settings();
|
|
|
|
|
|
|
|
$settings = $config->getSettings();
|
|
|
|
|
|
|
|
$message = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($settings["global"]["renderOnSave"] == "true" &&
|
|
|
|
|
|
|
|
$settings["global"]["dynamicRender"] == "false"
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
$render = new Render();
|
|
|
|
|
|
|
|
$render->renderTags();
|
|
|
|
|
|
|
|
$render->renderArchive();
|
|
|
|
|
|
|
|
$render->renderPages();
|
|
|
|
|
|
|
|
$message = "Filed edited and rendered. NOICE.";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$message = "File edited. Nice work";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
|
|
|
|
"message" => $message,
|
|
|
|
|
|
|
|
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
|
|
|
|
|
|
|
"id" => $uuid,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: When form submission is successful, make new form token
|
|
|
|
|
|
|
|
//Session token doesn't reset on the front end, so turning this off for now
|
|
|
|
|
|
|
|
//$form_token = md5(uniqid(microtime(), true));
|
|
|
|
|
|
|
|
//Session::set("form_token", $form_token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//once saved, update menu
|
|
|
|
|
|
|
|
$body["path"] = $path;
|
|
|
|
|
|
|
|
Settings::updateMenu($body);
|
|
|
|
|
|
|
|
Settings::updateTags();
|
|
|
|
|
|
|
|
//if new page added, update current index in Settings file
|
|
|
|
|
|
|
|
if ($task == "create") {
|
|
|
|
|
|
|
|
Settings::updateIndex();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
|
|
|
|
"message" => "Uh oh. File save problem. Don't panic",
|
|
|
|
|
|
|
|
"type" => "postError",
|
|
|
|
|
|
|
|
"id" => $uuid,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$next = $page + 1;
|
|
|
|
return $response;
|
|
|
|
if ($next > $numOfPages) {
|
|
|
|
|
|
|
|
$next = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
public function getPages(int $page, int $limit, string $sort = null)
|
|
|
|
"pages" => $folder,
|
|
|
|
{
|
|
|
|
"numOfPages" => $numOfPages,
|
|
|
|
$content = $this->getContents();
|
|
|
|
"entryCount" => count($filtered),
|
|
|
|
|
|
|
|
"paginate" => [
|
|
|
|
$published = filter($content, function ($item) {
|
|
|
|
|
|
|
|
return $item["published"] == true && $item["deleted"] == false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$deleted = filter($content, function ($item) {
|
|
|
|
|
|
|
|
return $item["deleted"] == true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//$all = $content;
|
|
|
|
|
|
|
|
$all = filter($content, function ($item) {
|
|
|
|
|
|
|
|
return $item["deleted"] == false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$filter = isset($sort) ? $sort : "all";
|
|
|
|
|
|
|
|
switch ($filter) {
|
|
|
|
|
|
|
|
case "published":
|
|
|
|
|
|
|
|
$filtered = $published;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "deleted":
|
|
|
|
|
|
|
|
$filtered = $deleted;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
$filtered = $all;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$numOfPages = ceil(count($filtered) / ($limit + 1));
|
|
|
|
|
|
|
|
$folder = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count($filtered) != 0) {
|
|
|
|
|
|
|
|
if (count($filtered) < $limit) {
|
|
|
|
|
|
|
|
$limit = count($filtered) - 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$range = $page * $limit - $limit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($range != 0) {
|
|
|
|
|
|
|
|
$range = $range + 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i = 0; $i <= $limit; $i++) {
|
|
|
|
|
|
|
|
if (isset($filtered[$i + $range])) {
|
|
|
|
|
|
|
|
array_push($folder, $filtered[$i + $range]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//chill out
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$prev = $page - 1;
|
|
|
|
|
|
|
|
if ($prev <= 0) {
|
|
|
|
|
|
|
|
$prev = $numOfPages;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$next = $page + 1;
|
|
|
|
|
|
|
|
if ($next > $numOfPages) {
|
|
|
|
|
|
|
|
$next = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
"pages" => $folder,
|
|
|
|
|
|
|
|
"numOfPages" => $numOfPages,
|
|
|
|
|
|
|
|
"entryCount" => count($filtered),
|
|
|
|
|
|
|
|
"paginate" => [
|
|
|
|
"sort" => $sort,
|
|
|
|
"sort" => $sort,
|
|
|
|
"nextPage" => $next,
|
|
|
|
"nextPage" => $next,
|
|
|
|
"prevPage" => $prev,
|
|
|
|
"prevPage" => $prev,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"stats" => [
|
|
|
|
"stats" => [
|
|
|
|
"all" => count($all),
|
|
|
|
"all" => count($all),
|
|
|
|
"published" => count($published),
|
|
|
|
"published" => count($published),
|
|
|
|
"deleted" => count($deleted),
|
|
|
|
"deleted" => count($deleted),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function getContents()
|
|
|
|
public function getContents()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//test new contents data class
|
|
|
|
//test new contents data class
|
|
|
|
//$new = (new Contents("../content/pages"))->getAll();
|
|
|
|
//$new = (new Contents("../content/pages"))->getAll();
|
|
|
|
$contents = (new Contents("../content/pages"))->getAll();
|
|
|
|
$contents = (new Contents("../content/pages"))->getAll();
|
|
|
|
return $contents;
|
|
|
|
return $contents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|