From f210d94f716acd86fd22c9651f591a778490e8a9 Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Thu, 1 Jun 2017 17:55:26 +0200 Subject: [PATCH] Using only one form in linklist.html + adding untaggedonly filter - fix #885 --- application/LinkDB.php | 7 +++-- application/LinkFilter.php | 41 ++++++++++++++++---------- application/PageBuilder.php | 1 + index.php | 16 +++++++++- tests/LinkFilterTest.php | 3 +- tpl/default/css/shaarli.css | 49 +++++++++++++++---------------- tpl/default/linklist.html | 50 ++++++++++++++------------------ tpl/default/linklist.paging.html | 11 ++++--- tpl/default/page.header.html | 39 ++++++++++--------------- 9 files changed, 113 insertions(+), 104 deletions(-) diff --git a/application/LinkDB.php b/application/LinkDB.php index 8ca0fab..9e3efd6 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 0e887d3..9551952 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); + 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); } - if (isset($request[1])) { - $lf = new LinkFilter($filtered); - $filtered = $lf->filterFulltext($request[1], $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 c86621a..7a42400 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')); diff --git a/index.php b/index.php index 85486eb..5c292b0 100644 --- a/index.php +++ b/index.php @@ -287,6 +287,7 @@ function logout() { unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); + unset($_SESSION['untaggedonly']); } setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); } @@ -1017,6 +1018,19 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) exit; } + // -------- User wants to see only untagged links (toggle) + if (isset($_GET['untaggedonly'])) { + $_SESSION['untaggedonly'] = !$_SESSION['untaggedonly']; + + if (! empty($_SERVER['HTTP_REFERER'])) { + $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('untaggedonly')); + } else { + $location = '?'; + } + header('Location: '. $location); + exit; + } + // -------- Handle other actions allowed for non-logged in users: if (!isLoggedIn()) { @@ -1651,7 +1665,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) 'searchtags' => $searchtags, 'searchterm' => $searchterm, ]; - $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility); + $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility, !empty($_SESSION['untaggedonly'])); } // ---- Handle paging. diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php index 7416235..d796d3a 100644 --- a/tests/LinkFilterTest.php +++ b/tests/LinkFilterTest.php @@ -63,10 +63,9 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '')) ); - // Untagged only $this->assertEquals( self::$refDB->countUntaggedLinks(), - count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, false)) + count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, /*$request=*/'', /*$casesensitive=*/false, /*$visibility=*/'all', /*$untaggedonly=*/true)) ); $this->assertEquals( diff --git a/tpl/default/css/shaarli.css b/tpl/default/css/shaarli.css index 39bbd0a..e1868c5 100644 --- a/tpl/default/css/shaarli.css +++ b/tpl/default/css/shaarli.css @@ -226,6 +226,12 @@ body, .pure-g [class*="pure-u"] { border-radius: 2px; color: #252525; } +@media screen and (max-width: 64em) { + .searchform { + max-width: 260px; + margin: 0 auto; + } +} /* because chrome */ #search input[type="text"]::-webkit-input-placeholder, @@ -236,43 +242,37 @@ body, .pure-g [class*="pure-u"] { #search button, #search-tagcloud button, #search-linklist button { - background: transparent; - border: none; -} - -#search button { + padding: 4px 8px 6px 8px; + background-color: #1B926C; color: #f5f5f5; + border: none; + border-radius: 2px; } -#search-linklist button { - color: #252525; +#search-tagcloud button { + width: 90%; +} + +@media screen and (max-width: 64em) { + #search-linklist button { + width: 100%; + } + #search-linklist .awesomplete { + margin: 5px 0; + } } #search button:hover, -#search-linklist button:hover { - color: #fff; -} +#search-linklist button:hover, #search-tagcloud button:hover { color: #d0d0d0; } +#search, #search-linklist { - padding: 5px 0; + padding: 6px 0; } -@media screen and (min-width: 64em) { - #search .searchform, - #search-linklist .searchform { - margin-right: 25px; - text-align: right; - } - - #search .tagfilter, - #search-linklist .tagfilter { - margin-left: 25px; - text-align: left; - } -} @media screen and (max-width: 64em) { #search, #search * { visibility: hidden; @@ -321,7 +321,6 @@ body, .pure-g [class*="pure-u"] { } .subheader-form input[type="text"], .subheader-form input[type="password"], .subheader-form .remember-me { - margin: 0 0 5px 0; padding: 5px 5px 3px 15px; height: 20px; width: 20%; diff --git a/tpl/default/linklist.html b/tpl/default/linklist.html index 2568a5d..685821e 100644 --- a/tpl/default/linklist.html +++ b/tpl/default/linklist.html @@ -19,30 +19,21 @@ {loop="$plugins_header.fields_toolbar"} @@ -91,7 +82,7 @@
{'Nothing found.'|t}
- {elseif="!empty($search_term) or $search_tags !== '' or !empty($visibility)"} + {elseif="!empty($search_term) or $search_tags !== '' or !empty($visibility) or $untaggedonly"}
@@ -107,10 +98,6 @@ {$value} {/loop} - {elseif="$search_tags === false"} - - {'untagged'|t} - {/if} {if="!empty($visibility)"} {'with status'|t} @@ -118,6 +105,11 @@ {$visibility|t} {/if} + {if="$untaggedonly"} + + {'without any tag'|t} + + {/if}
{/if} diff --git a/tpl/default/linklist.paging.html b/tpl/default/linklist.paging.html index d8c1e76..41e9fa3 100644 --- a/tpl/default/linklist.paging.html +++ b/tpl/default/linklist.paging.html @@ -6,10 +6,13 @@ {'Filters'|t} {if="isLoggedIn()"} - + {/if} + @@ -55,4 +58,4 @@ - \ No newline at end of file + diff --git a/tpl/default/page.header.html b/tpl/default/page.header.html index 6c71a71..2411703 100644 --- a/tpl/default/page.header.html +++ b/tpl/default/page.header.html @@ -97,30 +97,21 @@