Skip to content
Permalink
Browse files

[-] MO gsitemap: fix incorrect lastmod

Was using date('c') or system time for all entries. Now using date_upd from DB when available:

product
category
manufacturer
supplier
* no date_upd available in DB for CMS pages

If no date_upd available then module already defaults to "dunno" and skips lastmod tag. This preserves priority for pages that really have been changed more recently as opposed to giving current time to media we don't even know about.
  • Loading branch information...
tucoinfo committed Oct 17, 2013
1 parent 2e64c4c commit 1e3d511c46c39de5e5bbd08ae0381704a92f14bd
Showing with 6 additions and 6 deletions.
  1. +6 −6 gsitemap/gsitemap.php
@@ -326,7 +326,7 @@ private function _getProductLink(&$link_sitemap, $lang, &$index, &$i, $id_produc
$image_product = array();
if (isset($image_link) && ($file_headers[0] != 'HTTP/1.1 404 Not Found' || $file_headers === true))
$image_product = array('title_img' => htmlspecialchars(strip_tags($product->name)), 'caption' => htmlspecialchars(strip_tags($product->description_short)), 'link' => $image_link);
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'product', 'page' => 'product', 'link' => $url, 'image' => $image_product), $lang['iso_code'], $index, $i, $product_id['id_product']))
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'product', 'page' => 'product', 'lastmod' => $product->date_upd, 'link' => $url, 'image' => $image_product), $lang['iso_code'], $index, $i, $product_id['id_product']))
return false;
unset($image_link);
@@ -368,7 +368,7 @@ private function _getCategoryLink(&$link_sitemap, $lang, &$index, &$i, $id_categ
if (isset($image_link) && ($file_headers[0] != 'HTTP/1.1 404 Not Found' || $file_headers === true))
$image_category = array('title_img' => htmlspecialchars(strip_tags($category->name)), 'link' => $image_link);
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'category', 'page' => 'category', 'link' => $url, 'image' => $image_category), $lang['iso_code'], $index, $i, (int)$category_id['id_category']))
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'category', 'page' => 'category', 'lastmod' => $category->date_upd, 'link' => $url, 'image' => $image_category), $lang['iso_code'], $index, $i, (int)$category_id['id_category']))
return false;
unset($image_link);
@@ -410,7 +410,7 @@ private function _getManufacturerLink(&$link_sitemap, $lang, &$index, &$i, $id_m
$manifacturer_image = array();
if ($file_headers[0] != 'HTTP/1.1 404 Not Found' || $file_headers === true)
$manifacturer_image = array('title_img' => htmlspecialchars(strip_tags($manufacturer->name)), 'caption' => htmlspecialchars(strip_tags($manufacturer->short_description)), 'link' => $image_link);
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'manufacturer', 'page' => 'manufacturer', 'link' => $url, 'image' => $manifacturer_image), $lang['iso_code'], $index, $i, $manufacturer_id['id_manufacturer']))
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'manufacturer', 'page' => 'manufacturer', 'lastmod' => $manufacturer->date_upd, 'link' => $url, 'image' => $manifacturer_image), $lang['iso_code'], $index, $i, $manufacturer_id['id_manufacturer']))
return false;;
}
return true;
@@ -449,7 +449,7 @@ private function _getSupplierLink(&$link_sitemap, $lang, &$index, &$i, $id_suppl
$supplier_image = array();
if ($file_headers[0] != 'HTTP/1.1 404 Not Found' || $file_headers === true)
$supplier_image = array('title_img' => htmlspecialchars(strip_tags($supplier->name)), 'link' => 'http'.(Configuration::get('PS_SSL_ENABLED') ? 's' : '').'://'.Tools::getMediaServer(_THEME_SUP_DIR_)._THEME_SUP_DIR_.((!file_exists(_THEME_SUP_DIR_.'/'.(int)$supplier->id.'-medium_default.jpg')) ? $lang['iso_code'].'-default' : (int)$supplier->id).'-medium_default.jpg');
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'supplier', 'page' => 'supplier', 'link' => $url, 'image' => $supplier_image), $lang['iso_code'], $index, $i, $supplier_id['id_supplier']))
if (!$this->_addLinkToSitemap($link_sitemap, array('type' => 'supplier', 'page' => 'supplier', 'lastmod' => $supplier->date_upd, 'link' => $url, 'image' => $supplier_image), $lang['iso_code'], $index, $i, $supplier_id['id_supplier']))
return false;
}
return true;
@@ -583,7 +583,7 @@ private function _recursiveSitemapCreator($link_sitemap, $lang, &$index)
foreach ($link_sitemap as $key => $file)
{
fwrite($writeFd, '<url>'."\r\n");
$this->_addSitemapNode($writeFd, htmlspecialchars(strip_tags($file['link'])), $this->_getPriorityPage($file['page']), Configuration::get('GSITEMAP_FREQUENCY'), date('c'));
$this->_addSitemapNode($writeFd, htmlspecialchars(strip_tags($file['link'])), $this->_getPriorityPage($file['page']), Configuration::get('GSITEMAP_FREQUENCY'), $file['lastmod']);
if ($file['image'])
{
$this->_addSitemapNodeImage($writeFd, htmlspecialchars(strip_tags($file['image']['link'])), isset($file['image']['title_img']) ? htmlspecialchars(str_replace(array("\r\n", "\r", "\n"), '', strip_tags($file['image']['title_img']))) : '', isset($file['image']['caption']) ? htmlspecialchars(str_replace(array("\r\n", "\r", "\n"), '', strip_tags($file['image']['caption']))) : '');
@@ -669,4 +669,4 @@ private function tableColumnExists($table_name, $column = null)
return true;
}
}
}

4 comments on commit 1e3d511

@codeurWeb

This comment has been minimized.

Copy link
Contributor

replied Oct 26, 2013

There are errors in Google webmaster tools with lastmod.
The best way would be to remove the lastmod because it is optional.

@tucoinfo

This comment has been minimized.

Copy link
Contributor Author

replied Oct 26, 2013

Yes, apologies. There is another contributor PR to format correctly but it is not accepted due to a recent PHP version dependancy.
The least I can do is look at it again myself.

@tucoinfo

This comment has been minimized.

Copy link
Contributor Author

replied Oct 26, 2013

@codeurWeb

This comment has been minimized.

Copy link
Contributor

replied Oct 26, 2013

Great solution ! Thank you !

Please sign in to comment.
You can’t perform that action at this time.