From cbaedbc5251f3b127bd81242d1344c0cd3e56e0c Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Wed, 13 Oct 2021 21:51:07 +0100 Subject: Implemente redirects --- src/DTS/Bookmark.php | 10 ---------- src/DTS/BookmarkRepository.php | 18 ++++++++++-------- src/DTS/Functions.php | 5 +++++ src/templates/add.php | 16 ---------------- src/templates/confirm_deletion.php | 16 ++++++++++++++++ src/templates/create.php | 17 +++++++++++++++++ src/templates/delete.php | 15 --------------- src/templates/edit.php | 5 +++-- src/templates/index.php | 11 ++++++----- 9 files changed, 57 insertions(+), 56 deletions(-) delete mode 100644 src/templates/add.php create mode 100644 src/templates/confirm_deletion.php create mode 100644 src/templates/create.php delete mode 100644 src/templates/delete.php (limited to 'src') diff --git a/src/DTS/Bookmark.php b/src/DTS/Bookmark.php index 560fad4..543a552 100644 --- a/src/DTS/Bookmark.php +++ b/src/DTS/Bookmark.php @@ -17,14 +17,4 @@ class Bookmark public string $addedAt; public bool $unread; - - function __construct(string $id, string $url, string $title, string $tag, string $addedAt, bool $unread) - { - $this->id = $id; - $this->url = $url; - $this->title = $title; - $this->tag = $tag; - $this->addedAt = $addedAt; - $this->unread = $unread; - } } diff --git a/src/DTS/BookmarkRepository.php b/src/DTS/BookmarkRepository.php index 5d22100..a3fd5dd 100644 --- a/src/DTS/BookmarkRepository.php +++ b/src/DTS/BookmarkRepository.php @@ -128,14 +128,16 @@ class BookmarkRepository implements \Iterator } while (($data = fgetcsv($fp)) !== FALSE) { - $this->repository[] = new Bookmark( - $data[0], // Id. - $data[1], // Url. - $data[2], // Title. - $data[3], // Tag. - $data[4], // Added At. - (bool)$data[4], // Read. - ); + $bookmark = new Bookmark(); + + $bookmark->id = $data[0]; + $bookmark->url = $data[1]; + $bookmark->title = $data[2]; + $bookmark->tag = $data[3]; + $bookmark->addedAt = $data[4]; + $bookmark->unread = (bool)$data[5]; + + $this->repository[] = $bookmark; } fclose($fp); diff --git a/src/DTS/Functions.php b/src/DTS/Functions.php index d7ca835..2101cda 100644 --- a/src/DTS/Functions.php +++ b/src/DTS/Functions.php @@ -16,3 +16,8 @@ function respondAndExit(int $responseCode, string $header, string $body = '', ar exit(); } + +function redirectAndExit(string $location): void +{ + respondAndExit(302, 'Found', '', ["Location: $location"]); +} diff --git a/src/templates/add.php b/src/templates/add.php deleted file mode 100644 index a44c4d3..0000000 --- a/src/templates/add.php +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - Bookmarks - - -
-
-
-
- -
- - diff --git a/src/templates/confirm_deletion.php b/src/templates/confirm_deletion.php new file mode 100644 index 0000000..77998ff --- /dev/null +++ b/src/templates/confirm_deletion.php @@ -0,0 +1,16 @@ + + + + + + Bookmarks + + + Back +
+ + url.' '.$bookmark->title.' '.$bookmark->tag; ?> + +
+ + diff --git a/src/templates/create.php b/src/templates/create.php new file mode 100644 index 0000000..483e49e --- /dev/null +++ b/src/templates/create.php @@ -0,0 +1,17 @@ + + + + + + Bookmarks + + + Back +
+
+
+
+ +
+ + diff --git a/src/templates/delete.php b/src/templates/delete.php deleted file mode 100644 index 1be762b..0000000 --- a/src/templates/delete.php +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - Bookmarks - - -
- - url.' '.$bookmark->title.' '.$bookmark->tag; ?> - -
- - diff --git a/src/templates/edit.php b/src/templates/edit.php index a3c6930..d5f5a08 100644 --- a/src/templates/edit.php +++ b/src/templates/edit.php @@ -6,12 +6,13 @@ Bookmarks -
+ Back +


- +
diff --git a/src/templates/index.php b/src/templates/index.php index 1298985..ed84fd4 100644 --- a/src/templates/index.php +++ b/src/templates/index.php @@ -6,10 +6,11 @@ Bookmarks - + Add + -- cgit v1.2.3-13-gbd6f