diff --git a/.gitignore b/.gitignore index a7bce2e..9502db9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ public/* public/assets/* !public/assets/css public/assets/css/* -!public/assets/css/dash.css +!public/assets/css/dash !public/assets/scripts public/assets/scripts/* !public/assets/scripts/Start.js diff --git a/.stylelintrc b/.stylelintrc index 4448120..0a08a15 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -1,6 +1,3 @@ { - "extends": [ - "stylelint-config-standard-scss", - "stylelint-config-prettier-scss" - ] + "extends": ["stylelint-config-standard"] } diff --git a/brain/api/v1/FilesAPI.php b/brain/api/v1/FilesAPI.php new file mode 100644 index 0000000..af13713 --- /dev/null +++ b/brain/api/v1/FilesAPI.php @@ -0,0 +1,53 @@ +getUploadedFiles(); //grab uploaded files + $file = $upload['upload_files'][0]; //front end sends one by one for progress tracking, so grab first + $type = $file->getClientMediaType(); + $filesPath = ''; + $path = date('Y') . '/' . date('m'); + $response = []; + switch ($type) { + case 'image/jpeg': + case 'image/png': + case 'image/gif': + case 'image/svg': + $filesPath = '/assets/images/blog/' . $path . '/'; + + break; + case 'video/mp4': + $filesPath = '/assets/video/blog/' . $path . '/'; + break; + case 'audio/mpeg': + $filesPath = '/assets/sound/blog/' . $path . '/'; + break; + case 'application/pdf': + case 'text/plain': + case 'text/rtf': + $filesPath = '/assets/docs/blog/' . $path . '/'; + break; + } + + FileUploader::uploadFile('../public' . $filesPath, $file); + + $response = [ + 'message' => "File Uploaded. Great!", + "filePath" => $filesPath . urlencode($file->getClientFileName()), + "fileName" => urlencode($file->getClientFileName()), + 'type' => $type, + ]; + + return $response; + } +} diff --git a/brain/api/v1/PagesAPI.php b/brain/api/v1/PagesAPI.php index fdf85dd..753418e 100644 --- a/brain/api/v1/PagesAPI.php +++ b/brain/api/v1/PagesAPI.php @@ -111,7 +111,7 @@ class PagesAPI case 'delete': case 'create': case 'write': - $body = $request->getParsedBody(); + $body = json_decode(file_get_contents("php://input"), true); $passed = true; if (!isset($body['form_token'])) { $result = [ @@ -134,12 +134,15 @@ class PagesAPI 'featured', 'published', 'form_token', - 'feature_image', + 'imageList', + "fileList", + "remote" ]; foreach ($body as $key => $item) { if (!in_array($key, $keys)) { //found unnecessary key, so reject submission + var_dump($key); $passed = false; } } diff --git a/brain/controller/APIControl.php b/brain/controller/APIControl.php index 6f41555..2256f61 100644 --- a/brain/controller/APIControl.php +++ b/brain/controller/APIControl.php @@ -6,6 +6,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use brain\api\v1\AuthAPI; use brain\api\v1\PagesAPI; +use brain\api\v1\FilesAPI; use brain\api\v1\SettingsAPI; use brain\api\v1\InitAPI; use brain\api\v1\MailerAPI; @@ -22,7 +23,7 @@ class APIControl $filename = ''; switch (isset($args['third']) ? $args['third'] : 'none') { case 'status': - $result = AuthAPI::status(); + $result = AuthAPI::status(); break; case 'page': @@ -188,6 +189,24 @@ class APIControl ]; } + break; + case "files": + $token = $request->getHeader('fipamo-access-token'); + if (isset($token[0])) { + if (Session::verifyToken($token[0])) { + $result = FilesAPI::uploadFiles($request, $args); + } else { + $result = [ + 'message' => 'Invalid token, API access denied, homie', + 'type' => 'API_ERROR', + ]; + } + } else { + $result = [ + 'message' => 'No token, API access denied, homie', + 'type' => 'API_ERROR', + ]; + } break; case 'settings': if (isset($body)) { diff --git a/brain/controller/DashControl.php b/brain/controller/DashControl.php index cf8c673..d03f0ca 100644 --- a/brain/controller/DashControl.php +++ b/brain/controller/DashControl.php @@ -7,6 +7,7 @@ use brain\data\Session; use brain\data\Settings; use brain\data\Themes; use brain\utility\Setup; +use brain\utility\Sorting; use Carbon\Carbon; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -151,16 +152,15 @@ class DashControl $config = new Settings(); $settings = $config->getSettings(); $loader = new \Twig\Loader\FilesystemLoader( - '../content/themes' + '../content/themes/' . $settings['global']['theme'] . + '/' ); $display = new \Twig\Environment($loader, []); $book = new Book(); $page = $book->findPageById($uuid); $pageOptions = Sorting::page($page); - $preview = $settings['global']['theme'] . - '/' . - $page['layout'] . + $preview = $page['layout'] . '.twig'; $html = $display->render($preview, $pageOptions); $response->getBody()->write($html); diff --git a/brain/controller/RouteControl.php b/brain/controller/RouteControl.php index 3ceaa26..f3eb19e 100644 --- a/brain/controller/RouteControl.php +++ b/brain/controller/RouteControl.php @@ -33,13 +33,15 @@ class RouteControl ): ResponseInterface { switch (isset($args['first']) ? $args['first'] : 'index') { case 'api': - //$result = APIControl::post($request, $response, $args); return APIControl::post($request, $response, $args); break; default: - //echo "YES"; - //return IndexControl::start($request, $response, $args); - break; + $result = [ + 'message' => "Nothing matches this route. That's unfortunate", + 'type' => 'TASK_NONE', + ]; + $response->getBody()->write(json_encode($result)); + return $response->withHeader('Content-Type', 'application/json'); } } } diff --git a/brain/data/Book.php b/brain/data/Book.php index 71d8a26..efb0575 100644 --- a/brain/data/Book.php +++ b/brain/data/Book.php @@ -5,7 +5,6 @@ namespace brain\data; use Carbon\Carbon; use brain\utility\DocTools; use brain\utility\StringTools; -use brain\utility\FileUploader; use function _\find; use function _\filter; @@ -39,13 +38,8 @@ class Book public function editPage($task, $request) { $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(); - } + $body = json_decode(file_get_contents("php://input"), true); + //$body = find($content, ["uuid" => $parsed["id"]]); $page = find($content, ['uuid' => $body['uuid']]); $files = $request->getUploadedFiles(); @@ -63,65 +57,6 @@ class Book $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(); - //var_dump($type); - 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; - } - } - $page_feature = $imageList; - $page_files = $fileList; - } else { - // if no files, just reset string from page object - $page_feature = $page['feature']; - $page_files = $page['files']; - } - if ($task == 'delete') { $deleted = 'true'; $body['menu'] = 'false'; @@ -139,10 +74,10 @@ class Book $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'] = $page_feature; - $body['files'] = $page_files; + $body['id'] = $id; + $body['uuid'] = $uuid; + //$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/utility/DocTools.php b/brain/utility/DocTools.php index 4c71f45..1dd9dfd 100644 --- a/brain/utility/DocTools.php +++ b/brain/utility/DocTools.php @@ -99,10 +99,10 @@ class DocTools "'" . "\n" . 'feature: ' . - $object['feature'] . + $object['imageList'] . "\n" . 'files: ' . - $object['files'] . + $object['fileList'] . "\n" . 'path: ' . $object['path'] . diff --git a/brain/views/dash/_frame.old.twig b/brain/views/dash/_frame.old.twig deleted file mode 100644 index 4f96798..0000000 --- a/brain/views/dash/_frame.old.twig +++ /dev/null @@ -1,66 +0,0 @@ - - -
- - -