]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/LinkFilter.php
Empty tag search will look for not tagged links
[github/shaarli/Shaarli.git] / application / LinkFilter.php
index 81832a4b428f4bc650d3049b8e0ced2a850c1cdc..0e887d3805a2fa7ef2024f5da2d6b155dc4a870e 100644 (file)
@@ -253,6 +253,9 @@ class LinkFilter
     {
         // Implode if array for clean up.
         $tags = is_array($tags) ? trim(implode(' ', $tags)) : $tags;
+        if ($tags === false) {
+            return $this->filterUntagged($visibility);
+        }
         if (empty($tags)) {
             return $this->noFilter($visibility);
         }
@@ -295,6 +298,33 @@ class LinkFilter
         return $filtered;
     }
 
+    /**
+     * Return only links without any tag.
+     *
+     * @param string $visibility return only all/private/public links.
+     *
+     * @return array filtered links.
+     */
+    public function filterUntagged($visibility)
+    {
+        $filtered = [];
+        foreach ($this->links as $key => $link) {
+            if ($visibility !== 'all') {
+                if (! $link['private'] && $visibility === 'private') {
+                    continue;
+                } else if ($link['private'] && $visibility === 'public') {
+                    continue;
+                }
+            }
+
+            if (empty(trim($link['tags']))) {
+                $filtered[$key] = $link;
+            }
+        }
+
+        return $filtered;
+    }
+
     /**
      * Returns the list of articles for a given day, chronologically sorted
      *