aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/bookmark/BookmarkArray.php9
-rw-r--r--application/bookmark/BookmarkFileService.php13
-rw-r--r--application/bookmark/BookmarkServiceInterface.php9
-rw-r--r--application/feed/FeedBuilder.php2
-rw-r--r--tests/feed/FeedBuilderTest.php12
5 files changed, 31 insertions, 14 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
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index 5c2aaedb..fe37d5f2 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -87,7 +87,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
87 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 87 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
88 88
89 // Test first not pinned link (note link) 89 // Test first not pinned link (note link)
90 $link = $data['links'][array_keys($data['links'])[2]]; 90 $link = $data['links'][array_keys($data['links'])[0]];
91 $this->assertEquals(41, $link['id']); 91 $this->assertEquals(41, $link['id']);
92 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 92 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
93 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); 93 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
@@ -128,7 +128,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
128 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); 128 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
129 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 129 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
130 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); 130 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
131 $link = $data['links'][array_keys($data['links'])[2]]; 131 $link = $data['links'][array_keys($data['links'])[0]];
132 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); 132 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
133 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); 133 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
134 } 134 }
@@ -173,7 +173,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
173 $feedBuilder->setLocale(self::$LOCALE); 173 $feedBuilder->setLocale(self::$LOCALE);
174 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria); 174 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, $criteria);
175 $this->assertEquals(3, count($data['links'])); 175 $this->assertEquals(3, count($data['links']));
176 $link = $data['links'][array_keys($data['links'])[2]]; 176 $link = $data['links'][array_keys($data['links'])[0]];
177 $this->assertEquals(41, $link['id']); 177 $this->assertEquals(41, $link['id']);
178 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 178 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
179 } 179 }
@@ -195,7 +195,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
195 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 195 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
196 $this->assertTrue($data['usepermalinks']); 196 $this->assertTrue($data['usepermalinks']);
197 // First link is a permalink 197 // First link is a permalink
198 $link = $data['links'][array_keys($data['links'])[2]]; 198 $link = $data['links'][array_keys($data['links'])[0]];
199 $this->assertEquals(41, $link['id']); 199 $this->assertEquals(41, $link['id']);
200 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 200 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
201 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']); 201 $this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
@@ -203,7 +203,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
203 $this->assertContains('Direct link', $link['description']); 203 $this->assertContains('Direct link', $link['description']);
204 $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']); 204 $this->assertContains('http://host.tld/shaare/WDWyig', $link['description']);
205 // Second link is a direct link 205 // Second link is a direct link
206 $link = $data['links'][array_keys($data['links'])[3]]; 206 $link = $data['links'][array_keys($data['links'])[1]];
207 $this->assertEquals(8, $link['id']); 207 $this->assertEquals(8, $link['id']);
208 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); 208 $this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
209 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']); 209 $this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
@@ -270,7 +270,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
270 ); 270 );
271 271
272 // Test first link (note link) 272 // Test first link (note link)
273 $link = $data['links'][array_keys($data['links'])[2]]; 273 $link = $data['links'][array_keys($data['links'])[0]];
274 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']); 274 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']);
275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']); 275 $this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']);
276 $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']); 276 $this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);