From 604f780b0f35a2c0848c5a216d1bbd7722da2d17 Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Wed, 14 Jun 2023 11:42:09 +0200 Subject: [PATCH 1/2] Do not include blocked pages --- gsitemap.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gsitemap.php b/gsitemap.php index ef9160f..834dfd4 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -46,6 +46,16 @@ class Gsitemap extends Module */ protected $type_array = []; + /** + * @var array + */ + protected $disallow_controllers = [ + 'addresses', 'address', 'authentication', 'cart', 'discount', 'footer', + 'get-file', 'header', 'history', 'identity', 'images.inc', 'init', 'my-account', 'order', + 'order-slip', 'order-detail', 'order-follow', 'order-return', 'order-confirmation', 'pagination', 'password', + 'pdf-invoice', 'pdf-order-return', 'pdf-order-slip', 'product-sort', 'registration', 'search', 'statistics', 'attachment', 'guest-tracking', + ]; + public function __construct() { $this->name = 'gsitemap'; @@ -207,9 +217,13 @@ public function getContent() } /* Get Meta pages and remove index page it's managed elsewhere (@see $this->getHomeLink()) */ - $store_metas = array_filter(Meta::getMetasByIdLang((int) $this->context->cookie->id_lang), function ($meta) { - return $meta['page'] != 'index'; - }); + /* We also remove all pages that are blocked in core robots.txt file */ + $store_metas = array_filter(Meta::getMetasByIdLang( + (int) $this->context->cookie->id_lang), + function ($meta) { + return $meta['page'] != 'index' && !in_array($meta['page'], $this->disallow_controllers); + } + ); $store_url = $this->context->link->getBaseLink(); $this->context->smarty->assign([ 'gsitemap_form' => './index.php?tab=AdminModules&configure=gsitemap&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=gsitemap', @@ -360,6 +374,12 @@ protected function getMetaLink(&$link_sitemap, $lang, &$index, &$i, $id_meta = 0 $link = new Link(); $metas = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'meta` WHERE `configurable` > 0 AND `id_meta` >= ' . (int) $id_meta . ' AND page <> \'index\' ORDER BY `id_meta` ASC'); foreach ($metas as $meta) { + + // Check if this meta is not in the list of blocked controllers in core robots.txt + if (in_array($meta['page'], $this->disallow_controllers)) { + continue; + } + $url = ''; if (!in_array($meta['id_meta'], explode(',', Configuration::get('GSITEMAP_DISABLE_LINKS')))) { $url = $link->getPageLink($meta['page'], null, $lang['id_lang']); From ece5a5a1c1b489aecead7b71092acd49e9760512 Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Wed, 14 Jun 2023 11:51:28 +0200 Subject: [PATCH 2/2] Fix test --- gsitemap.php | 1 - 1 file changed, 1 deletion(-) diff --git a/gsitemap.php b/gsitemap.php index 834dfd4..4879529 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -374,7 +374,6 @@ protected function getMetaLink(&$link_sitemap, $lang, &$index, &$i, $id_meta = 0 $link = new Link(); $metas = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'meta` WHERE `configurable` > 0 AND `id_meta` >= ' . (int) $id_meta . ' AND page <> \'index\' ORDER BY `id_meta` ASC'); foreach ($metas as $meta) { - // Check if this meta is not in the list of blocked controllers in core robots.txt if (in_array($meta['page'], $this->disallow_controllers)) { continue;