@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | $addSlash = str_ends_with($path, '/'); |
| 66 | 66 | if (!empty($sitePath)) { |
| 67 | 67 | // Normalizes a URI path by trimming leading/ trailing slashes and removing double slashes |
| 68 | - $sitePath = '/' . preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
| 68 | + $sitePath = '/'.preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
| 69 | 69 | } |
| 70 | 70 | // Strip the $sitePath from the incoming $path |
| 71 | 71 | if (str_starts_with($path, $sitePath)) { |
| 72 | 72 | $path = substr($path, strlen($sitePath)); |
| 73 | - $path = '/' . preg_replace('/\/\/+/', '/', trim($path, '/')); |
|
| 73 | + $path = '/'.preg_replace('/\/\/+/', '/', trim($path, '/')); |
|
| 74 | 74 | } |
| 75 | - $path = $addSlash ? $path . '/' : $path; |
|
| 75 | + $path = $addSlash ? $path.'/' : $path; |
|
| 76 | 76 | |
| 77 | 77 | return $path; |
| 78 | 78 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $sitePath = parse_url($site->baseUrl, PHP_URL_PATH); |
| 91 | 91 | if (!empty($sitePath)) { |
| 92 | 92 | // Normalizes a URI path by trimming leading/ trailing slashes and removing double slashes |
| 93 | - $sitePath = '/' . preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
| 93 | + $sitePath = '/'.preg_replace('/\/\/+/', '/', trim($sitePath, '/')); |
|
| 94 | 94 | } |
| 95 | 95 | // See if the path begins with a site path prefix |
| 96 | 96 | if ($sitePath !== '/' && str_starts_with($path, $sitePath)) { |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | $overlap = 0; |
| 114 | 114 | $url = $url ?? ''; |
| 115 | 115 | $path = $path ?? ''; |
| 116 | - $url = rtrim($url, '/') . '/'; |
|
| 117 | - $path = '/' . ltrim($path, '/'); |
|
| 116 | + $url = rtrim($url, '/').'/'; |
|
| 117 | + $path = '/'.ltrim($path, '/'); |
|
| 118 | 118 | $urlOffset = strlen($url); |
| 119 | 119 | $pathLength = strlen($path); |
| 120 | 120 | $pathOffset = 0; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - return rtrim($url, '/') . '/' . ltrim(substr($path, $overlap), '/'); |
|
| 129 | + return rtrim($url, '/').'/'.ltrim(substr($path, $overlap), '/'); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | /** @noinspection CallableParameterUseCaseInTypeContextInspection */ |
| 147 | 147 | $url = preg_replace('/{.*}/', '', $url); |
| 148 | 148 | // Remove any linebreaks that may be errantly in the URL |
| 149 | - $url = (string)str_replace([ |
|
| 149 | + $url = (string) str_replace([ |
|
| 150 | 150 | PHP_EOL, |
| 151 | 151 | "\r", |
| 152 | 152 | "\n", |
@@ -280,13 +280,13 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | public function excludeUri($uri): bool |
| 282 | 282 | { |
| 283 | - $uri = '/' . ltrim($uri, '/'); |
|
| 283 | + $uri = '/'.ltrim($uri, '/'); |
|
| 284 | 284 | if (!empty(Retour::$settings->excludePatterns)) { |
| 285 | 285 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
| 286 | 286 | if (empty($excludePattern['pattern'])) { |
| 287 | 287 | continue; |
| 288 | 288 | } |
| 289 | - $pattern = '`' . $excludePattern['pattern'] . '`i'; |
|
| 289 | + $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
| 290 | 290 | try { |
| 291 | 291 | if (preg_match($pattern, $uri) === 1) { |
| 292 | 292 | Craft::info( |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | } catch (\Exception $e) { |
| 304 | 304 | // That's fine |
| 305 | - Craft::error('Invalid exclude URI Regex: ' . $pattern, __METHOD__); |
|
| 305 | + Craft::error('Invalid exclude URI Regex: '.$pattern, __METHOD__); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | } |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | * @return bool|array|null |
| 319 | 319 | */ |
| 320 | - public function findRedirectMatch(string $fullUrl, string $pathOnly, $siteId = null): bool|array|null |
|
| 320 | + public function findRedirectMatch(string $fullUrl, string $pathOnly, $siteId = null): bool | array | null |
|
| 321 | 321 | { |
| 322 | 322 | // Get the current site |
| 323 | 323 | if ($siteId === null) { |
@@ -370,10 +370,10 @@ discard block |
||
| 370 | 370 | * |
| 371 | 371 | * @return bool|array |
| 372 | 372 | */ |
| 373 | - public function getRedirectFromCache(string $url, int $siteId = 0): bool|array |
|
| 373 | + public function getRedirectFromCache(string $url, int $siteId = 0): bool | array |
|
| 374 | 374 | { |
| 375 | 375 | $cache = Craft::$app->getCache(); |
| 376 | - $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
| 376 | + $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
| 377 | 377 | $redirect = $cache->get($cacheKey); |
| 378 | 378 | Craft::info( |
| 379 | 379 | Craft::t( |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | 'id' => $redirectConfig['id'], |
| 419 | 419 | ] |
| 420 | 420 | )->execute(); |
| 421 | - Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
| 421 | + Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
| 422 | 422 | } catch (\Exception $e) { |
| 423 | 423 | Craft::error($e->getMessage(), __METHOD__); |
| 424 | 424 | } |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | } catch (SiteNotFoundException $e) { |
| 440 | 440 | $siteId = 1; |
| 441 | 441 | } |
| 442 | - $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
| 442 | + $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
| 443 | 443 | // Create the dependency tags |
| 444 | 444 | $dependency = new TagDependency([ |
| 445 | 445 | 'tags' => [ |
| 446 | 446 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
| 447 | - $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
| 447 | + $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
| 448 | 448 | ], |
| 449 | 449 | ]); |
| 450 | 450 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | foreach ($redirects as $redirect) { |
| 639 | 639 | // Figure out what type of source matching to do |
| 640 | 640 | $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
| 641 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
| 641 | + $redirectEnabled = (bool) $redirect['enabled']; |
|
| 642 | 642 | if ($redirectEnabled === true) { |
| 643 | 643 | switch ($redirectSrcMatch) { |
| 644 | 644 | case 'pathonly': |
@@ -679,12 +679,12 @@ discard block |
||
| 679 | 679 | |
| 680 | 680 | // Do a regex match |
| 681 | 681 | case 'regexmatch': |
| 682 | - $matchRegEx = '`' . $redirect['redirectSrcUrlParsed'] . '`i'; |
|
| 682 | + $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
| 683 | 683 | try { |
| 684 | 684 | if (preg_match($matchRegEx, $url) === 1) { |
| 685 | 685 | $this->incrementRedirectHitCount($redirect); |
| 686 | 686 | // If we're not associated with an EntryID, handle capture group replacement |
| 687 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
| 687 | + if ((int) $redirect['associatedElementId'] === 0) { |
|
| 688 | 688 | $redirect['redirectDestUrl'] = preg_replace( |
| 689 | 689 | $matchRegEx, |
| 690 | 690 | $redirect['redirectDestUrl'], |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | } |
| 713 | 713 | } catch (\Exception $e) { |
| 714 | 714 | // That's fine |
| 715 | - Craft::error('Invalid Redirect Regex: ' . $matchRegEx, __METHOD__); |
|
| 715 | + Craft::error('Invalid Redirect Regex: '.$matchRegEx, __METHOD__); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | break; |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | try { |
| 829 | 829 | $siteId = $redirect['siteId'] ?? null; |
| 830 | 830 | if ($siteId !== null) { |
| 831 | - $siteId = (int)$siteId; |
|
| 831 | + $siteId = (int) $siteId; |
|
| 832 | 832 | } |
| 833 | 833 | if (!UrlHelper::isAbsoluteUrl($dest) && !UrlHelper::pathHasSitePrefix($path) && Retour::$settings->resolveCraftSites) { |
| 834 | 834 | $dest = UrlHelper::siteUrl('/', null, null, $siteId); |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | try { |
| 851 | 851 | $siteId = $redirect['siteId'] ?? null; |
| 852 | 852 | if ($siteId !== null) { |
| 853 | - $siteId = (int)$siteId; |
|
| 853 | + $siteId = (int) $siteId; |
|
| 854 | 854 | } |
| 855 | 855 | $dest = UrlHelper::siteUrl($dest, null, null, $siteId); |
| 856 | 856 | } catch (\yii\base\Exception $e) { |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | // That's ok |
| 866 | 866 | } |
| 867 | 867 | if (!empty($queryString)) { |
| 868 | - $dest = strtok($dest, '?') . '?' . $queryString; |
|
| 868 | + $dest = strtok($dest, '?').'?'.$queryString; |
|
| 869 | 869 | } |
| 870 | 870 | } |
| 871 | 871 | $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
| 940 | 940 | /** @var Plugin $plugin */ |
| 941 | 941 | if (method_exists($plugin, 'retourMatch')) { |
| 942 | - $result[$plugin->getHandle()] = $plugin->name . Craft::t('retour', ' Match'); |
|
| 942 | + $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
| 943 | 943 | } |
| 944 | 944 | } |
| 945 | 945 | |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | $db = Craft::$app->getDb(); |
| 977 | 977 | // Trigger a 'beforeDeleteRedirect' event |
| 978 | 978 | $redirectConfig = $this->getRedirectById($id); |
| 979 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
| 979 | + $isNew = (int) $redirectConfig['id'] === 0; |
|
| 980 | 980 | $event = new RedirectEvent([ |
| 981 | 981 | 'isNew' => $isNew, |
| 982 | 982 | 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | // Get the validated model attributes and save them to the db |
| 1141 | 1141 | $redirectConfig = $redirect->getAttributes(); |
| 1142 | 1142 | // 0 for a siteId needs to be converted to null |
| 1143 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
| 1143 | + if (empty($redirectConfig['siteId']) || (int) $redirectConfig['siteId'] === 0) { |
|
| 1144 | 1144 | $redirectConfig['siteId'] = null; |
| 1145 | 1145 | } |
| 1146 | 1146 | // Throw an event to before saving the redirect |
@@ -1150,7 +1150,7 @@ discard block |
||
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | // See if a redirect exists with this source URL already |
| 1153 | - if ((int)$redirectConfig['id'] === 0) { |
|
| 1153 | + if ((int) $redirectConfig['id'] === 0) { |
|
| 1154 | 1154 | // Query the db table |
| 1155 | 1155 | $redirect = (new Query()) |
| 1156 | 1156 | ->from(['{{%retour_static_redirects}}']) |
@@ -1163,7 +1163,7 @@ discard block |
||
| 1163 | 1163 | } |
| 1164 | 1164 | } |
| 1165 | 1165 | // Trigger a 'beforeSaveRedirect' event |
| 1166 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
| 1166 | + $isNew = (int) $redirectConfig['id'] === 0; |
|
| 1167 | 1167 | $event = new RedirectEvent([ |
| 1168 | 1168 | 'isNew' => $isNew, |
| 1169 | 1169 | 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * @inerhitdoc |
| 70 | 70 | */ |
| 71 | - protected array|bool|int $allowAnonymous = [ |
|
| 71 | + protected array | bool | int $allowAnonymous = [ |
|
| 72 | 72 | ]; |
| 73 | 73 | |
| 74 | 74 | // Public Methods |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | ->orderBy([$sortField => $sortType]) |
| 124 | 124 | ->filterWhere(['like', 'redirectSrcUrl', $filter]) |
| 125 | 125 | ->orFilterWhere(['like', 'referrerUrl', $filter]); |
| 126 | - if ((int)$siteId !== 0) { |
|
| 126 | + if ((int) $siteId !== 0) { |
|
| 127 | 127 | $query->andWhere(['siteId' => $siteId]); |
| 128 | 128 | } |
| 129 | 129 | if ($handled !== 'all') { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | $stat['addLink'] = ''; |
| 146 | 146 | if (!$stat['handledByRetour']) { |
| 147 | - $encodedUrl = urlencode('/' . ltrim($stat['redirectSrcUrl'], '/')); |
|
| 147 | + $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/')); |
|
| 148 | 148 | // Add the siteId to the URL, but keep the current behavior of passing in siteId=0 for "all" |
| 149 | 149 | $statSiteId = $stat['siteId'] ?? 0; |
| 150 | 150 | try { |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } catch (SiteNotFoundException $e) { |
| 153 | 153 | $primarySite = null; |
| 154 | 154 | } |
| 155 | - if ($primarySite !== null && $statSiteId == (int)$primarySite->id) { |
|
| 155 | + if ($primarySite !== null && $statSiteId == (int) $primarySite->id) { |
|
| 156 | 156 | $statSiteId = 0; |
| 157 | 157 | } |
| 158 | 158 | $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [ |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | ->orderBy([$sortField => $sortType]) |
| 228 | 228 | ->filterWhere(['like', 'redirectSrcUrl', $filter]) |
| 229 | 229 | ->orFilterWhere(['like', 'redirectDestUrl', $filter]); |
| 230 | - if ((int)$siteId !== 0) { |
|
| 230 | + if ((int) $siteId !== 0) { |
|
| 231 | 231 | $query->andWhere(['siteId' => $siteId]); |
| 232 | 232 | } |
| 233 | 233 | if ($shortLinks) { |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | $redirect['siteBaseUrl'] = $site->getBaseUrl(); |
| 276 | 276 | |
| 277 | - $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect['id']); |
|
| 277 | + $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']); |
|
| 278 | 278 | } |
| 279 | 279 | // Format the data for the API |
| 280 | 280 | if ($redirects) { |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | // Protected Properties |
| 47 | 47 | // ========================================================================= |
| 48 | 48 | |
| 49 | - protected array|bool|int $allowAnonymous = []; |
|
| 49 | + protected array | bool | int $allowAnonymous = []; |
|
| 50 | 50 | |
| 51 | 51 | // Public Methods |
| 52 | 52 | // ========================================================================= |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $variables['docsUrl'] = self::DOCUMENTATION_URL; |
| 89 | 89 | $variables['pluginName'] = $pluginName; |
| 90 | 90 | $variables['title'] = $templateTitle; |
| 91 | - $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
| 91 | + $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
| 92 | 92 | $variables['crumbs'] = [ |
| 93 | 93 | [ |
| 94 | 94 | 'label' => $pluginName, |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | ], |
| 97 | 97 | [ |
| 98 | 98 | 'label' => $templateTitle, |
| 99 | - 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
| 99 | + 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
| 100 | 100 | ], |
| 101 | 101 | ]; |
| 102 | 102 | $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
@@ -156,13 +156,13 @@ discard block |
||
| 156 | 156 | if ($redirect->siteId) { |
| 157 | 157 | $site = $sites->getSiteById($redirect->siteId); |
| 158 | 158 | if ($site) { |
| 159 | - MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
| 159 | + MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | if ($siteId) { |
| 163 | 163 | $site = $sites->getSiteById($siteId); |
| 164 | 164 | if ($site) { |
| 165 | - MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
| 165 | + MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | $pluginName = Retour::$settings->pluginName; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | ], |
| 199 | 199 | [ |
| 200 | 200 | 'label' => $templateTitle, |
| 201 | - 'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId), |
|
| 201 | + 'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId), |
|
| 202 | 202 | ], |
| 203 | 203 | ]; |
| 204 | 204 | $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | if ($redirectConfig === null) { |
| 255 | 255 | throw new NotFoundHttpException('Redirect not found'); |
| 256 | 256 | } |
| 257 | - $redirectConfig['id'] = (int)$redirectConfig['id']; |
|
| 257 | + $redirectConfig['id'] = (int) $redirectConfig['id']; |
|
| 258 | 258 | // Handle enforcing trailing slashes |
| 259 | 259 | $generalConfig = Craft::$app->getConfig()->getGeneral(); |
| 260 | 260 | if ($generalConfig->addTrailingSlashesToUrls && $redirectConfig['redirectMatchType'] === 'exactmatch') { |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $variables['docsUrl'] = self::DOCUMENTATION_URL; |
| 343 | 343 | $variables['pluginName'] = $pluginName; |
| 344 | 344 | $variables['title'] = $templateTitle; |
| 345 | - $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
| 345 | + $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
| 346 | 346 | $variables['crumbs'] = [ |
| 347 | 347 | [ |
| 348 | 348 | 'label' => $pluginName, |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | ], |
| 351 | 351 | [ |
| 352 | 352 | 'label' => $templateTitle, |
| 353 | - 'url' => UrlHelper::cpUrl('retour/shortlinks' . $siteHandleUri), |
|
| 353 | + 'url' => UrlHelper::cpUrl('retour/shortlinks'.$siteHandleUri), |
|
| 354 | 354 | ], |
| 355 | 355 | ]; |
| 356 | 356 | $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
@@ -409,13 +409,13 @@ discard block |
||
| 409 | 409 | if (!preg_match('/\.[^\/]+$/', $url) && strpos($url, '?') === false && strpos($url, '#') === false) { |
| 410 | 410 | // If it's a root relative URL, assume it's a site URL |
| 411 | 411 | if (UrlHelper::isRootRelativeUrl($url)) { |
| 412 | - return rtrim($url, '/') . '/'; |
|
| 412 | + return rtrim($url, '/').'/'; |
|
| 413 | 413 | } |
| 414 | 414 | // If the URL matches any of the site's base URLs, assume it's a site URL |
| 415 | 415 | $sites = Craft::$app->getSites()->getAllSites(); |
| 416 | 416 | foreach ($sites as $site) { |
| 417 | 417 | if (strpos($url, $site->getBaseUrl()) === 0) { |
| 418 | - return rtrim($url, '/') . '/'; |
|
| 418 | + return rtrim($url, '/').'/'; |
|
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | } |