Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version 4.3.1 #172

Merged
merged 19 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@

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: <br/>
It can be configured differently from one store to another.<br/>
It can be configured quickly in the same way on all stores thanks to the all shops context or the group of shops.<br/>
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].
Expand All @@ -31,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
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>gsitemap</name>
<displayName><![CDATA[Google sitemap]]></displayName>
<version><![CDATA[4.3.0]]></version>
<version><![CDATA[4.3.1]]></version>
<description><![CDATA[Generate your Google sitemap file]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[seo]]></tab>
Expand Down
58 changes: 34 additions & 24 deletions gsitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ 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';
$this->tab = 'checkout';
$this->version = '4.3.0';
$this->version = '4.3.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -98,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)) {
Expand All @@ -111,12 +120,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 true;
}

$hook = new Hook();
$hook->name = self::HOOK_ADD_URLS;
$hook->title = 'GSitemap Append URLs';
Expand All @@ -143,19 +157,13 @@ 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)) {
return false;
}
}

$hook = new Hook(Hook::getIdByName(self::HOOK_ADD_URLS));
if (Validate::isLoadedObject($hook)) {
$hook->delete();
}

return parent::uninstall() && $this->removeSitemap();
}

Expand Down Expand Up @@ -187,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'));
Expand All @@ -207,12 +214,16 @@ 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',
'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'),
Expand All @@ -226,7 +237,6 @@ public function getContent()
'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,
]);

Expand Down Expand Up @@ -360,6 +370,11 @@ 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']);
Expand Down Expand Up @@ -434,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)),
Expand Down Expand Up @@ -499,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([
Expand All @@ -509,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),
Expand Down Expand Up @@ -674,7 +684,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();
}

Expand Down
35 changes: 35 additions & 0 deletions upgrade/upgrade-4.3.1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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;
}
2 changes: 0 additions & 2 deletions views/templates/admin/configuration.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
<option{if $gsitemap_frequency == 'never'} selected="selected"{/if} value='never'>{l s='never' d='Modules.Gsitemap.Admin'}</option>
</select></label>
</div>
<label><input type="checkbox" name="gsitemap_check_image_file" value="1" {if $gsitemap_check_image_file}checked{/if}> {l s='Check this box if you wish to check the presence of the image files on the server' d='Modules.Gsitemap.Admin'}</label>
<br>
<p>{l s='Indicate the pages that you do not want to include in your sitemap files:' d='Modules.Gsitemap.Admin'}</p>
<button class="btn btn-secondary" type="button" id="check">{l s='Uncheck all' d='Modules.Gsitemap.Admin'}</button>
<br>
Expand Down
Loading