aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 01:22:45 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 22:47:48 +0100
commit6696729b88e67504fdd333cbaab43a63c3617d86 (patch)
treef617e4108e0a2d41278935f4a2b4528f49e70c6d /application
parentf24896b237e40718fb6eaa2869592eb0855a47fd (diff)
downloadShaarli-6696729b88e67504fdd333cbaab43a63c3617d86.tar.gz
Shaarli-6696729b88e67504fdd333cbaab43a63c3617d86.tar.zst
Shaarli-6696729b88e67504fdd333cbaab43a63c3617d86.zip
namespacing: \Shaarli\Bookmark\LinkFilter
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'application')
-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
4 files changed, 47 insertions, 37 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}