diff options
Diffstat (limited to 'public')
| -rw-r--r-- | public/create/index.php | 37 | ||||
| -rw-r--r-- | public/css/site.css | 121 | ||||
| -rw-r--r-- | public/delete/confirm/index.php | 32 | ||||
| -rw-r--r-- | public/delete/index.php | 37 | ||||
| -rw-r--r-- | public/edit/index.php | 45 | ||||
| -rw-r--r-- | public/fonts/ComicMono-Bold.ttf | bin | 0 -> 20516 bytes | |||
| -rw-r--r-- | public/fonts/ComicMono.ttf | bin | 0 -> 18724 bytes | |||
| -rw-r--r-- | public/images/favicon.png | bin | 0 -> 190 bytes | |||
| -rw-r--r-- | public/index.php | 38 | ||||
| -rw-r--r-- | public/robots.txt | 2 | ||||
| -rw-r--r-- | public/store/index.php | 52 | ||||
| -rw-r--r-- | public/update/index.php | 56 |
12 files changed, 420 insertions, 0 deletions
diff --git a/public/create/index.php b/public/create/index.php new file mode 100644 index 0000000..8256ff5 --- /dev/null +++ b/public/create/index.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +use DTS\Todo; +use DTS\Errors; +use DTS\Old; +use DTS\Session; +use DTS\Template; + +use function DTS\Functions\respondAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +$session = Session::getInstance(); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'GET') { + respondAndExit(405, 'Method Not Allowed'); +} + +$old = $session->get('old', new Old()); + +$errors = $session->get('errors', new Errors()); + +$template = new Template($config['path_to_templates']); + +$todo = new Todo(); + +$html = $template->render('create', compact( + 'todo', + 'errors', + 'old' +)); + +respondAndExit(200, 'OK', $html); diff --git a/public/css/site.css b/public/css/site.css new file mode 100644 index 0000000..c1010a2 --- /dev/null +++ b/public/css/site.css @@ -0,0 +1,121 @@ +/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ +*,::after,::before{box-sizing:border-box}html{-moz-tab-size:4;tab-size:4}html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}body{font-family:system-ui,-apple-system,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji'}hr{height:0;color:inherit}abbr[title]{text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Consolas,'Liberation Mono',Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}::-moz-focus-inner{border-style:none;padding:0}:-moz-focusring{outline:1px dotted ButtonText}:-moz-ui-invalid{box-shadow:none}legend{padding:0}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item} +.hljs{display:block;overflow-x:auto;padding:.5em;background:#f0f0f0}.hljs,.hljs-subst{color:#444}.hljs-comment{color:#888}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#bc6060}.hljs-literal{color:#78a960}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta-string{color:#4d99bf}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700} + +@font-face { + font-family: 'comicsans'; + src: url('/fonts/ComicMono.ttf') format('truetype'), + url("/fonts/ComicMono.ttf") format("truetype"); +} + +body { + background-color: #1a202c; + font-family: "comicsans", monospace; + color: #ffffff; + font-size: 1.125rem; + line-height: 1.75rem; +} + +h1, +h2, +label { + font-weight: bold; + font-size: 1.125rem; +} + +h1 { + color: #BEF264; + text-align: center; + width: 100%; +} + +h2 { + color: #FCD34D; +} + +h2:before { + content: "## "; +} + +section { + padding: 1rem; +} + +a { + color: #93C5FD; + text-decoration: none; +} + +a:hover { + color: #3730A3; +} + +a:before { + content: "=> "; +} + +a.no-decoration:before { + content: ""; +} + +ul, +ol { + list-style-type: none; + padding: 0; +} + +label { + display: block; + color: #86EFAC; + margin-top: 1rem; +} + +input, +button { + border-radius: .25rem; + display: block; + width: 100%; +} + +input { + border: 2px solid #FFFFFF; + padding: .375rem .75rem; +} + +button { + background-color: #86EFAC; + border: 1px solid transparent; + cursor: pointer; + font-weight: 400; + line-height: 1.5; + margin-top: 1rem; + padding: .375rem .75rem; + text-align: center; + vertical-align: middle; +} + +input:focus-visible, +button:focus-visible { + outline: none; + box-shadow: 0 0 0 0.25rem rgb(134 239 172 / 25%); +} + +.message { + background-color: #93C5FD; + border-radius: .25rem; + border: 1px solid transparent; + color: #000000; + padding: .375rem .75rem; + text-align: center; +} + +.tag { + color: #86EFAC; +} + +@media (min-width: 1536px) { + section { + width: 80%; + margin: auto; + } +} diff --git a/public/delete/confirm/index.php b/public/delete/confirm/index.php new file mode 100644 index 0000000..9903f14 --- /dev/null +++ b/public/delete/confirm/index.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +use DTS\TodoRepository; +use DTS\Template; + +use function DTS\Functions\respondAndExit; + +require_once(__DIR__.'/../../../autoload.php'); + +$config = require_once(__DIR__.'/../../../config.php'); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'GET') { + respondAndExit(405, 'Method Not Allowed'); +} + +$id = filter_input(INPUT_GET, 'id'); + +$todos = new TodoRepository($config['path_to_repository']); + +$template = new Template($config['path_to_templates']); + +$todo = $todos->find($id); + +if ($todo === null) { + respondAndExit(404, 'Not Found'); +} + +$html = $template->render('confirm_deletion', compact('todo')); + +respondAndExit(200, 'OK', $html); diff --git a/public/delete/index.php b/public/delete/index.php new file mode 100644 index 0000000..a19f568 --- /dev/null +++ b/public/delete/index.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +use DTS\TodoRepository; +use DTS\Session; + +use function DTS\Functions\respondAndExit; +use function DTS\Functions\redirectAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +$session = Session::getInstance(); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') { + respondAndExit(405, 'Method Not Allowed'); +} + +$id = filter_input(INPUT_POST, 'id'); + +$todos = new TodoRepository($config['path_to_repository']); + +$todo = $todos->find($id); + +if ($todo === null) { + respondAndExit(404, 'Not Found'); +} + +if (!$todos->delete($todo)) { + respondAndExit(500, 'Internal Server Error'); +} + +$session->set('message', 'Todo Deleted'); + +redirectAndExit('/'); diff --git a/public/edit/index.php b/public/edit/index.php new file mode 100644 index 0000000..81aa121 --- /dev/null +++ b/public/edit/index.php @@ -0,0 +1,45 @@ +<?php + +declare(strict_types=1); + +use DTS\TodoRepository; +use DTS\Errors; +use DTS\Old; +use DTS\Session; +use DTS\Template; + +use function DTS\Functions\respondAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +$session = Session::getInstance(); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'GET') { + respondAndExit(405, 'Method Not Allowed'); +} + +$old = $session->get('old', new Old()); + +$errors = $session->get('errors', new Errors()); + +$id = filter_input(INPUT_GET, 'id'); + +$todos = new TodoRepository($config['path_to_repository']); + +$template = new Template($config['path_to_templates']); + +$todo = $todos->find($id); + +if ($todo === null) { + respondAndExit(404, 'Not Found'); +} + +$html = $template->render('edit', compact( + 'todo', + 'errors', + 'old' +)); + +respondAndExit(200, 'OK', $html); diff --git a/public/fonts/ComicMono-Bold.ttf b/public/fonts/ComicMono-Bold.ttf Binary files differnew file mode 100644 index 0000000..e03f41e --- /dev/null +++ b/public/fonts/ComicMono-Bold.ttf diff --git a/public/fonts/ComicMono.ttf b/public/fonts/ComicMono.ttf Binary files differnew file mode 100644 index 0000000..9bc7354 --- /dev/null +++ b/public/fonts/ComicMono.ttf diff --git a/public/images/favicon.png b/public/images/favicon.png Binary files differnew file mode 100644 index 0000000..4909792 --- /dev/null +++ b/public/images/favicon.png diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..4e18b9a --- /dev/null +++ b/public/index.php @@ -0,0 +1,38 @@ +<?php + +declare(strict_types=1); + +use DTS\TodoRepository; +use DTS\Session; +use DTS\Template; + +use function DTS\Functions\respondAndExit; + +require_once(__DIR__.'/../autoload.php'); + +$config = require_once(__DIR__.'/../config.php'); + +$session = Session::getInstance(); + +$todos = new TodoRepository($config['path_to_repository']); + +$template = new Template($config['path_to_templates']); + +$sort = $_GET['sort'] ?? 'asc'; + +$tag = $_GET['tag'] ?? null; + +if ($tag !== null) { + $todos->filter($tag); +} + +$todos->sort($sort === 'asc'); + +$message = $session->get('message'); + +$html = $template->render('index', compact( + 'todos', + 'message' +)); + +respondAndExit(200, 'OK', $html); diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/public/store/index.php b/public/store/index.php new file mode 100644 index 0000000..c4d24fa --- /dev/null +++ b/public/store/index.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +use DTS\Todo; +use DTS\TodoRepository; +use DTS\Old; +use DTS\Session; +use DTS\Validator; + +use function DTS\Functions\redirectAndExit; +use function DTS\Functions\respondAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +$session = Session::getInstance(); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') { + respondAndExit(405, 'Method Not Allowed'); +} + +$old = new Old($_REQUEST); + +$session->set('old', $old); + +$validator = new Validator($_REQUEST); + +if ($validator->errors->count()) { + $session->set('errors', $validator->errors); + + redirectAndExit('/create'); +} + +$validated = $validator->validated; + +$todos = new TodoRepository($config['path_to_repository']); + +$todo = new Todo(); + +$todo->task = $validated->task; +$todo->tag = $validated->tag; +$todo->addedAt = date('Y-m-d H:i:s'); + +if (!$todos->add($todo)) { + respondAndExit(500, 'Internal Server Error'); +} + +$session->set('message', 'Todo Added'); + +redirectAndExit('/'); diff --git a/public/update/index.php b/public/update/index.php new file mode 100644 index 0000000..82b3c3f --- /dev/null +++ b/public/update/index.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +use DTS\TodoRepository; +use DTS\Old; +use DTS\Session; +use DTS\Validator; + +use function DTS\Functions\respondAndExit; +use function DTS\Functions\redirectAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +$session = Session::getInstance(); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') { + respondAndExit(405, 'Method Not Allowed'); +} + +$id = filter_input(INPUT_POST, 'id'); + +$todos = new TodoRepository($config['path_to_repository']); + +$todo = $todos->find($id); + +if ($todo === null) { + respondAndExit(404, 'Not Found'); +} + +$old = new Old($_REQUEST); + +$session->set('old', $old); + +$validator = new Validator($_REQUEST); + +if ($validator->errors->count()) { + $session->set('errors', $validator->errors); + + redirectAndExit("/edit?id=$todo->id"); +} + +$validated = $validator->validated; + +$todo->task = $validated->task; +$todo->tag = $validated->tag; + +if (!$todos->update($todo)) { + respondAndExit(500, 'Internal Server Error'); +} + +$session->set('message', 'Todo Updated'); + +redirectAndExit('/'); |
