aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkDB.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r--application/LinkDB.php38
1 files changed, 12 insertions, 26 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 0d3c85bd..8ca0fab3 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -423,43 +423,29 @@ 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);
452 } 435 }
453 436
454 /** 437 /**
455 * Returns the list of all tags 438 * Returns the list tags appearing in the links with the given tags
456 * Output: associative array key=tags, value=0 439 * @param $filteringTags: tags selecting the links to consider
440 * @param $visibility: process only all/private/public links
441 * @return: a tag=>linksCount array
457 */ 442 */
458 public function allTags() 443 public function linksCountPerTag($filteringTags = [], $visibility = 'all')
459 { 444 {
445 $links = empty($filteringTags) ? $this->links : $this->filterSearch(['searchtags' => $filteringTags], false, $visibility);
460 $tags = array(); 446 $tags = array();
461 $caseMapping = array(); 447 $caseMapping = array();
462 foreach ($this->links as $link) { 448 foreach ($links as $link) {
463 foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { 449 foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) {
464 if (empty($tag)) { 450 if (empty($tag)) {
465 continue; 451 continue;