aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/bookmark/BookmarkFileService.php4
-rw-r--r--application/bookmark/BookmarkFilter.php17
-rw-r--r--application/bookmark/BookmarkInitializer.php74
-rw-r--r--application/container/ContainerBuilder.php4
-rw-r--r--application/container/ShaarliContainer.php9
-rw-r--r--application/front/controller/admin/PluginsController.php1
-rw-r--r--application/front/controller/admin/ShaarliAdminController.php2
-rw-r--r--application/front/controller/visitor/ErrorNotFoundController.php29
-rw-r--r--application/front/controller/visitor/ShaarliVisitorController.php26
-rw-r--r--application/plugin/PluginManager.php25
10 files changed, 145 insertions, 46 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php
index e3a61146..c9ec2609 100644
--- a/application/bookmark/BookmarkFileService.php
+++ b/application/bookmark/BookmarkFileService.php
@@ -362,7 +362,9 @@ class BookmarkFileService implements BookmarkServiceInterface
362 */ 362 */
363 public function filterDay($request) 363 public function filterDay($request)
364 { 364 {
365 return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request); 365 $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC;
366
367 return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request, false, $visibility);
366 } 368 }
367 369
368 /** 370 /**
diff --git a/application/bookmark/BookmarkFilter.php b/application/bookmark/BookmarkFilter.php
index 797a36b8..6636bbfe 100644
--- a/application/bookmark/BookmarkFilter.php
+++ b/application/bookmark/BookmarkFilter.php
@@ -115,7 +115,7 @@ class BookmarkFilter
115 return $this->filterTags($request, $casesensitive, $visibility); 115 return $this->filterTags($request, $casesensitive, $visibility);
116 } 116 }
117 case self::$FILTER_DAY: 117 case self::$FILTER_DAY:
118 return $this->filterDay($request); 118 return $this->filterDay($request, $visibility);
119 default: 119 default:
120 return $this->noFilter($visibility); 120 return $this->noFilter($visibility);
121 } 121 }
@@ -425,21 +425,26 @@ class BookmarkFilter
425 * print_r($mydb->filterDay('20120125')); 425 * print_r($mydb->filterDay('20120125'));
426 * 426 *
427 * @param string $day day to filter. 427 * @param string $day day to filter.
428 * 428 * @param string $visibility return only all/private/public bookmarks.
429
429 * @return array all link matching given day. 430 * @return array all link matching given day.
430 * 431 *
431 * @throws Exception if date format is invalid. 432 * @throws Exception if date format is invalid.
432 */ 433 */
433 public function filterDay($day) 434 public function filterDay($day, $visibility)
434 { 435 {
435 if (!checkDateFormat('Ymd', $day)) { 436 if (!checkDateFormat('Ymd', $day)) {
436 throw new Exception('Invalid date format'); 437 throw new Exception('Invalid date format');
437 } 438 }
438 439
439 $filtered = []; 440 $filtered = [];
440 foreach ($this->bookmarks as $key => $l) { 441 foreach ($this->bookmarks as $key => $bookmark) {
441 if ($l->getCreated()->format('Ymd') == $day) { 442 if ($visibility === static::$PUBLIC && $bookmark->isPrivate()) {
442 $filtered[$key] = $l; 443 continue;
444 }
445
446 if ($bookmark->getCreated()->format('Ymd') == $day) {
447 $filtered[$key] = $bookmark;
443 } 448 }
444 } 449 }
445 450
diff --git a/application/bookmark/BookmarkInitializer.php b/application/bookmark/BookmarkInitializer.php
index cd2d1724..815047e3 100644
--- a/application/bookmark/BookmarkInitializer.php
+++ b/application/bookmark/BookmarkInitializer.php
@@ -34,25 +34,77 @@ class BookmarkInitializer
34 public function initialize() 34 public function initialize()
35 { 35 {
36 $bookmark = new Bookmark(); 36 $bookmark = new Bookmark();
37 $bookmark->setTitle(t('My secret stuff... - Pastebin.com')); 37 $bookmark->setTitle('quicksilver (loop) on Vimeo ' . t('(private bookmark with thumbnail demo)'));
38 $bookmark->setUrl('http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8='); 38 $bookmark->setUrl('https://vimeo.com/153493904');
39 $bookmark->setDescription(t('Shhhh! I\'m a private link only YOU can see. You can delete me too.')); 39 $bookmark->setDescription(t(
40 $bookmark->setTagsString('secretstuff'); 40'Shaarli will automatically pick up the thumbnail for links to a variety of websites.
41
42Explore your new Shaarli instance by trying out controls and menus.
43Visit the project on [Github](https://github.com/shaarli/Shaarli) or [the documentation](https://shaarli.readthedocs.io/en/master/) to learn more about Shaarli.
44
45Now you can edit or delete the default shaares.
46'
47 ));
48 $bookmark->setTagsString('shaarli help thumbnail');
49 $bookmark->setPrivate(true);
50 $this->bookmarkService->add($bookmark, false);
51
52 $bookmark = new Bookmark();
53 $bookmark->setTitle(t('Note: Shaare descriptions'));
54 $bookmark->setDescription(t(
55'Adding a shaare without entering a URL creates a text-only "note" post such as this one.
56This note is private, so you are the only one able to see it while logged in.
57
58You can use this to keep notes, post articles, code snippets, and much more.
59
60The Markdown formatting setting allows you to format your notes and bookmark description:
61
62### Title headings
63
64#### Multiple headings levels
65 * bullet lists
66 * _italic_ text
67 * **bold** text
68 * ~~strike through~~ text
69 * `code` blocks
70 * images
71 * [links](https://en.wikipedia.org/wiki/Markdown)
72
73Markdown also supports tables:
74
75| Name | Type | Color | Qty |
76| ------- | --------- | ------ | ----- |
77| Orange | Fruit | Orange | 126 |
78| Apple | Fruit | Any | 62 |
79| Lemon | Fruit | Yellow | 30 |
80| Carrot | Vegetable | Red | 14 |
81'
82 ));
83 $bookmark->setTagsString('shaarli help');
41 $bookmark->setPrivate(true); 84 $bookmark->setPrivate(true);
42 $this->bookmarkService->add($bookmark, false); 85 $this->bookmarkService->add($bookmark, false);
43 86
44 $bookmark = new Bookmark(); 87 $bookmark = new Bookmark();
45 $bookmark->setTitle(t('The personal, minimalist, super-fast, database free, bookmarking service')); 88 $bookmark->setTitle(
46 $bookmark->setUrl('https://shaarli.readthedocs.io', []); 89 'Shaarli - ' . t('The personal, minimalist, super-fast, database free, bookmarking service')
90 );
47 $bookmark->setDescription(t( 91 $bookmark->setDescription(t(
48 'Welcome to Shaarli! This is your first public bookmark. ' 92'Welcome to Shaarli!
49 . 'To edit or delete me, you must first login. 93
94Shaarli allows you to bookmark your favorite pages, and share them with others or store them privately.
95You can add a description to your bookmarks, such as this one, and tag them.
96
97Create a new shaare by clicking the `+Shaare` button, or using any of the recommended tools (browser extension, mobile app, bookmarklet, REST API, etc.).
50 98
51To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page. 99You can easily retrieve your links, even with thousands of them, using the internal search engine, or search through tags (e.g. this Shaare is tagged with `shaarli` and `help`).
100Hashtags such as #shaarli #help are also supported.
101You can also filter the available [RSS feed](/feed/atom) and picture wall by tag or plaintext search.
52 102
53You use the community supported version of the original Shaarli project, by Sebastien Sauvage.' 103We hope that you will enjoy using Shaarli, maintained with ❤️ by the community!
104Feel free to open [an issue](https://github.com/shaarli/Shaarli/issues) if you have a suggestion or encounter an issue.
105'
54 )); 106 ));
55 $bookmark->setTagsString('opensource software'); 107 $bookmark->setTagsString('shaarli help');
56 $this->bookmarkService->add($bookmark, false); 108 $this->bookmarkService->add($bookmark, false);
57 } 109 }
58} 110}
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index 58067c99..55bb51b5 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -10,6 +10,7 @@ use Shaarli\Config\ConfigManager;
10use Shaarli\Feed\FeedBuilder; 10use Shaarli\Feed\FeedBuilder;
11use Shaarli\Formatter\FormatterFactory; 11use Shaarli\Formatter\FormatterFactory;
12use Shaarli\Front\Controller\Visitor\ErrorController; 12use Shaarli\Front\Controller\Visitor\ErrorController;
13use Shaarli\Front\Controller\Visitor\ErrorNotFoundController;
13use Shaarli\History; 14use Shaarli\History;
14use Shaarli\Http\HttpAccess; 15use Shaarli\Http\HttpAccess;
15use Shaarli\Netscape\NetscapeBookmarkUtils; 16use Shaarli\Netscape\NetscapeBookmarkUtils;
@@ -149,6 +150,9 @@ class ContainerBuilder
149 ); 150 );
150 }; 151 };
151 152
153 $container['notFoundHandler'] = function (ShaarliContainer $container): ErrorNotFoundController {
154 return new ErrorNotFoundController($container);
155 };
152 $container['errorHandler'] = function (ShaarliContainer $container): ErrorController { 156 $container['errorHandler'] = function (ShaarliContainer $container): ErrorController {
153 return new ErrorController($container); 157 return new ErrorController($container);
154 }; 158 };
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php
index 9a9a974a..66e669aa 100644
--- a/application/container/ShaarliContainer.php
+++ b/application/container/ShaarliContainer.php
@@ -24,21 +24,22 @@ use Slim\Container;
24/** 24/**
25 * Extension of Slim container to document the injected objects. 25 * Extension of Slim container to document the injected objects.
26 * 26 *
27 * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`) 27 * @property string $basePath Shaarli's instance base path (e.g. `/shaarli/`)
28 * @property BookmarkServiceInterface $bookmarkService 28 * @property BookmarkServiceInterface $bookmarkService
29 * @property CookieManager $cookieManager 29 * @property CookieManager $cookieManager
30 * @property ConfigManager $conf 30 * @property ConfigManager $conf
31 * @property mixed[] $environment $_SERVER automatically injected by Slim 31 * @property mixed[] $environment $_SERVER automatically injected by Slim
32 * @property callable $errorHandler Overrides default Slim exception display 32 * @property callable $errorHandler Overrides default Slim exception display
33 * @property FeedBuilder $feedBuilder 33 * @property FeedBuilder $feedBuilder
34 * @property FormatterFactory $formatterFactory 34 * @property FormatterFactory $formatterFactory
35 * @property History $history 35 * @property History $history
36 * @property HttpAccess $httpAccess 36 * @property HttpAccess $httpAccess
37 * @property LoginManager $loginManager 37 * @property LoginManager $loginManager
38 * @property NetscapeBookmarkUtils $netscapeBookmarkUtils 38 * @property NetscapeBookmarkUtils $netscapeBookmarkUtils
39 * @property callable $notFoundHandler Overrides default Slim exception display
39 * @property PageBuilder $pageBuilder 40 * @property PageBuilder $pageBuilder
40 * @property PageCacheManager $pageCacheManager 41 * @property PageCacheManager $pageCacheManager
41 * @property callable $phpErrorHandler Overrides default Slim PHP error display 42 * @property callable $phpErrorHandler Overrides default Slim PHP error display
42 * @property PluginManager $pluginManager 43 * @property PluginManager $pluginManager
43 * @property SessionManager $sessionManager 44 * @property SessionManager $sessionManager
44 * @property Thumbnailer $thumbnailer 45 * @property Thumbnailer $thumbnailer
diff --git a/application/front/controller/admin/PluginsController.php b/application/front/controller/admin/PluginsController.php
index 0e09116e..8e059681 100644
--- a/application/front/controller/admin/PluginsController.php
+++ b/application/front/controller/admin/PluginsController.php
@@ -62,6 +62,7 @@ class PluginsController extends ShaarliAdminController
62 62
63 if (isset($parameters['parameters_form'])) { 63 if (isset($parameters['parameters_form'])) {
64 unset($parameters['parameters_form']); 64 unset($parameters['parameters_form']);
65 unset($parameters['token']);
65 foreach ($parameters as $param => $value) { 66 foreach ($parameters as $param => $value) {
66 $this->container->conf->set('plugins.'. $param, escape($value)); 67 $this->container->conf->set('plugins.'. $param, escape($value));
67 } 68 }
diff --git a/application/front/controller/admin/ShaarliAdminController.php b/application/front/controller/admin/ShaarliAdminController.php
index 3b5939bb..c26c9cbe 100644
--- a/application/front/controller/admin/ShaarliAdminController.php
+++ b/application/front/controller/admin/ShaarliAdminController.php
@@ -4,9 +4,7 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Admin; 5namespace Shaarli\Front\Controller\Admin;
6 6
7use Shaarli\Container\ShaarliContainer;
8use Shaarli\Front\Controller\Visitor\ShaarliVisitorController; 7use Shaarli\Front\Controller\Visitor\ShaarliVisitorController;
9use Shaarli\Front\Exception\UnauthorizedException;
10use Shaarli\Front\Exception\WrongTokenException; 8use Shaarli\Front\Exception\WrongTokenException;
11use Shaarli\Security\SessionManager; 9use Shaarli\Security\SessionManager;
12use Slim\Http\Request; 10use Slim\Http\Request;
diff --git a/application/front/controller/visitor/ErrorNotFoundController.php b/application/front/controller/visitor/ErrorNotFoundController.php
new file mode 100644
index 00000000..758dd83b
--- /dev/null
+++ b/application/front/controller/visitor/ErrorNotFoundController.php
@@ -0,0 +1,29 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Visitor;
6
7use Slim\Http\Request;
8use Slim\Http\Response;
9
10/**
11 * Controller used to render the 404 error page.
12 */
13class ErrorNotFoundController extends ShaarliVisitorController
14{
15 public function __invoke(Request $request, Response $response): Response
16 {
17 // Request from the API
18 if (false !== strpos($request->getRequestTarget(), '/api/v1')) {
19 return $response->withStatus(404);
20 }
21
22 // This is required because the middleware is ignored if the route is not found.
23 $this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');
24
25 $this->assignView('error_message', t('Requested page could not be found.'));
26
27 return $response->withStatus(404)->write($this->render('404'));
28 }
29}
diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php
index f17c8ed3..cd27455b 100644
--- a/application/front/controller/visitor/ShaarliVisitorController.php
+++ b/application/front/controller/visitor/ShaarliVisitorController.php
@@ -78,16 +78,14 @@ abstract class ShaarliVisitorController
78 'footer', 78 'footer',
79 ]; 79 ];
80 80
81 $parameters = $this->buildPluginParameters($template);
82
81 foreach ($common_hooks as $name) { 83 foreach ($common_hooks as $name) {
82 $pluginData = []; 84 $pluginData = [];
83 $this->container->pluginManager->executeHooks( 85 $this->container->pluginManager->executeHooks(
84 'render_' . $name, 86 'render_' . $name,
85 $pluginData, 87 $pluginData,
86 [ 88 $parameters
87 'target' => $template,
88 'loggedin' => $this->container->loginManager->isLoggedIn(),
89 'basePath' => $this->container->basePath,
90 ]
91 ); 89 );
92 $this->assignView('plugins_' . $name, $pluginData); 90 $this->assignView('plugins_' . $name, $pluginData);
93 } 91 }
@@ -95,19 +93,23 @@ abstract class ShaarliVisitorController
95 93
96 protected function executePageHooks(string $hook, array &$data, string $template = null): void 94 protected function executePageHooks(string $hook, array &$data, string $template = null): void
97 { 95 {
98 $params = [
99 'target' => $template,
100 'loggedin' => $this->container->loginManager->isLoggedIn(),
101 'basePath' => $this->container->basePath,
102 ];
103
104 $this->container->pluginManager->executeHooks( 96 $this->container->pluginManager->executeHooks(
105 $hook, 97 $hook,
106 $data, 98 $data,
107 $params 99 $this->buildPluginParameters($template)
108 ); 100 );
109 } 101 }
110 102
103 protected function buildPluginParameters(?string $template): array
104 {
105 return [
106 'target' => $template,
107 'loggedin' => $this->container->loginManager->isLoggedIn(),
108 'basePath' => $this->container->basePath,
109 'bookmarkService' => $this->container->bookmarkService
110 ];
111 }
112
111 /** 113 /**
112 * Simple helper which prepend the base path to redirect path. 114 * Simple helper which prepend the base path to redirect path.
113 * 115 *
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php
index 2d93cb3a..1b2197c9 100644
--- a/application/plugin/PluginManager.php
+++ b/application/plugin/PluginManager.php
@@ -100,16 +100,17 @@ class PluginManager
100 */ 100 */
101 public function executeHooks($hook, &$data, $params = array()) 101 public function executeHooks($hook, &$data, $params = array())
102 { 102 {
103 if (!empty($params['target'])) { 103 $metadataParameters = [
104 $data['_PAGE_'] = $params['target']; 104 'target' => '_PAGE_',
105 } 105 'loggedin' => '_LOGGEDIN_',
106 106 'basePath' => '_BASE_PATH_',
107 if (isset($params['loggedin'])) { 107 'bookmarkService' => '_BOOKMARK_SERVICE_',
108 $data['_LOGGEDIN_'] = $params['loggedin']; 108 ];
109 } 109
110 110 foreach ($metadataParameters as $parameter => $metaKey) {
111 if (isset($params['basePath'])) { 111 if (array_key_exists($parameter, $params)) {
112 $data['_BASE_PATH_'] = $params['basePath']; 112 $data[$metaKey] = $params[$parameter];
113 }
113 } 114 }
114 115
115 foreach ($this->loadedPlugins as $plugin) { 116 foreach ($this->loadedPlugins as $plugin) {
@@ -124,6 +125,10 @@ class PluginManager
124 } 125 }
125 } 126 }
126 } 127 }
128
129 foreach ($metadataParameters as $metaKey) {
130 unset($data[$metaKey]);
131 }
127 } 132 }
128 133
129 /** 134 /**