| Conditions | 4 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | public function actionGetRedirectHash(): Response |
||
| 20 | { |
||
| 21 | $this->requireCpRequest(); |
||
| 22 | $this->requirePostRequest(); |
||
| 23 | $url = Craft::$app->getRequest()->getRequiredBodyParam('url'); |
||
| 24 | $path = \parse_url($url, PHP_URL_PATH); |
||
|
|
|||
| 25 | if (!$path) { |
||
| 26 | throw new BadRequestHttpException('Invalid URL'); |
||
| 27 | } |
||
| 28 | $segments = \array_values(\array_filter(\explode('/', $path))); |
||
| 29 | $cpTrigger = Craft::$app->getConfig()->getGeneral()->cpTrigger; |
||
| 30 | if ($segments[0] === $cpTrigger) { |
||
| 31 | \array_shift($segments); |
||
| 32 | } |
||
| 33 | $redirectTo = \implode('/', $segments); |
||
| 34 | $queryString = \parse_url($url, PHP_URL_QUERY); |
||
| 35 | if ($queryString) { |
||
| 36 | $redirectTo .= "?{$queryString}"; |
||
| 37 | } |
||
| 38 | return $this->asJson([ |
||
| 39 | 'data' => Craft::$app->getSecurity()->hashData($redirectTo), |
||
| 40 | ]); |
||
| 44 |