Skip to content
Open
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
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[5.0.0]]></version>
<version><![CDATA[5.1.0]]></version>
<description><![CDATA[Generates an XML sitemap for your shop and keeps it up to date. Compatible with all major search engines.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[seo]]></tab>
Expand Down
57 changes: 55 additions & 2 deletions gsitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct()
{
$this->name = 'gsitemap';
$this->tab = 'checkout';
$this->version = '5.0.0';
$this->version = '5.1.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down Expand Up @@ -190,7 +190,8 @@ public function install()
}

return parent::install()
&& Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'gsitemap_sitemap` (`link` varchar(255) DEFAULT NULL, `id_shop` int(11) DEFAULT 0) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;') && $this->installHook();
&& Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'gsitemap_sitemap` (`link` varchar(255) DEFAULT NULL, `id_shop` int(11) DEFAULT 0) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;') && $this->installHook()
&& $this->registerHook('actionAdminMetaAfterWriteRobotsFile');
}

/**
Expand Down Expand Up @@ -320,6 +321,58 @@ public function getContent()
return $this->display(__FILE__, 'views/templates/admin/configuration.tpl');
}

/**
* Declares the sitemaps of the remaining shops in robots.txt.
*
* The core writes a Sitemap line for the shop currently in context only, while a
* multistore installation serves one robots.txt file to every domain. Without this,
* the sitemaps of the other shops are not declared anywhere.
*
* @param array $params
*
* @return void
*/
public function hookActionAdminMetaAfterWriteRobotsFile($params)
{
if (!Shop::isFeatureActive() || empty($params['write_fd']) || !is_resource($params['write_fd'])) {
return;
}

$idShopInContext = (int) $this->context->shop->id;

foreach (array_keys(Shop::getShops(true)) as $idShop) {
$idShop = (int) $idShop;

// The core already declared this one.
if ($idShop === $idShopInContext) {
continue;
}

$filename = $idShop . '_index_sitemap.xml';
$sitemapFile = $this->normalizeDirectory(_PS_ROOT_DIR_) . $filename;
if (!file_exists($sitemapFile) || !filesize($sitemapFile)) {
continue;
}

$shop = new Shop($idShop);
if (!Validate::isLoadedObject($shop)) {
continue;
}

// Each shop has its own domain and can have its own SSL setting.
$useSsl = (bool) Configuration::get('PS_SSL_ENABLED', null, null, $idShop);
$domain = $useSsl ? $shop->domain_ssl : $shop->domain;
if (empty($domain)) {
continue;
}

fwrite(
$params['write_fd'],
'Sitemap: ' . Tools::getProtocol($useSsl) . $domain . $shop->getBaseURI() . $filename . PHP_EOL
);
}
}

/**
* Delete all the generated sitemap files from the files system and the database.
*
Expand Down
33 changes: 33 additions & 0 deletions upgrade/upgrade-5.1.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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_5_1_0($object)
{
return $object->registerHook('actionAdminMetaAfterWriteRobotsFile');
}
Loading