diff --git a/brain/controller/APIControl.inc.php b/brain/controller/APIControl.inc.php index 3486492..0cea17b 100644 --- a/brain/controller/APIControl.inc.php +++ b/brain/controller/APIControl.inc.php @@ -36,8 +36,6 @@ class APIControl break; } - //there's only one verion of the api for now - $result = []; switch (isset($args["third"]) ? $args["third"] : "none") { case "login": $result = Auth::login($body); diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index 7e1cd61..67f7330 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -55,15 +55,15 @@ class DashControl "status" => Session::active(), ]; } else { - header("Location: /dashboard"); - die(); + $pageOptions = [ + "title" => "Fipamo | Create Page", + "mode" => $mode, + "status" => Session::active(), + ]; } } else { - $template = "dash/start.twig"; - $pageOptions = [ - "title" => "Welcome to Fipamo", - "status" => Session::active(), - ]; + header("Location: /dashboard"); + die(); } break; diff --git a/brain/data/Book.inc.php b/brain/data/Book.inc.php index c68ed44..cca3470 100644 --- a/brain/data/Book.inc.php +++ b/brain/data/Book.inc.php @@ -171,23 +171,21 @@ class Book $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); - } + $status = DocTools::write($task, $path, $writePath, $write); - $response = [ - "message" => "File edited. Nice work", - "type" => $task == "write" ? "postUpdated" : "postAdded", - "id" => $uuid, - ]; + if ($status) { + $response = [ + "message" => "File edited. Nice work", + "type" => $task == "write" ? "postUpdated" : "postAdded", + "id" => $uuid, + ]; + } else { + $response = [ + "message" => "Uh oh. File save problem. Don't panic", + "type" => "postError", + "id" => $uuid, + ]; + } return $response; } diff --git a/brain/utility/DocTools.inc.php b/brain/utility/DocTools.inc.php new file mode 100644 index 0000000..e6fbd47 --- /dev/null +++ b/brain/utility/DocTools.inc.php @@ -0,0 +1,29 @@ +