diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/DTS/BookmarkRepository.php | 13 | ||||
| -rw-r--r-- | src/templates/index.php | 9 | 
2 files changed, 20 insertions, 2 deletions
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>  | 
