diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-03 08:45:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 08:45:12 +0200 |
commit | 2835ac7cbe65fd2b602cadad5e9d6b09eb670d59 (patch) | |
tree | f2f51a3a891060aeafef5b963a465bc29eaa823d /application | |
parent | ca636b898ccd62fbef68048ea29e3f922de7429f (diff) | |
parent | a8e210faa624517ee8b8978b7e659a0b3c689297 (diff) | |
download | Shaarli-2835ac7cbe65fd2b602cadad5e9d6b09eb670d59.tar.gz Shaarli-2835ac7cbe65fd2b602cadad5e9d6b09eb670d59.tar.zst Shaarli-2835ac7cbe65fd2b602cadad5e9d6b09eb670d59.zip |
Merge pull request #1524 from ArthurHoaro/fix/rss-sticky
Fixed: Pinned bookmarks are displayed first in ATOM/RSS feeds
Diffstat (limited to 'application')
-rw-r--r-- | application/bookmark/BookmarkArray.php | 9 | ||||
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 13 | ||||
-rw-r--r-- | application/bookmark/BookmarkServiceInterface.php | 9 | ||||
-rw-r--r-- | application/feed/FeedBuilder.php | 2 |
4 files changed, 25 insertions, 8 deletions
diff --git a/application/bookmark/BookmarkArray.php b/application/bookmark/BookmarkArray.php index d87d43b4..3bd5eb20 100644 --- a/application/bookmark/BookmarkArray.php +++ b/application/bookmark/BookmarkArray.php | |||
@@ -234,16 +234,17 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess | |||
234 | * | 234 | * |
235 | * Also update the urls and ids mapping arrays. | 235 | * Also update the urls and ids mapping arrays. |
236 | * | 236 | * |
237 | * @param string $order ASC|DESC | 237 | * @param string $order ASC|DESC |
238 | * @param bool $ignoreSticky If set to true, sticky bookmarks won't be first | ||
238 | */ | 239 | */ |
239 | public function reorder($order = 'DESC') | 240 | public function reorder(string $order = 'DESC', bool $ignoreSticky = false): void |
240 | { | 241 | { |
241 | $order = $order === 'ASC' ? -1 : 1; | 242 | $order = $order === 'ASC' ? -1 : 1; |
242 | // Reorder array by dates. | 243 | // Reorder array by dates. |
243 | usort($this->bookmarks, function ($a, $b) use ($order) { | 244 | usort($this->bookmarks, function ($a, $b) use ($order, $ignoreSticky) { |
244 | /** @var $a Bookmark */ | 245 | /** @var $a Bookmark */ |
245 | /** @var $b Bookmark */ | 246 | /** @var $b Bookmark */ |
246 | if ($a->isSticky() !== $b->isSticky()) { | 247 | if (false === $ignoreSticky && $a->isSticky() !== $b->isSticky()) { |
247 | return $a->isSticky() ? -1 : 1; | 248 | return $a->isSticky() ? -1 : 1; |
248 | } | 249 | } |
249 | return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order; | 250 | return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order; |
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index b3a90ed4..e3a61146 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php | |||
@@ -114,8 +114,13 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
114 | /** | 114 | /** |
115 | * @inheritDoc | 115 | * @inheritDoc |
116 | */ | 116 | */ |
117 | public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false) | 117 | public function search( |
118 | { | 118 | $request = [], |
119 | $visibility = null, | ||
120 | $caseSensitive = false, | ||
121 | $untaggedOnly = false, | ||
122 | bool $ignoreSticky = false | ||
123 | ) { | ||
119 | if ($visibility === null) { | 124 | if ($visibility === null) { |
120 | $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; | 125 | $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; |
121 | } | 126 | } |
@@ -124,6 +129,10 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
124 | $searchtags = isset($request['searchtags']) ? $request['searchtags'] : ''; | 129 | $searchtags = isset($request['searchtags']) ? $request['searchtags'] : ''; |
125 | $searchterm = isset($request['searchterm']) ? $request['searchterm'] : ''; | 130 | $searchterm = isset($request['searchterm']) ? $request['searchterm'] : ''; |
126 | 131 | ||
132 | if ($ignoreSticky) { | ||
133 | $this->bookmarks->reorder('DESC', true); | ||
134 | } | ||
135 | |||
127 | return $this->bookmarkFilter->filter( | 136 | return $this->bookmarkFilter->filter( |
128 | BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT, | 137 | BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT, |
129 | [$searchtags, $searchterm], | 138 | [$searchtags, $searchterm], |
diff --git a/application/bookmark/BookmarkServiceInterface.php b/application/bookmark/BookmarkServiceInterface.php index ce8bd912..b9b483eb 100644 --- a/application/bookmark/BookmarkServiceInterface.php +++ b/application/bookmark/BookmarkServiceInterface.php | |||
@@ -49,10 +49,17 @@ interface BookmarkServiceInterface | |||
49 | * @param string $visibility | 49 | * @param string $visibility |
50 | * @param bool $caseSensitive | 50 | * @param bool $caseSensitive |
51 | * @param bool $untaggedOnly | 51 | * @param bool $untaggedOnly |
52 | * @param bool $ignoreSticky | ||
52 | * | 53 | * |
53 | * @return Bookmark[] | 54 | * @return Bookmark[] |
54 | */ | 55 | */ |
55 | public function search($request = [], $visibility = null, $caseSensitive = false, $untaggedOnly = false); | 56 | public function search( |
57 | $request = [], | ||
58 | $visibility = null, | ||
59 | $caseSensitive = false, | ||
60 | $untaggedOnly = false, | ||
61 | bool $ignoreSticky = false | ||
62 | ); | ||
56 | 63 | ||
57 | /** | 64 | /** |
58 | * Get a single bookmark by its ID. | 65 | * Get a single bookmark by its ID. |
diff --git a/application/feed/FeedBuilder.php b/application/feed/FeedBuilder.php index 269ad877..3653c32f 100644 --- a/application/feed/FeedBuilder.php +++ b/application/feed/FeedBuilder.php | |||
@@ -102,7 +102,7 @@ class FeedBuilder | |||
102 | } | 102 | } |
103 | 103 | ||
104 | // Optionally filter the results: | 104 | // Optionally filter the results: |
105 | $linksToDisplay = $this->linkDB->search($userInput); | 105 | $linksToDisplay = $this->linkDB->search($userInput, null, false, false, true); |
106 | 106 | ||
107 | $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput); | 107 | $nblinksToDisplay = $this->getNbLinks(count($linksToDisplay), $userInput); |
108 | 108 | ||