Conditions | 7 |
Paths | 9 |
Total Lines | 23 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function actionGetRedirectHash(): string |
||
22 | { |
||
23 | $this->requireCpRequest(); |
||
24 | $this->requirePostRequest(); |
||
25 | $url = $this->request->getRequiredBodyParam('url'); |
||
26 | if (!$url || !is_string($url) || !$path = parse_url($url, PHP_URL_PATH)) { |
||
27 | throw new BadRequestHttpException('Bad URL parameter'); |
||
28 | } |
||
29 | $segments = array_values(array_filter(explode('/', $path))); |
||
30 | $cpTrigger = Craft::$app->getConfig()->getGeneral()->cpTrigger; |
||
31 | if ($segments[0] === $cpTrigger) { |
||
32 | array_shift($segments); |
||
33 | } |
||
34 | $redirectTo = implode('/', $segments); |
||
35 | $queryString = parse_url($url, PHP_URL_QUERY); |
||
36 | if ($queryString) { |
||
37 | $redirectTo .= "?{$queryString}"; |
||
38 | } |
||
39 | $hashbang = parse_url($url, PHP_URL_FRAGMENT); |
||
40 | if ($hashbang) { |
||
41 | $redirectTo .= "#{$hashbang}"; |
||
42 | } |
||
43 | return CpFieldInspectHelper::getRedirectUrl($redirectTo); |
||
44 | } |
||
47 |