From 4280d4960b623b8c1c9836b831360bd044090ba5 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 5 Feb 2018 16:23:46 +0100 Subject: [PATCH] Keep params when redirect on mobile --- controllers/CategoryController.php | 17 +++++++++---- override/classes/FrontController.php | 36 +++++++++++++++------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/controllers/CategoryController.php b/controllers/CategoryController.php index 4fa3b2cc..e4ef4254 100755 --- a/controllers/CategoryController.php +++ b/controllers/CategoryController.php @@ -59,10 +59,19 @@ class CategoryControllerCore extends FrontController $currentURL = preg_replace('/[?&].*$/', '', self::$link->getCategoryLink($this->category)); if (!preg_match('/^'.Tools::pRegexp($currentURL, '/').'([&?].*)?$/', Tools::getProtocol().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { + $params = ''; + $excludedKey = array('isolang', 'id_lang', 'id_category'); + foreach($_GET as $key => $value) { + if(!in_array($key, $excludedKey)) { + $params .= ($params == '' ? '?' : '&').$key.'='.$value; + } + } + echo "coucou : ".$currentURL.$params; exit; + if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ ) { + die('[Debug] This page has moved
Please use the following URL instead: '.$currentURL.$params.''); + } header('HTTP/1.0 301 Moved'); - if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ ) - die('[Debug] This page has moved
Please use the following URL instead: '.$currentURL.''); - Tools::redirectLink($currentURL); + Tools::redirectLink($currentURL.$params); } } } @@ -118,7 +127,7 @@ class CategoryControllerCore extends FrontController $this->category->description = nl2br2($this->category->description); $subCategories = $this->category->getSubCategories((int)self::$cookie->id_lang); - self::$smarty->assign('category', $this->category); + self::$smarty->assign('category', $this->category); if (isset($subCategories) AND !empty($subCategories) AND $subCategories) { diff --git a/override/classes/FrontController.php b/override/classes/FrontController.php index d1d47330..dd353c78 100755 --- a/override/classes/FrontController.php +++ b/override/classes/FrontController.php @@ -1,6 +1,8 @@ setMedia(); } - protected function canonicalRedirection() { + protected function canonicalRedirection() + { global $link, $cookie; if(Configuration::get('PS_CANONICAL_REDIRECT')) { @@ -343,7 +347,6 @@ class FrontController extends FrontControllerCore { // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain $canonicalURL = $link->getPageLink($this->php_self, $this->ssl, $cookie->id_lang); if(!Tools::getValue('ajax') && !preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/', (($_SERVER['SERVER_PORT'] == _PS_SSL_PORT_ || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == '443') || Configuration::get('PS_SSL_ENABLED'))? 'https://': 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { - header('HTTP/1.0 301 Moved'); $params = ''; $excludedKey = array('isolang', 'id_lang'); foreach($_GET as $key => $value) { @@ -354,17 +357,15 @@ class FrontController extends FrontControllerCore { if(defined('_PS_MODE_DEV_') && _PS_MODE_DEV_ && $_SERVER['REQUEST_URI'] != __PS_BASE_URI__) { die('[Debug] This page has moved
Please use the following URL instead: '.$canonicalURL.$params.''); } + header('HTTP/1.0 301 Moved'); Tools::redirectLink($canonicalURL.$params); } } } } - public function preProcess() { -/* ini_set('display_errors', 'on'); - $cmd = 'cd '._PS_ROOT_DIR_.'/themes/site/css/ && /home/www/bebeboutik.com/node_modules/less/bin/lessc --line-numbers=all style.less > style.css'; - exec($cmd);*/ - + public function preProcess() + { global $page_name, $cookie; if(!isset($this->php_self)) { @@ -470,22 +471,23 @@ class FrontController extends FrontControllerCore { parent::preProcess(); } - public function setMedia() { + public function setMedia() + { global $cookie; Tools::addCSS(_THEME_CSS_DIR_.'style.css?v=31'); Tools::addJS(array(Tools::getShopDomain(true)._PS_JS_DIR_.'scripts.js')); - if(Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))) { + if (Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))) { Tools::addJS(array( - Tools::getShopDomain(true)._PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js', - Tools::getShopDomain(true)._PS_JS_DIR_.'jquery/jquery.fancybox-1.3.4.js', - Tools::getShopDomain(true)._PS_JS_DIR_.'hookLiveEdit.js') - ); + Tools::getShopDomain(true)._PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js', + Tools::getShopDomain(true)._PS_JS_DIR_.'jquery/jquery.fancybox-1.3.4.js', + Tools::getShopDomain(true)._PS_JS_DIR_.'hookLiveEdit.js') + ); Tools::addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css'); } $language = new Language($cookie->id_lang); - if($language->is_rtl) { + if ($language->is_rtl) { Tools::addCSS(_THEME_CSS_DIR_.'rtl.css'); } }