|
|
|
@ -47,17 +47,26 @@ class Book
|
|
|
|
|
$image = $request->getUploadedFiles();
|
|
|
|
|
$member = Session::get("member");
|
|
|
|
|
|
|
|
|
|
if ($task != "add") {
|
|
|
|
|
if ($task != "create") {
|
|
|
|
|
$path =
|
|
|
|
|
date("Y", date($page["rawCreated"])) .
|
|
|
|
|
"/" .
|
|
|
|
|
date("m", date($page["rawCreated"]));
|
|
|
|
|
} else {
|
|
|
|
|
$path = date("Y", date()) . "/" . date("m");
|
|
|
|
|
$path = date("Y") . "/" . date("m");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($image["feature_image"])) {
|
|
|
|
|
$feature = $image["feature_image"]->getClientFileName();
|
|
|
|
|
if ($task != "create") {
|
|
|
|
|
$feature = $image["feature_image"]->getClientFileName();
|
|
|
|
|
} else {
|
|
|
|
|
$feature =
|
|
|
|
|
"/assets/images/blog/" .
|
|
|
|
|
$path .
|
|
|
|
|
"/" .
|
|
|
|
|
$image["feature_image"]->getClientFileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
|
"../public/assets/images/blog/" . $path . "/",
|
|
|
|
|
$image["feature_image"]
|
|
|
|
@ -93,22 +102,25 @@ class Book
|
|
|
|
|
? ($body["featured"] = "true")
|
|
|
|
|
: ($body["featured"] = "false");
|
|
|
|
|
} else {
|
|
|
|
|
$deleted = !$page["deleted"] ? "false" : $page["deleted"];
|
|
|
|
|
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$created =
|
|
|
|
|
$task != "add"
|
|
|
|
|
$task != "create"
|
|
|
|
|
? new \Moment\Moment($page["rawCreated"])
|
|
|
|
|
: new \Moment\Moment();
|
|
|
|
|
$updated = new \Moment\Moment();
|
|
|
|
|
|
|
|
|
|
//grab current index from settings and update
|
|
|
|
|
$id = $task != "create" ? $body["id"] : 6;
|
|
|
|
|
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
|
|
|
|
$write =
|
|
|
|
|
"---\n" .
|
|
|
|
|
"id: " .
|
|
|
|
|
$body["id"] .
|
|
|
|
|
$id .
|
|
|
|
|
"\n" .
|
|
|
|
|
"uuid: " .
|
|
|
|
|
$body["uuid"] .
|
|
|
|
|
$uuid .
|
|
|
|
|
"\n" .
|
|
|
|
|
"title: " .
|
|
|
|
|
$body["title"] .
|
|
|
|
@ -154,18 +166,27 @@ class Book
|
|
|
|
|
// if layout is index, change path to file
|
|
|
|
|
|
|
|
|
|
if ($body["layout"] == "index") {
|
|
|
|
|
$writePath = "../content/start/index.md";
|
|
|
|
|
$writePath = "../content/pages/start/index.md";
|
|
|
|
|
} else {
|
|
|
|
|
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
($new = fopen($writePath, "w")) or die("Unable to open file!");
|
|
|
|
|
fwrite($new, $write);
|
|
|
|
|
fclose($new);
|
|
|
|
|
if ($task == "create") {
|
|
|
|
|
if (!is_dir("../content/pages/" . $path)) {
|
|
|
|
|
//Directory does not exist, so lets create it.
|
|
|
|
|
mkdir("../content/pages/" . $path, 0755, true);
|
|
|
|
|
}
|
|
|
|
|
file_put_contents($writePath, $write);
|
|
|
|
|
} else {
|
|
|
|
|
($new = fopen($writePath, "w")) or die("Unable to open file!");
|
|
|
|
|
fwrite($new, $write);
|
|
|
|
|
fclose($new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
|
"message" => "File edited. Nice work",
|
|
|
|
|
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
|
|
|
|
"id" => $uuid,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|