From c4127be37d992a60ceef46997e27f0aa190397ed Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 20 Aug 2015 15:17:11 +0200 Subject: [PATCH] Re-added language checks in the controller redirect function. Ensures Grav admin always has the correct language set in the links (otherwise it's not happening). Bring back some lines removed in 8e814e30ada00c871b9afde48a900d0547f3f8eb --- classes/controller.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/classes/controller.php b/classes/controller.php index ee3f7347..d73b5818 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -119,21 +119,23 @@ class AdminController $base = $this->admin->base; - $this->redirect = '/' . ltrim($this->redirect, '/'); - - if (!Utils::startsWith($this->redirect, $base)) { - $this->redirect = $base . $this->redirect; + // if base path does not already contain the lang code, add it + $langPrefix = '/' . $this->grav['session']->admin_lang; + if (!Utils::startsWith($base, $langPrefix . '/')) { + $base = $langPrefix . $base; } - $this->grav->redirect($this->redirect, $this->redirectCode); + // now the first 4 chars of base contain the lang code. + // if redirect path already contains the lang code, and is != than the base lang code, then use redirect path as-is + if (substr($base, 0, 4) != substr($this->redirect, 0, 4)) { + $languages_enabled = $this->grav['config']->get('system.languages.supported', []); + if (in_array(substr($this->redirect, 1, 2), $languages_enabled)) { + $this->grav->redirect($this->redirect); + } + } -// if ($base[3] !== '/') { -// $base = '/' . $this->grav['session']->admin_lang . $base; -// } - -// $path = trim(substr($this->redirect, 0, strlen($base)) == $base ? substr($this->redirect, strlen($base)) : $this->redirect, '/'); - -// $this->grav->redirect($base . '/' . preg_replace('|/+|', '/', $path), $this->redirectCode); + $path = trim(substr($this->redirect, 0, strlen($base)) == $base ? substr($this->redirect, strlen($base)) : $this->redirect, '/'); + $this->grav->redirect($base . '/' . preg_replace('|/+|', '/', $path), $this->redirectCode); } /**