From f097d90558372e24d65d4d16b97ac69f0acb4c61 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Wed, 4 Mar 2015 14:20:05 +0700 Subject: [PATCH 1/7] fix missing .html when matching products --- cleanurls/override/classes/Dispatcher.php | 4 ++-- cleanurls/override/controllers/front/ProductController.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cleanurls/override/classes/Dispatcher.php b/cleanurls/override/classes/Dispatcher.php index 77b6ca1..fdbb6ba 100644 --- a/cleanurls/override/classes/Dispatcher.php +++ b/cleanurls/override/classes/Dispatcher.php @@ -113,7 +113,7 @@ public static function isProductLink($short_link) $sql = 'SELECT `id_product` FROM `'._DB_PREFIX_.'product_lang` - WHERE `link_rewrite` = \''.$explode_product_link[$count-1].'\' AND `id_lang` = '. Context::getContext()->language->id; + WHERE (`link_rewrite` = \''.$explode_product_link[$count-1].'\' OR `link_rewrite` = \''.str_replace(".html", "",$explode_product_link[$count-1]).'\') AND `id_lang` = '. Context::getContext()->language->id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { @@ -400,4 +400,4 @@ public function getController($id_shop = null) $_GET['controller'] = $this->controller; return $this->controller; } -} \ No newline at end of file +} diff --git a/cleanurls/override/controllers/front/ProductController.php b/cleanurls/override/controllers/front/ProductController.php index 17e4dea..6fe0825 100644 --- a/cleanurls/override/controllers/front/ProductController.php +++ b/cleanurls/override/controllers/front/ProductController.php @@ -12,7 +12,7 @@ public function init() $sql = 'SELECT `id_product` FROM `'._DB_PREFIX_.'product_lang` - WHERE `link_rewrite` = \''.$rewrite_url.'\' AND `id_lang` = '. Context::getContext()->language->id; + WHERE (`link_rewrite` = \''.$rewrite_url.'\' OR `link_rewrite` = \''.str_replace(".html", "",$rewrite_url).'\') AND `id_lang` = '. Context::getContext()->language->id; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { From c4b696fc9a32c322ea4ec3c0d0b3668439b2bd3a Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Wed, 4 Mar 2015 14:20:47 +0700 Subject: [PATCH 2/7] Add redirects from old id- formats --- cleanurls/override/classes/Dispatcher.php | 102 +++++++++++++++++++--- 1 file changed, 91 insertions(+), 11 deletions(-) diff --git a/cleanurls/override/classes/Dispatcher.php b/cleanurls/override/classes/Dispatcher.php index fdbb6ba..561bf7f 100644 --- a/cleanurls/override/classes/Dispatcher.php +++ b/cleanurls/override/classes/Dispatcher.php @@ -117,11 +117,26 @@ public static function isProductLink($short_link) if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { - $sql .= ' AND `id_shop` = '.(int)Shop::getContextShopID(); + $sql2 = ' AND `id_shop` = '.(int)Shop::getContextShopID(); } - $id_product = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); - + $id_product = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + + if(!$id_product){ + $split = explode("-", $explode_product_link[$count-1], 2); + if(count($split) == 2 && is_numeric($split[0])){ + $sql = 'SELECT `id_product` + FROM `'._DB_PREFIX_.'product_lang` + WHERE (`link_rewrite` = \''.$split[1].'\' OR `link_rewrite` = \''.str_replace(".html", "",$split[1]).'\') + AND `id_product` = "'.$split[0].'" AND `id_lang` = '. Context::getContext()->language->id; + $redirect = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + if($redirect){ + $url = (($_SERVER['HTTPS'])?"https://":"http://") . $_SERVER['HTTP_HOST'] . str_replace($split[0]."-".$split[1], $split[1], $_SERVER['REQUEST_URI']); + Tools::redirect($url); + } + } + } + return ($id_product > 0) ? true : false; } @@ -141,10 +156,24 @@ public static function isCategoryLink($short_link) if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { - $sql .= ' AND `id_shop` = '.(int)Shop::getContextShopID(); + $sql2 = ' AND `id_shop` = '.(int)Shop::getContextShopID(); } - $id_category = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); + $id_category = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + + if(!$id_category){ + $split = explode("-", $categories[0], 2); + if(count($split) == 2 && is_numeric($split[0])){ + $sql = 'SELECT `id_category` FROM `'._DB_PREFIX_.'category_lang` + WHERE `link_rewrite` = \''.$split[1].'\' + AND `id_category` = "'.$split[0].'" AND `id_lang` = '. Context::getContext()->language->id; + $redirect = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + if($redirect){ + $url = (($_SERVER['HTTPS'])?"https://":"http://") . $_SERVER['HTTP_HOST'] . str_replace($split[0]."-".$split[1], $split[1], $_SERVER['REQUEST_URI']); + Tools::redirect($url); + } + } + } return ($id_category > 0) ? true : false; } @@ -168,10 +197,27 @@ public static function isCmsLink($short_link) if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { - $sql .= ' AND s.`id_shop` = '.(int)Shop::getContextShopID(); + $sql2 = ' AND s.`id_shop` = '.(int)Shop::getContextShopID(); } - $id_cms = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); + $id_cms = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + + if(!$id_cms){ + $split = explode("-", $explode_cms_link[$count-1], 2); + if(count($split) == 2 && is_numeric($split[0])){ + $sql = 'SELECT l.`id_cms` + FROM `'._DB_PREFIX_.'cms_lang` l + LEFT JOIN `'._DB_PREFIX_.'cms_shop` s ON (l.`id_cms` = s.`id_cms`) + WHERE l.`link_rewrite` = \''.$split[1].'\' + AND l.`id_cms` = "'.$split[0].'"'; + + $redirect = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + if($redirect){ + $url = (($_SERVER['HTTPS'])?"https://":"http://") . $_SERVER['HTTP_HOST'] . str_replace($split[0]."-".$split[1], $split[1], $_SERVER['REQUEST_URI']); + Tools::redirect($url); + } + } + } return ($id_cms > 0) ? true : false; } @@ -197,10 +243,27 @@ public static function isManufacturerLink($short_link) if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { - $sql .= ' AND s.`id_shop` = '.(int)Shop::getContextShopID(); + $sql2 = ' AND s.`id_shop` = '.(int)Shop::getContextShopID(); } - $id_manufacturer = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); + $id_manufacturer = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + + if(!$id_manufacturer){ + $split = explode("-", $name_manufacturer, 2); + if(count($split) == 2 && is_numeric($split[0])){ + $sql = 'SELECT m.`id_manufacturer` + FROM `'._DB_PREFIX_.'manufacturer` m + LEFT JOIN `'._DB_PREFIX_.'manufacturer_shop` s ON (m.`id_manufacturer` = s.`id_manufacturer`) + WHERE m.`name` LIKE \''.$split[1].'\' + AND m.`id_manufacturer` = "'.$split[0].'"'; + + $redirect = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + if($redirect){ + $url = (($_SERVER['HTTPS'])?"https://":"http://") . $_SERVER['HTTP_HOST'] . str_replace($split[0]."-".$split[1], $split[1], $_SERVER['REQUEST_URI']); + Tools::redirect($url); + } + } + } return ($id_manufacturer > 0) ? true : false; } @@ -226,10 +289,27 @@ public static function isSupplierLink($short_link) if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { - $sql .= ' AND s.`id_shop` = '.(int)Shop::getContextShopID(); + $sql2 = ' AND s.`id_shop` = '.(int)Shop::getContextShopID(); } - $id_supplier = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); + $id_supplier = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + + if(!$id_supplier){ + $split = explode("-", $explode_supplier_link[$count-1], 2); + if(count($split) == 2 && is_numeric($split[0])){ + $sql = 'SELECT sp.`id_supplier` + FROM `'._DB_PREFIX_.'supplier` sp + LEFT JOIN `'._DB_PREFIX_.'supplier_shop` s ON (sp.`id_supplier` = s.`id_supplier`) + WHERE sp.`name` LIKE \''.$split[1].'\' + AND sp.`id_supplier` = "'.$split[0].'"'; + + $redirect = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql.$sql2); + if($redirect){ + $url = (($_SERVER['HTTPS'])?"https://":"http://") . $_SERVER['HTTP_HOST'] . str_replace($split[0]."-".$split[1], $split[1], $_SERVER['REQUEST_URI']); + Tools::redirect($url); + } + } + } return ($id_supplier > 0) ? true : false; } From 3e568ba51cdbec4b9ce8c2777e05f0c116b1bd39 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Wed, 4 Mar 2015 14:22:02 +0700 Subject: [PATCH 3/7] fix array cast to int --- cleanurls/cleanurls.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cleanurls/cleanurls.php b/cleanurls/cleanurls.php index 96df801..03520c7 100644 --- a/cleanurls/cleanurls.php +++ b/cleanurls/cleanurls.php @@ -12,6 +12,7 @@ * This code is provided as is without any warranty. * No promise of being safe or secure * +* @adapted by mnwalker / AWcode * @author Ha!*!*y * @copyright 2012-2013 Ha!*!*y * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) @@ -24,9 +25,9 @@ public function __construct() { $this->name = 'cleanurls'; $this->tab = 'seo'; - $this->version = '0.42.1'; + $this->version = '0.6.0'; $this->need_instance = 0; - $this->author = 'ha!*!*y'; + $this->author = 'AWcode'; parent::__construct(); @@ -45,21 +46,21 @@ public function getContent() Go to back office -> Preferences -> SEO and URLs -> Set userfriendly URL on -> Save

'; - $sql = 'SELECT * FROM `'._DB_PREFIX_.'product_lang` + $sql = 'SELECT id_lang, name, id_product, link_rewrite FROM `'._DB_PREFIX_.'product_lang` WHERE `link_rewrite` IN (SELECT `link_rewrite` FROM `'._DB_PREFIX_.'product_lang` GROUP BY `link_rewrite`, `id_lang` - HAVING count(`link_rewrite`) > 1)'; + HAVING count(`link_rewrite`) > 1) LIMIT 20'; if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) { $sql .= ' AND `id_shop` = '.(int)Shop::getContextShopID(); } - - if ($results = (int)Db::getInstance()->ExecuteS($sql)) + $results = Db::getInstance()->ExecuteS($sql); + if (count($results)) { $output .= 'You need to fix duplicate URL entries
'; - foreach ($results AS $row) + foreach ($results as $row) { $language_info = $this->context->language->getLanguage($row['id_lang']); $output .= $row['name'].' ('.$row['id_product'] .') - '. $row['link_rewrite'].'
'; From 5a16f56b41c96496344c9ecad9bc1fb55f570664 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Wed, 4 Mar 2015 14:25:38 +0700 Subject: [PATCH 4/7] Update readme etc --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- cleanurls/config.xml | 8 ++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 781693a..91f67b9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ -[ABOUT](http://lebioda.github.io/PrestaShop-modules-CleanURLs/) +[ABOUT] =============================================================== +Adaptation of CleanURLs module originally created by Ha99y and modified by Lebioda and Lapy90 +https://github.com/Ha99y/PrestaShop-modules-CleanURLs +http://lebioda.github.io/PrestaShop-modules-CleanURLs/ + +CHANGES +-------- +Fixed an issue that was being experienced with .html on product pages + +INSTALLATION +-------- + +Install the module from the Backoffice (administration panel) + +In the modules tab, click on add a new module. Click on Browse to open the dialogue box letting you search your computer, select the file then validate the dialogue box. Finally click on Upload this module. + + +UNINSTALLATION +-------- + +Go to modules -> Find and uninstall "CleanURL". + +Open folder /override/classes/ +-> Remove "Link.php" +-> Remove "Dispatcher.php" + +Open folder /override/controllers/front/ +-> Remove "CategoryController.php" +-> Remove "CmsController.php" +-> Remove "ManufacturerController.php" +-> Remove "ProductController.php" +-> Remove "SupplierController.php" + +Open folder /cache/ +-> Remove "class_index.php" + +Go to back office -> Preferences -> SEO and URLs -> Set userfriendly URL off -> Save +Go to back office -> Preferences -> SEO and URLs -> Set userfriendly URL on -> Save + +If you got any other override modules, you should now go to you back office, uninstall them, and reinstall them again to work correctly. + diff --git a/cleanurls/config.xml b/cleanurls/config.xml index 58849e0..afa1dd4 100644 --- a/cleanurls/config.xml +++ b/cleanurls/config.xml @@ -2,11 +2,11 @@ cleanurls - - - + + + 1 0 - \ No newline at end of file + From 108eee0416d450e55a76c3de24bc8f40c6383445 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Wed, 4 Mar 2015 14:28:28 +0700 Subject: [PATCH 5/7] Update readme etc --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 91f67b9..cc0fd10 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ [ABOUT] =============================================================== Adaptation of CleanURLs module originally created by Ha99y and modified by Lebioda and Lapy90 + https://github.com/Ha99y/PrestaShop-modules-CleanURLs + http://lebioda.github.io/PrestaShop-modules-CleanURLs/ CHANGES From 9ecac3f74c371351e026658e1e44aa92632cf2f4 Mon Sep 17 00:00:00 2001 From: mnwalker Date: Fri, 6 Mar 2015 08:53:18 +0700 Subject: [PATCH 6/7] manufacturer with trailing slash --- cleanurls/override/classes/Dispatcher.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cleanurls/override/classes/Dispatcher.php b/cleanurls/override/classes/Dispatcher.php index 561bf7f..a87562c 100644 --- a/cleanurls/override/classes/Dispatcher.php +++ b/cleanurls/override/classes/Dispatcher.php @@ -231,8 +231,13 @@ public static function isCmsLink($short_link) public static function isManufacturerLink($short_link) { // check if any keyword - $explode_manufacturer_link = explode("/", $short_link); + $explode_manufacturer_link = explode("/", $short_link, 2); + $count = count($explode_manufacturer_link); + if($explode_manufacturer_link[$count-1] == ""){ + unset($explode_manufacturer_link[$count-1]); + $count = count($explode_manufacturer_link); + } $name_manufacturer = str_replace('-', '%', $explode_manufacturer_link[$count-1]); From a3ed64aa5ada8c2898765e56a287c4dc5c4a7567 Mon Sep 17 00:00:00 2001 From: mnwalker Date: Fri, 6 Mar 2015 09:04:16 +0700 Subject: [PATCH 7/7] manufacturer with trailing slash --- cleanurls/override/classes/Dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cleanurls/override/classes/Dispatcher.php b/cleanurls/override/classes/Dispatcher.php index a87562c..f513f91 100644 --- a/cleanurls/override/classes/Dispatcher.php +++ b/cleanurls/override/classes/Dispatcher.php @@ -231,7 +231,7 @@ public static function isCmsLink($short_link) public static function isManufacturerLink($short_link) { // check if any keyword - $explode_manufacturer_link = explode("/", $short_link, 2); + $explode_manufacturer_link = explode("/", $short_link); $count = count($explode_manufacturer_link); if($explode_manufacturer_link[$count-1] == ""){