From f210d94f716acd86fd22c9651f591a778490e8a9 Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Thu, 1 Jun 2017 17:55:26 +0200 Subject: Using only one form in linklist.html + adding untaggedonly filter - fix #885 --- application/LinkDB.php | 7 ++++--- application/LinkFilter.php | 41 +++++++++++++++++++++++++---------------- application/PageBuilder.php | 1 + 3 files changed, 30 insertions(+), 19 deletions(-) (limited to 'application') diff --git a/application/LinkDB.php b/application/LinkDB.php index 8ca0fab3..9e3efd6b 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php @@ -417,21 +417,22 @@ You use the community supported version of the original Shaarli project, by Seba * - searchterm: term search * @param bool $casesensitive Optional: Perform case sensitive filter * @param string $visibility return only all/private/public links + * @param string $untaggedonly return only untagged links * * @return array filtered links, all links if no suitable filter was provided. */ - public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all') + public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all', $untaggedonly = false) { // Filter link database according to parameters. $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; // Search tags + fullsearch - blank string parameter will return all links. - $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; + $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; // == "vuotext" $request = [$searchtags, $searchterm]; $linkFilter = new LinkFilter($this); - return $linkFilter->filter($type, $request, $casesensitive, $visibility); + return $linkFilter->filter($type, $request, $casesensitive, $visibility, $untaggedonly); } /** diff --git a/application/LinkFilter.php b/application/LinkFilter.php index 0e887d38..95519528 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php @@ -52,10 +52,11 @@ class LinkFilter * @param mixed $request Filter content. * @param bool $casesensitive Optional: Perform case sensitive filter if true. * @param string $visibility Optional: return only all/private/public links + * @param string $untaggedonly Optional: return only untagged links. Applies only if $type includes FILTER_TAG * * @return array filtered link list. */ - public function filter($type, $request, $casesensitive = false, $visibility = 'all') + public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false) { if (! in_array($visibility, ['all', 'public', 'private'])) { $visibility = 'all'; @@ -64,23 +65,34 @@ class LinkFilter switch($type) { case self::$FILTER_HASH: return $this->filterSmallHash($request); - case self::$FILTER_TAG | self::$FILTER_TEXT: - if (!empty($request)) { - $filtered = $this->links; - if (isset($request[0])) { - $filtered = $this->filterTags($request[0], $casesensitive, $visibility); - } - if (isset($request[1])) { - $lf = new LinkFilter($filtered); - $filtered = $lf->filterFulltext($request[1], $visibility); + case self::$FILTER_TAG | self::$FILTER_TEXT: // == "vuotext" + $noRequest = empty($request) || (empty($request[0]) && empty($request[1])); + if ($noRequest) { + if ($untaggedonly) { + return $this->filterUntagged($visibility); } - return $filtered; + return $this->noFilter($visibility); } - return $this->noFilter($visibility); + if ($untaggedonly) { + $filtered = $this->filterUntagged($visibility); + } else { + $filtered = $this->links; + } + if (!empty($request[0])) { + $filtered = (new LinkFilter($filtered))->filterTags($request[0], $casesensitive, $visibility); + } + if (!empty($request[1])) { + $filtered = (new LinkFilter($filtered))->filterFulltext($request[1], $visibility); + } + return $filtered; case self::$FILTER_TEXT: return $this->filterFulltext($request, $visibility); case self::$FILTER_TAG: - return $this->filterTags($request, $casesensitive, $visibility); + if ($untaggedonly) { + return $this->filterUntagged($visibility); + } else { + return $this->filterTags($request, $casesensitive, $visibility); + } case self::$FILTER_DAY: return $this->filterDay($request); default: @@ -253,9 +265,6 @@ 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); } diff --git a/application/PageBuilder.php b/application/PageBuilder.php index c86621a2..7a42400d 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -78,6 +78,7 @@ class PageBuilder $this->tpl->assign('version', shaarli_version); $this->tpl->assign('scripturl', index_url($_SERVER)); $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? + $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); if ($this->conf->exists('general.header_link')) { $this->tpl->assign('titleLink', $this->conf->get('general.header_link')); -- cgit v1.2.3