diff options
Diffstat (limited to 'application/legacy/LegacyController.php')
-rw-r--r-- | application/legacy/LegacyController.php | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php new file mode 100644 index 00000000..26465d2c --- /dev/null +++ b/application/legacy/LegacyController.php | |||
@@ -0,0 +1,130 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Legacy; | ||
6 | |||
7 | use Shaarli\Feed\FeedBuilder; | ||
8 | use Shaarli\Front\Controller\Visitor\ShaarliVisitorController; | ||
9 | use Slim\Http\Request; | ||
10 | use Slim\Http\Response; | ||
11 | |||
12 | /** | ||
13 | * We use this to maintain legacy routes, and redirect requests to the corresponding Slim route. | ||
14 | * Only public routes, and both `?addlink` and `?post` were kept here. | ||
15 | * Other routes will just display the linklist. | ||
16 | * | ||
17 | * @deprecated | ||
18 | */ | ||
19 | class LegacyController extends ShaarliVisitorController | ||
20 | { | ||
21 | /** @var string[] Both `?post` and `?addlink` do not use `?do=` format. */ | ||
22 | public const LEGACY_GET_ROUTES = [ | ||
23 | 'post', | ||
24 | 'addlink', | ||
25 | ]; | ||
26 | |||
27 | /** | ||
28 | * This method will call `$action` method, which will redirect to corresponding Slim route. | ||
29 | */ | ||
30 | public function process(Request $request, Response $response, string $action): Response | ||
31 | { | ||
32 | if (!method_exists($this, $action)) { | ||
33 | throw new UnknowLegacyRouteException(); | ||
34 | } | ||
35 | |||
36 | return $this->{$action}($request, $response); | ||
37 | } | ||
38 | |||
39 | /** Legacy route: ?post= */ | ||
40 | public function post(Request $request, Response $response): Response | ||
41 | { | ||
42 | $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; | ||
43 | |||
44 | if (!$this->container->loginManager->isLoggedIn()) { | ||
45 | return $this->redirect($response, '/login' . $parameters); | ||
46 | } | ||
47 | |||
48 | return $this->redirect($response, '/admin/shaare' . $parameters); | ||
49 | } | ||
50 | |||
51 | /** Legacy route: ?addlink= */ | ||
52 | protected function addlink(Request $request, Response $response): Response | ||
53 | { | ||
54 | if (!$this->container->loginManager->isLoggedIn()) { | ||
55 | return $this->redirect($response, '/login'); | ||
56 | } | ||
57 | |||
58 | return $this->redirect($response, '/admin/add-shaare'); | ||
59 | } | ||
60 | |||
61 | /** Legacy route: ?do=login */ | ||
62 | protected function login(Request $request, Response $response): Response | ||
63 | { | ||
64 | return $this->redirect($response, '/login'); | ||
65 | } | ||
66 | |||
67 | /** Legacy route: ?do=logout */ | ||
68 | protected function logout(Request $request, Response $response): Response | ||
69 | { | ||
70 | return $this->redirect($response, '/admin/logout'); | ||
71 | } | ||
72 | |||
73 | /** Legacy route: ?do=picwall */ | ||
74 | protected function picwall(Request $request, Response $response): Response | ||
75 | { | ||
76 | return $this->redirect($response, '/picture-wall'); | ||
77 | } | ||
78 | |||
79 | /** Legacy route: ?do=tagcloud */ | ||
80 | protected function tagcloud(Request $request, Response $response): Response | ||
81 | { | ||
82 | return $this->redirect($response, '/tags/cloud'); | ||
83 | } | ||
84 | |||
85 | /** Legacy route: ?do=taglist */ | ||
86 | protected function taglist(Request $request, Response $response): Response | ||
87 | { | ||
88 | return $this->redirect($response, '/tags/list'); | ||
89 | } | ||
90 | |||
91 | /** Legacy route: ?do=daily */ | ||
92 | protected function daily(Request $request, Response $response): Response | ||
93 | { | ||
94 | $dayParam = !empty($request->getParam('day')) ? '?day=' . escape($request->getParam('day')) : ''; | ||
95 | |||
96 | return $this->redirect($response, '/daily' . $dayParam); | ||
97 | } | ||
98 | |||
99 | /** Legacy route: ?do=rss */ | ||
100 | protected function rss(Request $request, Response $response): Response | ||
101 | { | ||
102 | return $this->feed($request, $response, FeedBuilder::$FEED_RSS); | ||
103 | } | ||
104 | |||
105 | /** Legacy route: ?do=atom */ | ||
106 | protected function atom(Request $request, Response $response): Response | ||
107 | { | ||
108 | return $this->feed($request, $response, FeedBuilder::$FEED_ATOM); | ||
109 | } | ||
110 | |||
111 | /** Legacy route: ?do=opensearch */ | ||
112 | protected function opensearch(Request $request, Response $response): Response | ||
113 | { | ||
114 | return $this->redirect($response, '/open-search'); | ||
115 | } | ||
116 | |||
117 | /** Legacy route: ?do=dailyrss */ | ||
118 | protected function dailyrss(Request $request, Response $response): Response | ||
119 | { | ||
120 | return $this->redirect($response, '/daily-rss'); | ||
121 | } | ||
122 | |||
123 | /** Legacy route: ?do=feed */ | ||
124 | protected function feed(Request $request, Response $response, string $feedType): Response | ||
125 | { | ||
126 | $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; | ||
127 | |||
128 | return $this->redirect($response, '/feed/' . $feedType . $parameters); | ||
129 | } | ||
130 | } | ||