diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/Languages.php | 3 | ||||
-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 | ||||
-rw-r--r-- | application/front/ShaarliMiddleware.php | 2 | ||||
-rw-r--r-- | application/legacy/LegacyController.php | 32 | ||||
-rw-r--r-- | application/render/PageBuilder.php | 2 |
8 files changed, 57 insertions, 15 deletions
diff --git a/application/Languages.php b/application/Languages.php index 5cda802e..d83e0765 100644 --- a/application/Languages.php +++ b/application/Languages.php | |||
@@ -179,9 +179,10 @@ class Languages | |||
179 | { | 179 | { |
180 | return [ | 180 | return [ |
181 | 'auto' => t('Automatic'), | 181 | 'auto' => t('Automatic'), |
182 | 'de' => t('German'), | ||
182 | 'en' => t('English'), | 183 | 'en' => t('English'), |
183 | 'fr' => t('French'), | 184 | 'fr' => t('French'), |
184 | 'de' => t('German'), | 185 | 'jp' => t('Japanese'), |
185 | ]; | 186 | ]; |
186 | } | 187 | } |
187 | } | 188 | } |
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/application/front/ShaarliMiddleware.php b/application/front/ShaarliMiddleware.php index c015c0c6..d1aa1399 100644 --- a/application/front/ShaarliMiddleware.php +++ b/application/front/ShaarliMiddleware.php | |||
@@ -94,7 +94,7 @@ class ShaarliMiddleware | |||
94 | && $this->container->conf->get('privacy.force_login') | 94 | && $this->container->conf->get('privacy.force_login') |
95 | // and the current page isn't already the login page | 95 | // and the current page isn't already the login page |
96 | // and the user is not requesting a feed (which would lead to a different content-type as expected) | 96 | // and the user is not requesting a feed (which would lead to a different content-type as expected) |
97 | && !in_array($next->getName(), ['login', 'atom', 'rss'], true) | 97 | && !in_array($next->getName(), ['login', 'processLogin', 'atom', 'rss'], true) |
98 | ) { | 98 | ) { |
99 | throw new UnauthorizedException(); | 99 | throw new UnauthorizedException(); |
100 | } | 100 | } |
diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php index 26465d2c..e16dd0f4 100644 --- a/application/legacy/LegacyController.php +++ b/application/legacy/LegacyController.php | |||
@@ -40,28 +40,33 @@ class LegacyController extends ShaarliVisitorController | |||
40 | public function post(Request $request, Response $response): Response | 40 | public function post(Request $request, Response $response): Response |
41 | { | 41 | { |
42 | $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; | 42 | $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; |
43 | $route = '/admin/shaare'; | ||
43 | 44 | ||
44 | if (!$this->container->loginManager->isLoggedIn()) { | 45 | if (!$this->container->loginManager->isLoggedIn()) { |
45 | return $this->redirect($response, '/login' . $parameters); | 46 | return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters); |
46 | } | 47 | } |
47 | 48 | ||
48 | return $this->redirect($response, '/admin/shaare' . $parameters); | 49 | return $this->redirect($response, $route . $parameters); |
49 | } | 50 | } |
50 | 51 | ||
51 | /** Legacy route: ?addlink= */ | 52 | /** Legacy route: ?addlink= */ |
52 | protected function addlink(Request $request, Response $response): Response | 53 | protected function addlink(Request $request, Response $response): Response |
53 | { | 54 | { |
55 | $route = '/admin/add-shaare'; | ||
56 | |||
54 | if (!$this->container->loginManager->isLoggedIn()) { | 57 | if (!$this->container->loginManager->isLoggedIn()) { |
55 | return $this->redirect($response, '/login'); | 58 | return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route); |
56 | } | 59 | } |
57 | 60 | ||
58 | return $this->redirect($response, '/admin/add-shaare'); | 61 | return $this->redirect($response, $route); |
59 | } | 62 | } |
60 | 63 | ||
61 | /** Legacy route: ?do=login */ | 64 | /** Legacy route: ?do=login */ |
62 | protected function login(Request $request, Response $response): Response | 65 | protected function login(Request $request, Response $response): Response |
63 | { | 66 | { |
64 | return $this->redirect($response, '/login'); | 67 | $returnUrl = $request->getQueryParam('returnurl'); |
68 | |||
69 | return $this->redirect($response, '/login' . ($returnUrl ? '?returnurl=' . $returnUrl : '')); | ||
65 | } | 70 | } |
66 | 71 | ||
67 | /** Legacy route: ?do=logout */ | 72 | /** Legacy route: ?do=logout */ |
@@ -127,4 +132,21 @@ class LegacyController extends ShaarliVisitorController | |||
127 | 132 | ||
128 | return $this->redirect($response, '/feed/' . $feedType . $parameters); | 133 | return $this->redirect($response, '/feed/' . $feedType . $parameters); |
129 | } | 134 | } |
135 | |||
136 | /** Legacy route: ?do=configure */ | ||
137 | protected function configure(Request $request, Response $response): Response | ||
138 | { | ||
139 | $route = '/admin/configure'; | ||
140 | |||
141 | if (!$this->container->loginManager->isLoggedIn()) { | ||
142 | return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route); | ||
143 | } | ||
144 | |||
145 | return $this->redirect($response, $route); | ||
146 | } | ||
147 | |||
148 | protected function getBasePath(): string | ||
149 | { | ||
150 | return $this->container->basePath ?: ''; | ||
151 | } | ||
130 | } | 152 | } |
diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 7a716673..c52e3b76 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php | |||
@@ -149,6 +149,8 @@ class PageBuilder | |||
149 | 149 | ||
150 | $this->tpl->assign('formatter', $this->conf->get('formatter', 'default')); | 150 | $this->tpl->assign('formatter', $this->conf->get('formatter', 'default')); |
151 | 151 | ||
152 | $this->tpl->assign('links_per_page', $this->session['LINKS_PER_PAGE']); | ||
153 | |||
152 | // To be removed with a proper theme configuration. | 154 | // To be removed with a proper theme configuration. |
153 | $this->tpl->assign('conf', $this->conf); | 155 | $this->tpl->assign('conf', $this->conf); |
154 | } | 156 | } |