aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-25 15:54:20 +0200
committerGitHub <noreply@github.com>2017-05-25 15:54:20 +0200
commit3e395a6bc63cba16b0772a382f6cbac0ce4ab906 (patch)
tree220eaf3400aeeea821b7e150855a1d44f1b5bfe9 /application
parentb2e2aa42e288e0becaa95bf9cc3be679743fc98e (diff)
parent7d86f40bdb2135655b5b4fe8cbcc1ac102114f86 (diff)
downloadShaarli-3e395a6bc63cba16b0772a382f6cbac0ce4ab906.tar.gz
Shaarli-3e395a6bc63cba16b0772a382f6cbac0ce4ab906.tar.zst
Shaarli-3e395a6bc63cba16b0772a382f6cbac0ce4ab906.zip
Merge pull request #841 from ArthurHoaro/feature/search-no-tag
Empty tag search will look for not tagged links
Diffstat (limited to 'application')
-rw-r--r--application/FeedBuilder.php5
-rw-r--r--application/LinkDB.php27
-rw-r--r--application/LinkFilter.php30
-rw-r--r--application/Utils.php4
4 files changed, 44 insertions, 22 deletions
diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php
index a1f4da48..7377bcec 100644
--- a/application/FeedBuilder.php
+++ b/application/FeedBuilder.php
@@ -97,6 +97,11 @@ class FeedBuilder
97 */ 97 */
98 public function buildData() 98 public function buildData()
99 { 99 {
100 // Search for untagged links
101 if (isset($this->userInput['searchtags']) && empty($this->userInput['searchtags'])) {
102 $this->userInput['searchtags'] = false;
103 }
104
100 // Optionally filter the results: 105 // Optionally filter the results:
101 $linksToDisplay = $this->linkDB->filterSearch($this->userInput); 106 $linksToDisplay = $this->linkDB->filterSearch($this->userInput);
102 107
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 7802cc8a..8ca0fab3 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -423,29 +423,12 @@ You use the community supported version of the original Shaarli project, by Seba
423 public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all') 423 public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all')
424 { 424 {
425 // Filter link database according to parameters. 425 // Filter link database according to parameters.
426 $searchtags = !empty($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; 426 $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : '';
427 $searchterm = !empty($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; 427 $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : '';
428 428
429 // Search tags + fullsearch. 429 // Search tags + fullsearch - blank string parameter will return all links.
430 if (! empty($searchtags) && ! empty($searchterm)) { 430 $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT;
431 $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; 431 $request = [$searchtags, $searchterm];
432 $request = array($searchtags, $searchterm);
433 }
434 // Search by tags.
435 elseif (! empty($searchtags)) {
436 $type = LinkFilter::$FILTER_TAG;
437 $request = $searchtags;
438 }
439 // Fulltext search.
440 elseif (! empty($searchterm)) {
441 $type = LinkFilter::$FILTER_TEXT;
442 $request = $searchterm;
443 }
444 // Otherwise, display without filtering.
445 else {
446 $type = '';
447 $request = '';
448 }
449 432
450 $linkFilter = new LinkFilter($this); 433 $linkFilter = new LinkFilter($this);
451 return $linkFilter->filter($type, $request, $casesensitive, $visibility); 434 return $linkFilter->filter($type, $request, $casesensitive, $visibility);
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.
diff --git a/application/Utils.php b/application/Utils.php
index 9d0ebc5e..4a2f5561 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -91,6 +91,10 @@ function endsWith($haystack, $needle, $case = true)
91 */ 91 */
92function escape($input) 92function escape($input)
93{ 93{
94 if (is_bool($input)) {
95 return $input;
96 }
97
94 if (is_array($input)) { 98 if (is_array($input)) {
95 $out = array(); 99 $out = array();
96 foreach($input as $key => $value) { 100 foreach($input as $key => $value) {