From 1351b98ee49c62d885ed89a645d3648edc028d09 Mon Sep 17 00:00:00 2001 From: Ro Date: Tue, 15 Mar 2022 16:56:37 -0700 Subject: [PATCH] cleaned up create page process, update page edit template to handle empty files --- brain/controller/DashControl.inc.php | 8 +- brain/data/Book.inc.php | 139 +++++++++++---------------- brain/views/dash/forms/login.twig | 2 +- brain/views/dash/page-edit.twig | 27 +++++- public/assets/scripts/Start.js | 15 ++- src/com/ui/FileManager.js | 4 - 6 files changed, 88 insertions(+), 107 deletions(-) diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index 211dad3..b011507 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -116,15 +116,15 @@ class DashControl $files = []; foreach ($imageList as $item) { $image = trim($item); - if ($item != null || $item != "") { - array_push($images, $item); + if (!empty($image)) { + array_push($images, $image); } } foreach ($fileList as $item) { $file = trim($item); - if ($item != null || $item != "") { - array_push($files, $item); + if (!empty($file)) { + array_push($files, $file); } } diff --git a/brain/data/Book.inc.php b/brain/data/Book.inc.php index 6d77de4..b3a68ff 100644 --- a/brain/data/Book.inc.php +++ b/brain/data/Book.inc.php @@ -53,96 +53,67 @@ class Book $path = date("Y") . "/" . date("m"); } - if (isset($files)) { - //var_dump($files); - if ($task != "create") { - $imageList = ""; - $fileList = ""; + $page_feature = ''; + $page_files = ''; + + if (isset($files["page_files"])) { + $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()). ", "; + 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/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/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/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; - } + 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(); - */ } + $page_feature = $imageList; + $page_files = $fileList; } 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 no files, just reset string from page object + $page_feature = $page["feature"]; + $page_files = $page["files"]; } if ($task == "delete") { @@ -167,8 +138,8 @@ class Book $body["id"] = $id; $body["uuid"] = $uuid; - $body["feature"] = $feature; - $body["files"] = $files; + $body["feature"] = $page_feature; + $body["files"] = $page_files; $body["path"] = $path; $body["author"] = $member["handle"]; $body["created"] = $created->format("Y-m-d\TH:i:sP"); diff --git a/brain/views/dash/forms/login.twig b/brain/views/dash/forms/login.twig index 3ddbb06..2a8792d 100644 --- a/brain/views/dash/forms/login.twig +++ b/brain/views/dash/forms/login.twig @@ -1,7 +1,7 @@
-