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}}

+
+ {{ forms.selectField({ + fieldClass: 'nomarginfield', + class: 'selectField', + id: "redirectLocale", + options: localeOptions, + name: "redirectLocale", + value: values.locale, + }) }} +
+ {% endif %} diff --git a/templates/redirects.twig b/templates/redirects.twig index 52cbfc5..569c97d 100755 --- a/templates/redirects.twig +++ b/templates/redirects.twig @@ -58,7 +58,8 @@ {{ "Legacy URL Pattern"|t }} {{ "Redirect To"|t }} - {{ "Pattern Match Type"|t }} + {{ "Locale"|t }} + {{ "Pattern Match Type"|t }} {{ "Redirect Type"|t }} {{ "Hits"|t }} {{ "Last Hit"|t }} @@ -70,6 +71,7 @@ {{ redir.redirectSrcUrl }} {{ redir.redirectDestUrl }} + {{ redir.locale }} {{ matchesList[redir.redirectMatchType] }} {{ redir.redirectHttpCode }} {{ redir.hitCount }} @@ -98,7 +100,8 @@ {{ "Legacy URL Pattern"|t }} {{ "Redirect To"|t }} - {{ "Pattern Match Type"|t }} + {{ "Locale"|t }} + {{ "Pattern Match Type"|t }} {{ "Redirect Type"|t }} {{ "Hits"|t }} {{ "Last Hit"|t }} @@ -111,6 +114,7 @@ {{ redir.redirectSrcUrl }} {{ redir.redirectDestUrl }} + {{ redir.locale }} {{ matchesList[redir.redirectMatchType] }} {{ redir.redirectHttpCode }} {{ redir.hitCount }} @@ -144,7 +148,7 @@ $('#static-redirects').dataTable({ "sDom": '<"top"ilpf<"clear">>rt<"bottom"ilp<"clear">>', "sPaginationType": "full_numbers", "aaSorting": [[ 4, "desc" ]], - "aoColumns": [ null, null, null, { "sType": "num" }, { "sType": "num" }, { "sType": "date" }, null], + "aoColumns": [ null, null, null, null, { "sType": "num" }, { "sType": "num" }, { "sType": "date" }, null], "bLengthChange": false, "iDisplayLength": 20, "bInfo": true, @@ -173,7 +177,7 @@ $('#entry-redirects').dataTable({ "sDom": '<"top"ilpf<"clear">>rt<"bottom"ilp<"clear">>', "sPaginationType": "full_numbers", "aaSorting": [[ 4, "desc" ]], - "aoColumns": [ null, null, null, { "sType": "num" }, { "sType": "num" }, { "sType": "date" }], + "aoColumns": [ null, null, null, null, { "sType": "num" }, { "sType": "num" }, { "sType": "date" }], "bLengthChange": false, "iDisplayLength": 20, "bInfo": true,