summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2021-11-08 20:50:15 +0000
committerDavid T. Sadler <davidtsadler@googlemail.com>2021-11-08 20:50:15 +0000
commit4a40b41f386af23da54cd35b8abac1f27c8e5ef7 (patch)
treee618372a6f5446adc9e3770607cbb5fb04377900
parent745664a1bf36cce13f3439698275b0b147efde3b (diff)
Filter by tag
-rw-r--r--public/css/site.css5
-rw-r--r--src/DTS/BookmarkRepository.php13
-rw-r--r--src/templates/index.php9
3 files changed, 25 insertions, 2 deletions
diff --git a/public/css/site.css b/public/css/site.css
index 6204f7b..e689de7 100644
--- a/public/css/site.css
+++ b/public/css/site.css
@@ -58,6 +58,7 @@ a.no-decoration:before {
content: "";
}
+ul,
ol {
list-style-type: none;
padding: 0;
@@ -102,6 +103,10 @@ button {
text-align: center;
}
+.tag {
+ color: #86EFAC;
+}
+
@media (min-width: 1536px) {
section {
width: 80%;
diff --git a/src/DTS/BookmarkRepository.php b/src/DTS/BookmarkRepository.php
index 01f6de4..fde8510 100644
--- a/src/DTS/BookmarkRepository.php
+++ b/src/DTS/BookmarkRepository.php
@@ -12,6 +12,8 @@ class BookmarkRepository implements \Iterator
private array $repository = [];
+ private array $tags = [];
+
private int $position = 0;
function __construct(string $pathToRepository)
@@ -75,6 +77,11 @@ class BookmarkRepository implements \Iterator
return false;
}
+ public function tags(): array
+ {
+ return $this->tags;
+ }
+
public function current(): mixed
{
return $this->repository[$this->position];
@@ -122,8 +129,14 @@ class BookmarkRepository implements \Iterator
$bookmark->addedAt = $data[3];
$this->repository[] = $bookmark;
+
+ $this->tags[] = $bookmark->tag;
}
+ $this->tags = array_filter(array_unique($this->tags));
+
+ sort($this->tags);
+
fclose($fp);
}
diff --git a/src/templates/index.php b/src/templates/index.php
index c046e6c..796bc26 100644
--- a/src/templates/index.php
+++ b/src/templates/index.php
@@ -15,11 +15,16 @@
<?php } ?>
<a href="/create">Add Bookmark</a>
<h2>Tags</h2>
- <a href="/">All</a>
+ <ul>
+ <a href="/">All</a>
+ <?php foreach($bookmarks->tags() as $tag) { ?>
+ <li><a href="/?tag=<?php echo htmlentities($tag); ?>"><?php echo $tag; ?></a></li>
+ <?php } ?>
+ </ul>
<h2>Bookmarks</h2>
<ol>
<?php foreach ($bookmarks as $bookmark) { ?>
- <li><a href="<?php echo htmlentities($bookmark->url); ?>"><?php echo (new DateTime($bookmark->addedAt))->format('Y-m-d'); ?> - <?php echo $bookmark->title != '' ? htmlentities($bookmark->title) : htmlentities($bookmark->url); ?></a> | <a class="no-decoration" href="/edit?id=<?php echo $bookmark->id; ?>">Edit</a> | <a class="no-decoration" href="/delete/confirm?id=<?php echo $bookmark->id; ?>">Delete</a></li>
+ <li><a href="<?php echo htmlentities($bookmark->url); ?>"><?php echo (new DateTime($bookmark->addedAt))->format('Y-m-d'); ?> - <?php echo $bookmark->title != '' ? htmlentities($bookmark->title) : htmlentities($bookmark->url); ?></a> | <?php if ($bookmark->tag) { ?><a class="no-decoration tag" href="/?tag=<?php echo htmlentities($bookmark->tag); ?>"><?php echo htmlentities($bookmark->tag); ?></a> | <?php } ?><a class="no-decoration" href="/edit?id=<?php echo $bookmark->id; ?>">Edit</a> | <a class="no-decoration" href="/delete/confirm?id=<?php echo $bookmark->id; ?>">Delete</a></li>
<?php } ?>
</ol>
<p>Copyright © 2021 David T. Sadler.</p>