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/front/controller/visitor/FeedController.php | 4 | ||||
-rw-r--r-- | application/legacy/LegacyController.php | 44 | ||||
-rw-r--r-- | application/legacy/LegacyRouter.php | 134 | ||||
-rw-r--r-- | application/render/PageBuilder.php | 2 |
10 files changed, 75 insertions, 147 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/front/controller/visitor/FeedController.php b/application/front/controller/visitor/FeedController.php index da2848c2..8d8b546a 100644 --- a/application/front/controller/visitor/FeedController.php +++ b/application/front/controller/visitor/FeedController.php | |||
@@ -46,10 +46,10 @@ class FeedController extends ShaarliVisitorController | |||
46 | 46 | ||
47 | $data = $this->container->feedBuilder->buildData($feedType, $request->getParams()); | 47 | $data = $this->container->feedBuilder->buildData($feedType, $request->getParams()); |
48 | 48 | ||
49 | $this->executePageHooks('render_feed', $data, $feedType); | 49 | $this->executePageHooks('render_feed', $data, 'feed.' . $feedType); |
50 | $this->assignAllView($data); | 50 | $this->assignAllView($data); |
51 | 51 | ||
52 | $content = $this->render('feed.'. $feedType); | 52 | $content = $this->render('feed.' . $feedType); |
53 | 53 | ||
54 | $cache->cache($content); | 54 | $cache->cache($content); |
55 | 55 | ||
diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php index 26465d2c..826604e7 100644 --- a/application/legacy/LegacyController.php +++ b/application/legacy/LegacyController.php | |||
@@ -39,29 +39,44 @@ class LegacyController extends ShaarliVisitorController | |||
39 | /** Legacy route: ?post= */ | 39 | /** Legacy route: ?post= */ |
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 | $route = '/admin/shaare'; |
43 | $buildParameters = function (?array $parameters, bool $encode) { | ||
44 | if ($encode) { | ||
45 | $parameters = array_map('urlencode', $parameters); | ||
46 | } | ||
47 | |||
48 | return count($parameters) > 0 ? '?' . http_build_query($parameters) : ''; | ||
49 | }; | ||
50 | |||
43 | 51 | ||
44 | if (!$this->container->loginManager->isLoggedIn()) { | 52 | if (!$this->container->loginManager->isLoggedIn()) { |
45 | return $this->redirect($response, '/login' . $parameters); | 53 | $parameters = $buildParameters($request->getQueryParams(), true); |
54 | return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters); | ||
46 | } | 55 | } |
47 | 56 | ||
48 | return $this->redirect($response, '/admin/shaare' . $parameters); | 57 | $parameters = $buildParameters($request->getQueryParams(), false); |
58 | |||
59 | return $this->redirect($response, $route . $parameters); | ||
49 | } | 60 | } |
50 | 61 | ||
51 | /** Legacy route: ?addlink= */ | 62 | /** Legacy route: ?addlink= */ |
52 | protected function addlink(Request $request, Response $response): Response | 63 | protected function addlink(Request $request, Response $response): Response |
53 | { | 64 | { |
65 | $route = '/admin/add-shaare'; | ||
66 | |||
54 | if (!$this->container->loginManager->isLoggedIn()) { | 67 | if (!$this->container->loginManager->isLoggedIn()) { |
55 | return $this->redirect($response, '/login'); | 68 | return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route); |
56 | } | 69 | } |
57 | 70 | ||
58 | return $this->redirect($response, '/admin/add-shaare'); | 71 | return $this->redirect($response, $route); |
59 | } | 72 | } |
60 | 73 | ||
61 | /** Legacy route: ?do=login */ | 74 | /** Legacy route: ?do=login */ |
62 | protected function login(Request $request, Response $response): Response | 75 | protected function login(Request $request, Response $response): Response |
63 | { | 76 | { |
64 | return $this->redirect($response, '/login'); | 77 | $returnUrl = $request->getQueryParam('returnurl'); |
78 | |||
79 | return $this->redirect($response, '/login' . ($returnUrl ? '?returnurl=' . $returnUrl : '')); | ||
65 | } | 80 | } |
66 | 81 | ||
67 | /** Legacy route: ?do=logout */ | 82 | /** Legacy route: ?do=logout */ |
@@ -127,4 +142,21 @@ class LegacyController extends ShaarliVisitorController | |||
127 | 142 | ||
128 | return $this->redirect($response, '/feed/' . $feedType . $parameters); | 143 | return $this->redirect($response, '/feed/' . $feedType . $parameters); |
129 | } | 144 | } |
145 | |||
146 | /** Legacy route: ?do=configure */ | ||
147 | protected function configure(Request $request, Response $response): Response | ||
148 | { | ||
149 | $route = '/admin/configure'; | ||
150 | |||
151 | if (!$this->container->loginManager->isLoggedIn()) { | ||
152 | return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route); | ||
153 | } | ||
154 | |||
155 | return $this->redirect($response, $route); | ||
156 | } | ||
157 | |||
158 | protected function getBasePath(): string | ||
159 | { | ||
160 | return $this->container->basePath ?: ''; | ||
161 | } | ||
130 | } | 162 | } |
diff --git a/application/legacy/LegacyRouter.php b/application/legacy/LegacyRouter.php index cea99154..0449c7e1 100644 --- a/application/legacy/LegacyRouter.php +++ b/application/legacy/LegacyRouter.php | |||
@@ -17,15 +17,15 @@ class LegacyRouter | |||
17 | 17 | ||
18 | public static $PAGE_PICWALL = 'picwall'; | 18 | public static $PAGE_PICWALL = 'picwall'; |
19 | 19 | ||
20 | public static $PAGE_TAGCLOUD = 'tagcloud'; | 20 | public static $PAGE_TAGCLOUD = 'tag.cloud'; |
21 | 21 | ||
22 | public static $PAGE_TAGLIST = 'taglist'; | 22 | public static $PAGE_TAGLIST = 'tag.list'; |
23 | 23 | ||
24 | public static $PAGE_DAILY = 'daily'; | 24 | public static $PAGE_DAILY = 'daily'; |
25 | 25 | ||
26 | public static $PAGE_FEED_ATOM = 'atom'; | 26 | public static $PAGE_FEED_ATOM = 'feed.atom'; |
27 | 27 | ||
28 | public static $PAGE_FEED_RSS = 'rss'; | 28 | public static $PAGE_FEED_RSS = 'feed.rss'; |
29 | 29 | ||
30 | public static $PAGE_TOOLS = 'tools'; | 30 | public static $PAGE_TOOLS = 'tools'; |
31 | 31 | ||
@@ -37,7 +37,7 @@ class LegacyRouter | |||
37 | 37 | ||
38 | public static $PAGE_ADDLINK = 'addlink'; | 38 | public static $PAGE_ADDLINK = 'addlink'; |
39 | 39 | ||
40 | public static $PAGE_EDITLINK = 'edit_link'; | 40 | public static $PAGE_EDITLINK = 'editlink'; |
41 | 41 | ||
42 | public static $PAGE_DELETELINK = 'delete_link'; | 42 | public static $PAGE_DELETELINK = 'delete_link'; |
43 | 43 | ||
@@ -60,128 +60,4 @@ class LegacyRouter | |||
60 | public static $PAGE_THUMBS_UPDATE = 'thumbs_update'; | 60 | public static $PAGE_THUMBS_UPDATE = 'thumbs_update'; |
61 | 61 | ||
62 | public static $GET_TOKEN = 'token'; | 62 | public static $GET_TOKEN = 'token'; |
63 | |||
64 | /** | ||
65 | * Reproducing renderPage() if hell, to avoid regression. | ||
66 | * | ||
67 | * This highlights how bad this needs to be rewrite, | ||
68 | * but let's focus on plugins for now. | ||
69 | * | ||
70 | * @param string $query $_SERVER['QUERY_STRING']. | ||
71 | * @param array $get $_SERVER['GET']. | ||
72 | * @param bool $loggedIn true if authenticated user. | ||
73 | * | ||
74 | * @return string page found. | ||
75 | */ | ||
76 | public static function findPage($query, $get, $loggedIn) | ||
77 | { | ||
78 | $loggedIn = ($loggedIn === true) ? true : false; | ||
79 | |||
80 | if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) { | ||
81 | return self::$PAGE_LINKLIST; | ||
82 | } | ||
83 | |||
84 | if (startsWith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) { | ||
85 | return self::$PAGE_LOGIN; | ||
86 | } | ||
87 | |||
88 | if (startsWith($query, 'do=' . self::$PAGE_PICWALL)) { | ||
89 | return self::$PAGE_PICWALL; | ||
90 | } | ||
91 | |||
92 | if (startsWith($query, 'do=' . self::$PAGE_TAGCLOUD)) { | ||
93 | return self::$PAGE_TAGCLOUD; | ||
94 | } | ||
95 | |||
96 | if (startsWith($query, 'do=' . self::$PAGE_TAGLIST)) { | ||
97 | return self::$PAGE_TAGLIST; | ||
98 | } | ||
99 | |||
100 | if (startsWith($query, 'do=' . self::$PAGE_OPENSEARCH)) { | ||
101 | return self::$PAGE_OPENSEARCH; | ||
102 | } | ||
103 | |||
104 | if (startsWith($query, 'do=' . self::$PAGE_DAILY)) { | ||
105 | return self::$PAGE_DAILY; | ||
106 | } | ||
107 | |||
108 | if (startsWith($query, 'do=' . self::$PAGE_FEED_ATOM)) { | ||
109 | return self::$PAGE_FEED_ATOM; | ||
110 | } | ||
111 | |||
112 | if (startsWith($query, 'do=' . self::$PAGE_FEED_RSS)) { | ||
113 | return self::$PAGE_FEED_RSS; | ||
114 | } | ||
115 | |||
116 | if (startsWith($query, 'do=' . self::$PAGE_THUMBS_UPDATE)) { | ||
117 | return self::$PAGE_THUMBS_UPDATE; | ||
118 | } | ||
119 | |||
120 | if (startsWith($query, 'do=' . self::$AJAX_THUMB_UPDATE)) { | ||
121 | return self::$AJAX_THUMB_UPDATE; | ||
122 | } | ||
123 | |||
124 | // At this point, only loggedin pages. | ||
125 | if (!$loggedIn) { | ||
126 | return self::$PAGE_LINKLIST; | ||
127 | } | ||
128 | |||
129 | if (startsWith($query, 'do=' . self::$PAGE_TOOLS)) { | ||
130 | return self::$PAGE_TOOLS; | ||
131 | } | ||
132 | |||
133 | if (startsWith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) { | ||
134 | return self::$PAGE_CHANGEPASSWORD; | ||
135 | } | ||
136 | |||
137 | if (startsWith($query, 'do=' . self::$PAGE_CONFIGURE)) { | ||
138 | return self::$PAGE_CONFIGURE; | ||
139 | } | ||
140 | |||
141 | if (startsWith($query, 'do=' . self::$PAGE_CHANGETAG)) { | ||
142 | return self::$PAGE_CHANGETAG; | ||
143 | } | ||
144 | |||
145 | if (startsWith($query, 'do=' . self::$PAGE_ADDLINK)) { | ||
146 | return self::$PAGE_ADDLINK; | ||
147 | } | ||
148 | |||
149 | if (isset($get['edit_link']) || isset($get['post'])) { | ||
150 | return self::$PAGE_EDITLINK; | ||
151 | } | ||
152 | |||
153 | if (isset($get['delete_link'])) { | ||
154 | return self::$PAGE_DELETELINK; | ||
155 | } | ||
156 | |||
157 | if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) { | ||
158 | return self::$PAGE_CHANGE_VISIBILITY; | ||
159 | } | ||
160 | |||
161 | if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) { | ||
162 | return self::$PAGE_PINLINK; | ||
163 | } | ||
164 | |||
165 | if (startsWith($query, 'do=' . self::$PAGE_EXPORT)) { | ||
166 | return self::$PAGE_EXPORT; | ||
167 | } | ||
168 | |||
169 | if (startsWith($query, 'do=' . self::$PAGE_IMPORT)) { | ||
170 | return self::$PAGE_IMPORT; | ||
171 | } | ||
172 | |||
173 | if (startsWith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) { | ||
174 | return self::$PAGE_PLUGINSADMIN; | ||
175 | } | ||
176 | |||
177 | if (startsWith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) { | ||
178 | return self::$PAGE_SAVE_PLUGINSADMIN; | ||
179 | } | ||
180 | |||
181 | if (startsWith($query, 'do=' . self::$GET_TOKEN)) { | ||
182 | return self::$GET_TOKEN; | ||
183 | } | ||
184 | |||
185 | return self::$PAGE_LINKLIST; | ||
186 | } | ||
187 | } | 63 | } |
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 | } |