From 61854aa368048edec367a3df723e25972c14f591 Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Wed, 8 Mar 2023 17:05:17 +0100 Subject: [PATCH 01/11] Check if the hook is present before adding it --- gsitemap.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gsitemap.php b/gsitemap.php index 92121c5..eca2c4b 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -111,12 +111,17 @@ public function install() } /** - * Registers hook(s) + * Check if the hook is present in the system or add it * * @return bool */ protected function installHook() { + $hook = new Hook(Hook::getIdByName(self::HOOK_ADD_URLS)); + if (Validate::isLoadedObject($hook)) { + return; + } + $hook = new Hook(); $hook->name = self::HOOK_ADD_URLS; $hook->title = 'GSitemap Append URLs'; @@ -151,11 +156,6 @@ public function uninstall() } } - $hook = new Hook(Hook::getIdByName(self::HOOK_ADD_URLS)); - if (Validate::isLoadedObject($hook)) { - $hook->delete(); - } - return parent::uninstall() && $this->removeSitemap(); } From af82d38ca2e6b1e4218802a927c5fbe1453d7e9a Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Wed, 8 Mar 2023 17:07:48 +0100 Subject: [PATCH 02/11] Fix return value --- gsitemap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsitemap.php b/gsitemap.php index eca2c4b..01d348a 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -119,7 +119,7 @@ protected function installHook() { $hook = new Hook(Hook::getIdByName(self::HOOK_ADD_URLS)); if (Validate::isLoadedObject($hook)) { - return; + return true; } $hook = new Hook(); From 604f780b0f35a2c0848c5a216d1bbd7722da2d17 Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Wed, 14 Jun 2023 11:42:09 +0200 Subject: [PATCH 03/11] 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 04/11] 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; From 46c9f52ffafa51c4a11f9e91f44b66849d4dd688 Mon Sep 17 00:00:00 2001 From: florine2623 <16019289+florine2623@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:56:31 +0200 Subject: [PATCH 05/11] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 694932c..48c4f38 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ Generate your Google sitemap file and keep it up to date with this module. +## Compatibility + +PrestaShop: `1.7.1.0` or later + ## Multistore compatibility This module is compatible with the multistore :heavy_check_mark:
From 477a80604a1673586cc9d3f2c9200296645ba44b Mon Sep 17 00:00:00 2001 From: florine2623 <16019289+florine2623@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:43:37 +0200 Subject: [PATCH 06/11] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 48c4f38..a226d00 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ It can be configured differently from one store to another.
It can be configured quickly in the same way on all stores thanks to the all shops context or the group of shops.
It can be activated on one store and deactivated on another +## How to test + +Configure your sitemap and generate it +Check that 1 sitemap is generated per language of shop +xml file should be available to download + ## Reporting issues You can report issues with this module in the main PrestaShop repository. [Click here to report an issue][report-issue]. From 3203f286d71b677fc43d8de6b6b46984a731ce80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 20 Oct 2023 09:25:35 +0200 Subject: [PATCH 07/11] Replace old urls --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a226d00..89e9378 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,6 @@ Just make sure to follow our [contribution guidelines][contribution-guidelines]. This module is released under the [Academic Free License 3.0][AFL-3.0] [report-issue]: https://github.com/PrestaShop/PrestaShop/issues/new/choose -[prestashop]: https://www.prestashop.com/ -[contribution-guidelines]: https://devdocs.prestashop.com/1.7/contribute/contribution-guidelines/project-modules/ +[prestashop]: https://www.prestashop-project.org/ +[contribution-guidelines]: https://devdocs.prestashop-project.org/1.7/contribute/contribution-guidelines/project-modules/ [AFL-3.0]: https://opensource.org/licenses/AFL-3.0 From 21f565214cb386a73d73a24801f0bdbb5662661b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Thu, 23 Nov 2023 14:14:45 +0100 Subject: [PATCH 08/11] Update gsitemap.php --- gsitemap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsitemap.php b/gsitemap.php index 7bb0624..2110234 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -226,7 +226,7 @@ function ($meta) { ); $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', + 'gsitemap_form' => './index.php?controller=AdminModules&configure=gsitemap&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=gsitemap', 'gsitemap_cron' => $store_url . 'modules/gsitemap/gsitemap-cron.php?token=' . Tools::substr(Tools::hash('gsitemap/cron'), 0, 10) . '&id_shop=' . $this->context->shop->id, 'gsitemap_feed_exists' => file_exists($this->normalizeDirectory(_PS_ROOT_DIR_) . 'index_sitemap.xml'), 'gsitemap_last_export' => Configuration::get('GSITEMAP_LAST_EXPORT'), @@ -693,7 +693,7 @@ public function createSitemap($id_shop = 0) if ($this->cron) { exit(); } - Tools::redirectAdmin('index.php?tab=AdminModules&configure=gsitemap&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=gsitemap&validation'); + Tools::redirectAdmin('index.php?controller=AdminModules&configure=gsitemap&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=gsitemap&validation'); exit(); } From 7d2987b6e317b7e85d5a122b93b853c099ad79d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Thu, 23 Nov 2023 14:22:44 +0100 Subject: [PATCH 09/11] Update gsitemap.php --- gsitemap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsitemap.php b/gsitemap.php index 7bb0624..6149e66 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -60,7 +60,7 @@ public function __construct() { $this->name = 'gsitemap'; $this->tab = 'checkout'; - $this->version = '4.3.0'; + $this->version = '4.3.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; From 279e6a228432affa52b02ba2affd185de8a1a09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Thu, 23 Nov 2023 14:23:14 +0100 Subject: [PATCH 10/11] Update config.xml --- config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.xml b/config.xml index de47d8e..691faa5 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ gsitemap - + From 5f67762d2c84b70825876310071c71d1ecbda150 Mon Sep 17 00:00:00 2001 From: Dominik Ulrich Date: Thu, 16 Nov 2023 20:29:30 +0100 Subject: [PATCH 11/11] Remove function of checking images --- config.xml | 2 +- gsitemap.php | 17 +++--------- upgrade/upgrade-4.3.1.php | 35 +++++++++++++++++++++++++ views/templates/admin/configuration.tpl | 2 -- 4 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 upgrade/upgrade-4.3.1.php diff --git a/config.xml b/config.xml index de47d8e..691faa5 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ gsitemap - + diff --git a/gsitemap.php b/gsitemap.php index 7bb0624..4412372 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -60,7 +60,7 @@ public function __construct() { $this->name = 'gsitemap'; $this->tab = 'checkout'; - $this->version = '4.3.0'; + $this->version = '4.3.1'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; @@ -108,7 +108,6 @@ public function install() 'GSITEMAP_PRIORITY_CATEGORY' => 0.8, 'GSITEMAP_PRIORITY_CMS' => 0.7, 'GSITEMAP_FREQUENCY' => 'weekly', - 'GSITEMAP_CHECK_IMAGE_FILE' => false, 'GSITEMAP_LAST_EXPORT' => false, ] as $key => $val) { if (!Configuration::updateValue($key, $val)) { @@ -158,7 +157,6 @@ public function uninstall() 'GSITEMAP_PRIORITY_CATEGORY' => '', 'GSITEMAP_PRIORITY_CMS' => '', 'GSITEMAP_FREQUENCY' => '', - 'GSITEMAP_CHECK_IMAGE_FILE' => '', 'GSITEMAP_LAST_EXPORT' => '', ] as $key => $val) { if (!Configuration::deleteByName($key)) { @@ -197,7 +195,6 @@ public function getContent() if (Tools::isSubmit('SubmitGsitemap')) { Configuration::updateValue('GSITEMAP_FREQUENCY', pSQL(Tools::getValue('gsitemap_frequency'))); Configuration::updateValue('GSITEMAP_INDEX_CHECK', ''); - Configuration::updateValue('GSITEMAP_CHECK_IMAGE_FILE', pSQL(Tools::getValue('gsitemap_check_image_file'))); $meta = ''; if (Tools::getValue('gsitemap_meta')) { $meta .= implode(', ', Tools::getValue('gsitemap_meta')); @@ -240,7 +237,6 @@ function ($meta) { 'memory_limit' => (int) ini_get('memory_limit'), ], 'prestashop_ssl' => Configuration::get('PS_SSL_ENABLED'), - 'gsitemap_check_image_file' => Configuration::get('GSITEMAP_CHECK_IMAGE_FILE'), 'shop' => $this->context->shop, ]); @@ -453,9 +449,7 @@ protected function getProductLink(&$link_sitemap, $lang, &$index, &$i, $id_produ 'http', Context::getContext()->shop->domain . Context::getContext()->shop->physical_uri . Context::getContext()->shop->virtual_uri, ], $image_link) : $image_link; - } - $file_headers = (Configuration::get('GSITEMAP_CHECK_IMAGE_FILE') && isset($image_link)) ? @get_headers($image_link) : true; - if (isset($image_link) && ((isset($file_headers[0]) && $file_headers[0] != 'HTTP/1.1 404 Not Found') || $file_headers === true)) { + $images_product[] = [ 'title_img' => htmlspecialchars(strip_tags($product->name)), 'caption' => htmlspecialchars(strip_tags($product->meta_description)), @@ -518,7 +512,7 @@ protected function getCategoryLink(&$link_sitemap, $lang, &$index, &$i, $id_cate foreach ($categories_id as $category_id) { $category = new Category((int) $category_id['id_category'], (int) $lang['id_lang']); $url = $link->getCategoryLink($category, urlencode($category->link_rewrite), (int) $lang['id_lang']); - + $image_category = []; if ($category->id_image) { $image_link = $this->context->link->getCatImageLink($category->link_rewrite, (int) $category->id_image, ImageType::getFormattedName('category')); $image_link = (!in_array(rtrim(Context::getContext()->shop->virtual_uri, '/'), explode('/', $image_link))) ? str_replace([ @@ -528,10 +522,7 @@ protected function getCategoryLink(&$link_sitemap, $lang, &$index, &$i, $id_cate 'http', Context::getContext()->shop->domain . Context::getContext()->shop->physical_uri . Context::getContext()->shop->virtual_uri, ], $image_link) : $image_link; - } - $file_headers = (Configuration::get('GSITEMAP_CHECK_IMAGE_FILE') && isset($image_link)) ? @get_headers($image_link) : true; - $image_category = []; - if (isset($image_link) && ((isset($file_headers[0]) && $file_headers[0] != 'HTTP/1.1 404 Not Found') || $file_headers === true)) { + $image_category = [ 'title_img' => htmlspecialchars(strip_tags($category->name)), 'caption' => Tools::substr(htmlspecialchars(strip_tags($category->description)), 0, 350), diff --git a/upgrade/upgrade-4.3.1.php b/upgrade/upgrade-4.3.1.php new file mode 100644 index 0000000..79f6a8b --- /dev/null +++ b/upgrade/upgrade-4.3.1.php @@ -0,0 +1,35 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_4_3_1($object) +{ + Configuration::deleteByName('GSITEMAP_CHECK_IMAGE_FILE'); + + return true; +} diff --git a/views/templates/admin/configuration.tpl b/views/templates/admin/configuration.tpl index 959a65e..7772f2c 100644 --- a/views/templates/admin/configuration.tpl +++ b/views/templates/admin/configuration.tpl @@ -94,8 +94,6 @@ {l s='never' d='Modules.Gsitemap.Admin'} - -

{l s='Indicate the pages that you do not want to include in your sitemap files:' d='Modules.Gsitemap.Admin'}