X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FLinkDB.php;h=8ca0fab30d55cbee54501579375e7d0697f48e62;hb=57ee53d6c6be4b641764b0a635b2998c6cdc8197;hp=0d3c85bd9815e2c879d8b18160441dfd19fd80f5;hpb=77de24876ff542e3770aa2845e993c58f87e37df;p=github%2Fshaarli%2FShaarli.git 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 public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all') { // Filter link database according to parameters. - $searchtags = !empty($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; - $searchterm = !empty($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; + $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; + $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; - // Search tags + fullsearch. - if (! empty($searchtags) && ! empty($searchterm)) { - $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; - $request = array($searchtags, $searchterm); - } - // Search by tags. - elseif (! empty($searchtags)) { - $type = LinkFilter::$FILTER_TAG; - $request = $searchtags; - } - // Fulltext search. - elseif (! empty($searchterm)) { - $type = LinkFilter::$FILTER_TEXT; - $request = $searchterm; - } - // Otherwise, display without filtering. - else { - $type = ''; - $request = ''; - } + // Search tags + fullsearch - blank string parameter will return all links. + $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; + $request = [$searchtags, $searchterm]; $linkFilter = new LinkFilter($this); return $linkFilter->filter($type, $request, $casesensitive, $visibility); } /** - * Returns the list of all tags - * Output: associative array key=tags, value=0 + * Returns the list tags appearing in the links with the given tags + * @param $filteringTags: tags selecting the links to consider + * @param $visibility: process only all/private/public links + * @return: a tag=>linksCount array */ - public function allTags() + public function linksCountPerTag($filteringTags = [], $visibility = 'all') { + $links = empty($filteringTags) ? $this->links : $this->filterSearch(['searchtags' => $filteringTags], false, $visibility); $tags = array(); $caseMapping = array(); - foreach ($this->links as $link) { + foreach ($links as $link) { foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { if (empty($tag)) { continue;