aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Updater.php1
-rw-r--r--application/bookmark/LinkDB.php26
-rw-r--r--application/bookmark/LinkFilter.php (renamed from application/LinkFilter.php)42
-rw-r--r--application/bookmark/exception/LinkNotFoundException.php15
-rw-r--r--composer.json1
-rw-r--r--index.php2
-rw-r--r--tests/bookmark/LinkDBTest.php6
-rw-r--r--tests/bookmark/LinkFilterTest.php (renamed from tests/LinkFilterTest.php)23
8 files changed, 66 insertions, 50 deletions
diff --git a/application/Updater.php b/application/Updater.php
index 043ecf68..ca05ecc2 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -1,6 +1,7 @@
1<?php 1<?php
2 2
3use Shaarli\Bookmark\LinkDB; 3use Shaarli\Bookmark\LinkDB;
4use Shaarli\Bookmark\LinkFilter;
4use Shaarli\Config\ConfigJson; 5use Shaarli\Config\ConfigJson;
5use Shaarli\Config\ConfigPhp; 6use Shaarli\Config\ConfigPhp;
6use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
diff --git a/application/bookmark/LinkDB.php b/application/bookmark/LinkDB.php
index 3b77422a..6041c088 100644
--- a/application/bookmark/LinkDB.php
+++ b/application/bookmark/LinkDB.php
@@ -6,8 +6,8 @@ use ArrayAccess;
6use Countable; 6use Countable;
7use DateTime; 7use DateTime;
8use Iterator; 8use Iterator;
9use LinkFilter; 9use Shaarli\Bookmark\LinkFilter;
10use LinkNotFoundException; 10use Shaarli\Bookmark\Exception\LinkNotFoundException;
11use Shaarli\Exceptions\IOException; 11use Shaarli\Exceptions\IOException;
12use Shaarli\FileUtils; 12use Shaarli\FileUtils;
13 13
@@ -107,10 +107,10 @@ class LinkDB implements Iterator, Countable, ArrayAccess
107 * 107 *
108 * Checks if the datastore exists; else, attempts to create a dummy one. 108 * Checks if the datastore exists; else, attempts to create a dummy one.
109 * 109 *
110 * @param string $datastore datastore file path. 110 * @param string $datastore datastore file path.
111 * @param boolean $isLoggedIn is the user logged in? 111 * @param boolean $isLoggedIn is the user logged in?
112 * @param boolean $hidePublicLinks if true all links are private. 112 * @param boolean $hidePublicLinks if true all links are private.
113 * @param string $redirector link redirector set in user settings. 113 * @param string $redirector link redirector set in user settings.
114 * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true). 114 * @param boolean $redirectorEncode Enable urlencode on redirected urls (default: true).
115 */ 115 */
116 public function __construct( 116 public function __construct(
@@ -426,12 +426,12 @@ You use the community supported version of the original Shaarli project, by Seba
426 /** 426 /**
427 * Filter links according to search parameters. 427 * Filter links according to search parameters.
428 * 428 *
429 * @param array $filterRequest Search request content. Supported keys: 429 * @param array $filterRequest Search request content. Supported keys:
430 * - searchtags: list of tags 430 * - searchtags: list of tags
431 * - searchterm: term search 431 * - searchterm: term search
432 * @param bool $casesensitive Optional: Perform case sensitive filter 432 * @param bool $casesensitive Optional: Perform case sensitive filter
433 * @param string $visibility return only all/private/public links 433 * @param string $visibility return only all/private/public links
434 * @param string $untaggedonly return only untagged links 434 * @param bool $untaggedonly return only untagged links
435 * 435 *
436 * @return array filtered links, all links if no suitable filter was provided. 436 * @return array filtered links, all links if no suitable filter was provided.
437 */ 437 */
@@ -457,8 +457,8 @@ You use the community supported version of the original Shaarli project, by Seba
457 /** 457 /**
458 * Returns the list tags appearing in the links with the given tags 458 * Returns the list tags appearing in the links with the given tags
459 * 459 *
460 * @param array $filteringTags tags selecting the links to consider 460 * @param array $filteringTags tags selecting the links to consider
461 * @param string $visibility process only all/private/public links 461 * @param string $visibility process only all/private/public links
462 * 462 *
463 * @return array tag => linksCount 463 * @return array tag => linksCount
464 */ 464 */
@@ -500,7 +500,7 @@ You use the community supported version of the original Shaarli project, by Seba
500 * Rename or delete a tag across all links. 500 * Rename or delete a tag across all links.
501 * 501 *
502 * @param string $from Tag to rename 502 * @param string $from Tag to rename
503 * @param string $to New tag. If none is provided, the from tag will be deleted 503 * @param string $to New tag. If none is provided, the from tag will be deleted
504 * 504 *
505 * @return array|bool List of altered links or false on error 505 * @return array|bool List of altered links or false on error
506 */ 506 */
diff --git a/application/LinkFilter.php b/application/bookmark/LinkFilter.php
index 91c79905..9b966307 100644
--- a/application/LinkFilter.php
+++ b/application/bookmark/LinkFilter.php
@@ -1,6 +1,9 @@
1<?php 1<?php
2 2
3use Shaarli\Bookmark\LinkDB; 3namespace Shaarli\Bookmark;
4
5use Exception;
6use Shaarli\Bookmark\Exception\LinkNotFoundException;
4 7
5/** 8/**
6 * Class LinkFilter. 9 * Class LinkFilter.
@@ -12,22 +15,22 @@ class LinkFilter
12 /** 15 /**
13 * @var string permalinks. 16 * @var string permalinks.
14 */ 17 */
15 public static $FILTER_HASH = 'permalink'; 18 public static $FILTER_HASH = 'permalink';
16 19
17 /** 20 /**
18 * @var string text search. 21 * @var string text search.
19 */ 22 */
20 public static $FILTER_TEXT = 'fulltext'; 23 public static $FILTER_TEXT = 'fulltext';
21 24
22 /** 25 /**
23 * @var string tag filter. 26 * @var string tag filter.
24 */ 27 */
25 public static $FILTER_TAG = 'tags'; 28 public static $FILTER_TAG = 'tags';
26 29
27 /** 30 /**
28 * @var string filter by day. 31 * @var string filter by day.
29 */ 32 */
30 public static $FILTER_DAY = 'FILTER_DAY'; 33 public static $FILTER_DAY = 'FILTER_DAY';
31 34
32 /** 35 /**
33 * @var string Allowed characters for hashtags (regex syntax). 36 * @var string Allowed characters for hashtags (regex syntax).
@@ -60,7 +63,7 @@ class LinkFilter
60 */ 63 */
61 public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false) 64 public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
62 { 65 {
63 if (! in_array($visibility, ['all', 'public', 'private'])) { 66 if (!in_array($visibility, ['all', 'public', 'private'])) {
64 $visibility = 'all'; 67 $visibility = 'all';
65 } 68 }
66 69
@@ -119,7 +122,7 @@ class LinkFilter
119 foreach ($this->links as $key => $value) { 122 foreach ($this->links as $key => $value) {
120 if ($value['private'] && $visibility === 'private') { 123 if ($value['private'] && $visibility === 'private') {
121 $out[$key] = $value; 124 $out[$key] = $value;
122 } elseif (! $value['private'] && $visibility === 'public') { 125 } elseif (!$value['private'] && $visibility === 'public') {
123 $out[$key] = $value; 126 $out[$key] = $value;
124 } 127 }
125 } 128 }
@@ -134,7 +137,7 @@ class LinkFilter
134 * 137 *
135 * @return array $filtered array containing permalink data. 138 * @return array $filtered array containing permalink data.
136 * 139 *
137 * @throws LinkNotFoundException if the smallhash doesn't match any link. 140 * @throws \Shaarli\Bookmark\Exception\LinkNotFoundException if the smallhash doesn't match any link.
138 */ 141 */
139 private function filterSmallHash($smallHash) 142 private function filterSmallHash($smallHash)
140 { 143 {
@@ -171,7 +174,7 @@ class LinkFilter
171 * - see https://github.com/shaarli/Shaarli/issues/75 for examples 174 * - see https://github.com/shaarli/Shaarli/issues/75 for examples
172 * 175 *
173 * @param string $searchterms search query. 176 * @param string $searchterms search query.
174 * @param string $visibility Optional: return only all/private/public links. 177 * @param string $visibility Optional: return only all/private/public links.
175 * 178 *
176 * @return array search results. 179 * @return array search results.
177 */ 180 */
@@ -209,7 +212,7 @@ class LinkFilter
209 foreach ($this->links as $id => $link) { 212 foreach ($this->links as $id => $link) {
210 // ignore non private links when 'privatonly' is on. 213 // ignore non private links when 'privatonly' is on.
211 if ($visibility !== 'all') { 214 if ($visibility !== 'all') {
212 if (! $link['private'] && $visibility === 'private') { 215 if (!$link['private'] && $visibility === 'private') {
213 continue; 216 continue;
214 } elseif ($link['private'] && $visibility === 'public') { 217 } elseif ($link['private'] && $visibility === 'public') {
215 continue; 218 continue;
@@ -252,7 +255,9 @@ class LinkFilter
252 255
253 /** 256 /**
254 * generate a regex fragment out of a tag 257 * generate a regex fragment out of a tag
258 *
255 * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard 259 * @param string $tag to to generate regexs from. may start with '-' to negate, contain '*' as wildcard
260 *
256 * @return string generated regex fragment 261 * @return string generated regex fragment
257 */ 262 */
258 private static function tag2regex($tag) 263 private static function tag2regex($tag)
@@ -336,7 +341,7 @@ class LinkFilter
336 // check level of visibility 341 // check level of visibility
337 // ignore non private links when 'privateonly' is on. 342 // ignore non private links when 'privateonly' is on.
338 if ($visibility !== 'all') { 343 if ($visibility !== 'all') {
339 if (! $link['private'] && $visibility === 'private') { 344 if (!$link['private'] && $visibility === 'private') {
340 continue; 345 continue;
341 } elseif ($link['private'] && $visibility === 'public') { 346 } elseif ($link['private'] && $visibility === 'public') {
342 continue; 347 continue;
@@ -379,7 +384,7 @@ class LinkFilter
379 $filtered = []; 384 $filtered = [];
380 foreach ($this->links as $key => $link) { 385 foreach ($this->links as $key => $link) {
381 if ($visibility !== 'all') { 386 if ($visibility !== 'all') {
382 if (! $link['private'] && $visibility === 'private') { 387 if (!$link['private'] && $visibility === 'private') {
383 continue; 388 continue;
384 } elseif ($link['private'] && $visibility === 'public') { 389 } elseif ($link['private'] && $visibility === 'public') {
385 continue; 390 continue;
@@ -408,7 +413,7 @@ class LinkFilter
408 */ 413 */
409 public function filterDay($day) 414 public function filterDay($day)
410 { 415 {
411 if (! checkDateFormat('Ymd', $day)) { 416 if (!checkDateFormat('Ymd', $day)) {
412 throw new Exception('Invalid date format'); 417 throw new Exception('Invalid date format');
413 } 418 }
414 419
@@ -442,14 +447,3 @@ class LinkFilter
442 return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY); 447 return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
443 } 448 }
444} 449}
445
446class LinkNotFoundException extends Exception
447{
448 /**
449 * LinkNotFoundException constructor.
450 */
451 public function __construct()
452 {
453 $this->message = t('The link you are trying to reach does not exist or has been deleted.');
454 }
455}
diff --git a/application/bookmark/exception/LinkNotFoundException.php b/application/bookmark/exception/LinkNotFoundException.php
new file mode 100644
index 00000000..f9414428
--- /dev/null
+++ b/application/bookmark/exception/LinkNotFoundException.php
@@ -0,0 +1,15 @@
1<?php
2namespace Shaarli\Bookmark\Exception;
3
4use Exception;
5
6class LinkNotFoundException extends Exception
7{
8 /**
9 * LinkNotFoundException constructor.
10 */
11 public function __construct()
12 {
13 $this->message = t('The link you are trying to reach does not exist or has been deleted.');
14 }
15}
diff --git a/composer.json b/composer.json
index e8dc2eb1..7d0f96b3 100644
--- a/composer.json
+++ b/composer.json
@@ -36,6 +36,7 @@
36 "Shaarli\\Api\\Controllers\\": "application/api/controllers", 36 "Shaarli\\Api\\Controllers\\": "application/api/controllers",
37 "Shaarli\\Api\\Exceptions\\": "application/api/exceptions", 37 "Shaarli\\Api\\Exceptions\\": "application/api/exceptions",
38 "Shaarli\\Bookmark\\": "application/bookmark", 38 "Shaarli\\Bookmark\\": "application/bookmark",
39 "Shaarli\\Bookmark\\Exception\\": "application/bookmark/exception",
39 "Shaarli\\Config\\": "application/config/", 40 "Shaarli\\Config\\": "application/config/",
40 "Shaarli\\Config\\Exception\\": "application/config/exception", 41 "Shaarli\\Config\\Exception\\": "application/config/exception",
41 "Shaarli\\Exceptions\\": "application/exceptions", 42 "Shaarli\\Exceptions\\": "application/exceptions",
diff --git a/index.php b/index.php
index b1d37a01..dbb3c6fc 100644
--- a/index.php
+++ b/index.php
@@ -63,7 +63,6 @@ require_once 'application/http/HttpUtils.php';
63require_once 'application/http/UrlUtils.php'; 63require_once 'application/http/UrlUtils.php';
64require_once 'application/FileUtils.php'; 64require_once 'application/FileUtils.php';
65require_once 'application/History.php'; 65require_once 'application/History.php';
66require_once 'application/LinkFilter.php';
67require_once 'application/LinkUtils.php'; 66require_once 'application/LinkUtils.php';
68require_once 'application/NetscapeBookmarkUtils.php'; 67require_once 'application/NetscapeBookmarkUtils.php';
69require_once 'application/TimeZone.php'; 68require_once 'application/TimeZone.php';
@@ -72,6 +71,7 @@ require_once 'application/PluginManager.php';
72require_once 'application/Router.php'; 71require_once 'application/Router.php';
73require_once 'application/Updater.php'; 72require_once 'application/Updater.php';
74 73
74use \Shaarli\Bookmark\Exception\LinkNotFoundException;
75use \Shaarli\Bookmark\LinkDB; 75use \Shaarli\Bookmark\LinkDB;
76use \Shaarli\Config\ConfigManager; 76use \Shaarli\Config\ConfigManager;
77use \Shaarli\Feed\CachedPage; 77use \Shaarli\Feed\CachedPage;
diff --git a/tests/bookmark/LinkDBTest.php b/tests/bookmark/LinkDBTest.php
index f18a3155..65409e95 100644
--- a/tests/bookmark/LinkDBTest.php
+++ b/tests/bookmark/LinkDBTest.php
@@ -6,7 +6,7 @@
6namespace Shaarli\Bookmark; 6namespace Shaarli\Bookmark;
7 7
8use DateTime; 8use DateTime;
9use LinkNotFoundException; 9use Shaarli\Bookmark\Exception\LinkNotFoundException;
10use ReferenceLinkDB; 10use ReferenceLinkDB;
11use ReflectionClass; 11use ReflectionClass;
12use Shaarli; 12use Shaarli;
@@ -457,7 +457,7 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase
457 /** 457 /**
458 * Test filterHash() with an invalid smallhash. 458 * Test filterHash() with an invalid smallhash.
459 * 459 *
460 * @expectedException LinkNotFoundException 460 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
461 */ 461 */
462 public function testFilterHashInValid1() 462 public function testFilterHashInValid1()
463 { 463 {
@@ -468,7 +468,7 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase
468 /** 468 /**
469 * Test filterHash() with an empty smallhash. 469 * Test filterHash() with an empty smallhash.
470 * 470 *
471 * @expectedException LinkNotFoundException 471 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
472 */ 472 */
473 public function testFilterHashInValid() 473 public function testFilterHashInValid()
474 { 474 {
diff --git a/tests/LinkFilterTest.php b/tests/bookmark/LinkFilterTest.php
index db28b1c4..808f8122 100644
--- a/tests/LinkFilterTest.php
+++ b/tests/bookmark/LinkFilterTest.php
@@ -1,13 +1,14 @@
1<?php 1<?php
2 2
3use Shaarli\Bookmark\LinkDB; 3namespace Shaarli\Bookmark;
4 4
5require_once 'application/LinkFilter.php'; 5use Exception;
6use ReferenceLinkDB;
6 7
7/** 8/**
8 * Class LinkFilterTest. 9 * Class LinkFilterTest.
9 */ 10 */
10class LinkFilterTest extends PHPUnit_Framework_TestCase 11class LinkFilterTest extends \PHPUnit\Framework\TestCase
11{ 12{
12 /** 13 /**
13 * @var string Test datastore path. 14 * @var string Test datastore path.
@@ -29,7 +30,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
29 protected static $linkDB; 30 protected static $linkDB;
30 31
31 /** 32 /**
32 * Instanciate linkFilter with ReferenceLinkDB data. 33 * Instantiate linkFilter with ReferenceLinkDB data.
33 */ 34 */
34 public static function setUpBeforeClass() 35 public static function setUpBeforeClass()
35 { 36 {
@@ -81,10 +82,14 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
81 count( 82 count(
82 self::$linkFilter->filter( 83 self::$linkFilter->filter(
83 LinkFilter::$FILTER_TAG, 84 LinkFilter::$FILTER_TAG,
84 /*$request=*/'', 85 /*$request=*/
85 /*$casesensitive=*/false, 86 '',
86 /*$visibility=*/'all', 87 /*$casesensitive=*/
87 /*$untaggedonly=*/true 88 false,
89 /*$visibility=*/
90 'all',
91 /*$untaggedonly=*/
92 true
88 ) 93 )
89 ) 94 )
90 ); 95 );
@@ -229,7 +234,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
229 /** 234 /**
230 * No link for this hash 235 * No link for this hash
231 * 236 *
232 * @expectedException LinkNotFoundException 237 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
233 */ 238 */
234 public function testFilterUnknownSmallHash() 239 public function testFilterUnknownSmallHash()
235 { 240 {