diff options
Diffstat (limited to 'application/legacy')
-rw-r--r-- | application/legacy/LegacyController.php | 12 | ||||
-rw-r--r-- | application/legacy/LegacyRouter.php | 134 |
2 files changed, 16 insertions, 130 deletions
diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php index e16dd0f4..826604e7 100644 --- a/application/legacy/LegacyController.php +++ b/application/legacy/LegacyController.php | |||
@@ -39,13 +39,23 @@ 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()) : ''; | ||
43 | $route = '/admin/shaare'; | 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 | |||
44 | 51 | ||
45 | if (!$this->container->loginManager->isLoggedIn()) { | 52 | if (!$this->container->loginManager->isLoggedIn()) { |
53 | $parameters = $buildParameters($request->getQueryParams(), true); | ||
46 | return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters); | 54 | return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters); |
47 | } | 55 | } |
48 | 56 | ||
57 | $parameters = $buildParameters($request->getQueryParams(), false); | ||
58 | |||
49 | return $this->redirect($response, $route . $parameters); | 59 | return $this->redirect($response, $route . $parameters); |
50 | } | 60 | } |
51 | 61 | ||
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 | } |