diff --git a/controllers/RetourController.php b/controllers/RetourController.php index 8b34809..a274f8a 100644 --- a/controllers/RetourController.php +++ b/controllers/RetourController.php @@ -141,8 +141,10 @@ public function actionSaveRedirect(array $variables = array()) $record = new Retour_StaticRedirectsRecord; } + // Set the record attributes, defaulting to the existing values for whatever is missing from the post data - $record->locale = craft()->language; + + $record->locale = craft()->request->getPost('redirectLocale', craft()->language); $record->redirectMatchType = craft()->request->getPost('redirectMatchType', $record->redirectMatchType); $record->redirectSrcUrl = craft()->request->getPost('redirectSrcUrl', $record->redirectSrcUrl); if (($record->redirectMatchType == "exactmatch") && ($record->redirectSrcUrl != "")) { diff --git a/services/RetourService.php b/services/RetourService.php index fdf5872..6a51edf 100644 --- a/services/RetourService.php +++ b/services/RetourService.php @@ -203,28 +203,30 @@ public function lookupRedirect($url, $redirects) // Do a straight up match case "exactmatch": if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { - $error = $this->incrementRedirectHitCount($redirect); - RetourPlugin::log($redirectMatchType . " result: " . print_r($error, true), LogLevel::Info, false); - $this->saveRedirectToCache($url, $redirect); - - return $redirect; + if (($this->shouldMatchLocale() && $this->getLocale() == $redirect['locale']) || !$this->shouldMatchLocale()) { + $error = $this->incrementRedirectHitCount($redirect); + RetourPlugin::log($redirectMatchType . " result: " . print_r($error, true), LogLevel::Info, false); + $this->saveRedirectToCache($url, $redirect); + return $redirect; + } } break; - // Do a regex match case "regexmatch": $matchRegEx = "`" . $redirect['redirectSrcUrlParsed'] . "`i"; if (preg_match($matchRegEx, $url) === 1) { - $error = $this->incrementRedirectHitCount($redirect); - RetourPlugin::log($redirectMatchType . " result: " . print_r($error, true), LogLevel::Info, false); + if (($this->shouldMatchLocale() && $this->getLocale() == $redirect['locale']) || !$this->shouldMatchLocale()) { + $error = $this->incrementRedirectHitCount($redirect); + RetourPlugin::log($redirectMatchType . " result: " . print_r($error, true), LogLevel::Info, false); - // If we're not associated with an EntryID, handle capture group replacement - if ($redirect['associatedElementId'] == 0) { - $redirect['redirectDestUrl'] = preg_replace($matchRegEx, $redirect['redirectDestUrl'], $url); - } - $this->saveRedirectToCache($url, $redirect); + // If we're not associated with an EntryID, handle capture group replacement + if ($redirect['associatedElementId'] == 0) { + $redirect['redirectDestUrl'] = preg_replace($matchRegEx, $redirect['redirectDestUrl'], $url); + } + $this->saveRedirectToCache($url, $redirect); - return $redirect; + return $redirect; + } } break; @@ -578,5 +580,23 @@ public function getMatchesList() } return $result; + } + + /** + * @return Whether locale should be compared against + */ + function shouldMatchLocale() + { + return defined("CRAFT_LOCALE"); + } /* -- shouldMatchLocale */ + + /** + * @return Get locale + */ + function getLocale() + { + return CRAFT_LOCALE; + } /* -- getLocale */ + } diff --git a/templates/_edit.twig b/templates/_edit.twig index 257659e..679bfd6 100755 --- a/templates/_edit.twig +++ b/templates/_edit.twig @@ -123,6 +123,30 @@ value: values.redirectHttpCode, }) }} + + {% set locales = craft.i18n.getSiteLocales %} + {% if locales|length %} + {% set localeOptions = {} %} + {% for locale in locales %} + {% set localeId = locale.id %} + {% set localeName = locale.name %} + {% set localeOptions = localeOptions | merge({ (localeId) : localeName}) %} + {% endfor %} +
{{ "Select the locale for this redirect." |t |raw}}