forked from projects/fipamo
cleaned up page creation
This commit is contained in:
parent
1b9252fef0
commit
ed2105edcc
8 changed files with 67 additions and 20 deletions
|
@ -36,6 +36,7 @@ class APIControl
|
|||
}
|
||||
|
||||
//there's only one verion of the api for now
|
||||
//$result = [];
|
||||
switch (isset($args["third"]) ? $args["third"] : "none") {
|
||||
case "login":
|
||||
$result = Auth::login($body);
|
||||
|
@ -50,17 +51,22 @@ class APIControl
|
|||
if (Session::verifyToken($token[0])) {
|
||||
switch ($task) {
|
||||
case "delete":
|
||||
case "add":
|
||||
case "edit":
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
|
|
|
@ -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"])) {
|
||||
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";
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -4,6 +4,25 @@
|
|||
|
||||
class StringTools
|
||||
{
|
||||
public static function createUUID()
|
||||
{
|
||||
if (function_exists("com_create_guid") === true) {
|
||||
return trim(com_create_guid(), "{}");
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
"%04X%04X-%04X-%04X-%04X-%04X%04X%04X",
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(16384, 20479),
|
||||
mt_rand(32768, 49151),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535)
|
||||
);
|
||||
}
|
||||
|
||||
public static function randomString(int $length)
|
||||
{
|
||||
$alphanum =
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
<a class="page-link" href="/dashboard/page/edit/{{ page.uuid }}">
|
||||
<div class="page-bg" style="background: url({{ page.feature }}) no-repeat center center / cover">
|
||||
<div id="meta">
|
||||
<span>
|
||||
{{ page.updated }}
|
||||
</span>
|
||||
<label>
|
||||
{{ page.title }}
|
||||
</label>
|
||||
|
|
|
@ -39,9 +39,7 @@
|
|||
<div id="post-feature">
|
||||
{% if page['feature'] == null %}
|
||||
<div id="featured-image-drop">
|
||||
DRAG AND DROP IMAGE OR
|
||||
<label for="featured-image-upload"></label>
|
||||
CLICK TO CHOSE
|
||||
DRAG AND DROP IMAGE OR <label for="featured-image-upload">CLICK TO CHOSE</label>
|
||||
</div>
|
||||
{% else %}
|
||||
<div id="featured-new-image-btn">
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
</button>
|
||||
{% else %}
|
||||
<button id="edit-save" class="post-sumbit-btn submit-start editor-button" data-action='blog-add' type='submit'>
|
||||
<svg id="submit-save" class="icon-hide" viewbox="0 0 20 20" class="icons">
|
||||
<svg id="submit-save" viewbox="0 0 20 20" class="icons">
|
||||
<use id="submit-save" xlink:href="/assets/images/global/sprite.svg#entypo-plus"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
|
|
@ -162,7 +162,7 @@ export default class PostEditor {
|
|||
notify.alert(r.message, true);
|
||||
} else {
|
||||
notify.alert(r.message, true);
|
||||
window.location = "/@/dashboard/page/edit/" + r.id;
|
||||
window.location = "/dashboard/page/edit/" + r.id;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -280,7 +280,7 @@ export default class APIUtils {
|
|||
request.open(requestType, requestURL, true);
|
||||
request.onload = () => {
|
||||
if (request.status == 200) {
|
||||
//console.log("RESPONSE", request);
|
||||
console.log("RESPONSE", request);
|
||||
let response = JSON.parse(request["response"]);
|
||||
resolve(response);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue