aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkFilter.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-04-01 12:17:37 +0200
committerArthurHoaro <arthur@hoa.ro>2017-05-25 15:51:12 +0200
commit7d86f40bdb2135655b5b4fe8cbcc1ac102114f86 (patch)
treec70ac4ad89a4fc84b8e52114aca7d9755cc92086 /application/LinkFilter.php
parentb64d83cd2b60b6851741787f8ce2ae2c93092841 (diff)
downloadShaarli-7d86f40bdb2135655b5b4fe8cbcc1ac102114f86.tar.gz
Shaarli-7d86f40bdb2135655b5b4fe8cbcc1ac102114f86.tar.zst
Shaarli-7d86f40bdb2135655b5b4fe8cbcc1ac102114f86.zip
Empty tag search will look for not tagged links
Fixes #784 From now, searching for tags with an empty value will return only not tagged links, with the search bar showing `x results [not tagged]`. Note that using the api, the searchtags request parameter must be set to `false` to get the same result. - [ ] Update API doc
Diffstat (limited to 'application/LinkFilter.php')
-rw-r--r--application/LinkFilter.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/application/LinkFilter.php b/application/LinkFilter.php
index 81832a4b..0e887d38 100644
--- a/application/LinkFilter.php
+++ b/application/LinkFilter.php
@@ -253,6 +253,9 @@ class LinkFilter
253 { 253 {
254 // Implode if array for clean up. 254 // Implode if array for clean up.
255 $tags = is_array($tags) ? trim(implode(' ', $tags)) : $tags; 255 $tags = is_array($tags) ? trim(implode(' ', $tags)) : $tags;
256 if ($tags === false) {
257 return $this->filterUntagged($visibility);
258 }
256 if (empty($tags)) { 259 if (empty($tags)) {
257 return $this->noFilter($visibility); 260 return $this->noFilter($visibility);
258 } 261 }
@@ -296,6 +299,33 @@ class LinkFilter
296 } 299 }
297 300
298 /** 301 /**
302 * Return only links without any tag.
303 *
304 * @param string $visibility return only all/private/public links.
305 *
306 * @return array filtered links.
307 */
308 public function filterUntagged($visibility)
309 {
310 $filtered = [];
311 foreach ($this->links as $key => $link) {
312 if ($visibility !== 'all') {
313 if (! $link['private'] && $visibility === 'private') {
314 continue;
315 } else if ($link['private'] && $visibility === 'public') {
316 continue;
317 }
318 }
319
320 if (empty(trim($link['tags']))) {
321 $filtered[$key] = $link;
322 }
323 }
324
325 return $filtered;
326 }
327
328 /**
299 * Returns the list of articles for a given day, chronologically sorted 329 * Returns the list of articles for a given day, chronologically sorted
300 * 330 *
301 * Day must be in the form 'YYYYMMDD' (e.g. '20120125'), e.g. 331 * Day must be in the form 'YYYYMMDD' (e.g. '20120125'), e.g.