// Fixed #PSCFI-5331

This commit is contained in:
bMancone
2012-04-10 14:14:41 +00:00
parent b88bacedcc
commit 972d7fbe0d
+59 -49
View File
@@ -182,36 +182,42 @@ XML;
AND ps.id_shop = '.$shopID.' AND ps.id_shop = '.$shopID.'
'.(Configuration::get('GSITEMAP_ALL_PRODUCTS') ? '' : 'HAVING level_depth IS NOT NULL').' '.(Configuration::get('GSITEMAP_ALL_PRODUCTS') ? '' : 'HAVING level_depth IS NOT NULL').'
ORDER BY pl.id_product, pl.id_lang ASC'; ORDER BY pl.id_product, pl.id_lang ASC';
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
$tmp = null; $resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
$res = null;
// array used to know which product/image was already added (blacklist)
$done = null; $done = null;
foreach ($products as $product) $sitemap = null;
// iterates on the products, to gather the image ids
while ($product = Db::getInstance()->nextRow($resource))
{ {
if (!isset($done[$product['id_image']])) // if the product has not been added
$id_product = $product['id_product'];
if (!isset($done[$id_product]['added']))
{ {
if ($tmp == $product['id_product']) // priority
$res[$tmp]['images'] []= array('id_image' => $product['id_image'], 'legend_image' => $product['legend_image']); if (($priority = 0.7 - ($product['level_depth'] / 10)) < 0.1)
else $priority = 0.1;
{
$tmp = $product['id_product']; // adds the product
$res[$tmp] = $product; $tmpLink = $this->context->link->getProductLink((int)($product['id_product']), $product['link_rewrite'], $product['category'], $product['ean13'], (int)($product['id_lang']));
unset($res[$tmp]['id_image'], $res[$tmp]['legend_image']); $sitemap = $this->_addSitemapNode($xml, $tmpLink, $priority, 'weekly', substr($product['date_upd'], 0, 10));
$res[$tmp]['images'] []= array('id_image' => $product['id_image'], 'legend_image' => $product['legend_image']);
} // considers the product has added
$done[$product['id_image']] = true; $done[$id_product]['added'] = true;
} }
}
foreach ($res as $product) // if the image has not been added
{ $id_image = $product['id_image'];
if (($priority = 0.7 - ($product['level_depth'] / 10)) < 0.1) if (!isset($done[$id_product][$id_image]) && $id_image)
$priority = 0.1; {
// adds the image
$this->_addSitemapNodeImage($sitemap, $product);
$tmpLink = $this->context->link->getProductLink((int)($product['id_product']), $product['link_rewrite'], $product['category'], $product['ean13'], (int)($product['id_lang'])); // considers the image as added
$sitemap = $this->_addSitemapNode($xml, $tmpLink, $priority, 'weekly', substr($product['date_upd'], 0, 10)); $done[$id_product][$id_image] = true;
$sitemap = $this->_addSitemapNodeImage($sitemap, $product); }
} }
/* Categories Generator */ /* Categories Generator */
@@ -329,15 +335,12 @@ XML;
private function _addSitemapNodeImage($xml, $product) private function _addSitemapNodeImage($xml, $product)
{ {
foreach ($product['images'] as $img) $image = $xml->addChild('image', null, 'http://www.google.com/schemas/sitemap-image/1.1');
{ $image->addChild('loc', htmlspecialchars($this->context->link->getImageLink($product['link_rewrite'], (int)$product['id_product'].'-'.(int)$product['id_image'])), 'http://www.google.com/schemas/sitemap-image/1.1');
$image = $xml->addChild('image', null, 'http://www.google.com/schemas/sitemap-image/1.1');
$image->addChild('loc', htmlspecialchars($this->context->link->getImageLink($product['link_rewrite'], (int)$product['id_product'].'-'.(int)$img['id_image'])), 'http://www.google.com/schemas/sitemap-image/1.1');
$legend_image = preg_replace('/(&+)/i', '&amp;', $img['legend_image']); $legend_image = preg_replace('/(&+)/i', '&amp;', $product['legend_image']);
$image->addChild('caption', $legend_image, 'http://www.google.com/schemas/sitemap-image/1.1'); $image->addChild('caption', $legend_image, 'http://www.google.com/schemas/sitemap-image/1.1');
$image->addChild('title', $legend_image, 'http://www.google.com/schemas/sitemap-image/1.1'); $image->addChild('title', $legend_image, 'http://www.google.com/schemas/sitemap-image/1.1');
}
} }
private function _displaySitemap() private function _displaySitemap()
@@ -406,28 +409,25 @@ XML;
else else
$domain = Tools::getShopDomain(true); $domain = Tools::getShopDomain(true);
$this->_html .= $this->_html .= '
'<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post"> <form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
<div style="margin:0 0 20px 0;"> <div style="margin:0 0 20px 0;">
<input type="checkbox" name="GSITEMAP_ALL_PRODUCTS" id="GSITEMAP_ALL_PRODUCTS" style="vertical-align: middle;" value="1" '.(Configuration::get('GSITEMAP_ALL_PRODUCTS') ? 'checked="checked"' : '').' /> <label class="t" for="GSITEMAP_ALL_PRODUCTS">'.$this->l('Sitemap also includes products from inactive categories').'</label> <input type="checkbox" name="GSITEMAP_ALL_PRODUCTS" id="GSITEMAP_ALL_PRODUCTS" style="vertical-align: middle;" value="1" '.(Configuration::get('GSITEMAP_ALL_PRODUCTS') ? 'checked="checked"' : '').' /> <label class="t" for="GSITEMAP_ALL_PRODUCTS">'.$this->l('Sitemap also includes products from inactive categories').'</label>
</div> </div>
<div style="margin:0 0 20px 0;"> <div style="margin:0 0 20px 0;">
<input type="checkbox" name="GSITEMAP_ALL_CMS" id="GSITEMAP_ALL_CMS" style="vertical-align: middle;" value="1" '.(Configuration::get('GSITEMAP_ALL_CMS') ? 'checked="checked"' : '').' /> <label class="t" for="GSITEMAP_ALL_CMS">'.$this->l('Sitemap also includes CMS pages which are not in a CMS block').'</label> <input type="checkbox" name="GSITEMAP_ALL_CMS" id="GSITEMAP_ALL_CMS" style="vertical-align: middle;" value="1" '.(Configuration::get('GSITEMAP_ALL_CMS') ? 'checked="checked"' : '').' /> <label class="t" for="GSITEMAP_ALL_CMS">'.$this->l('Sitemap also includes CMS pages which are not in a CMS block').'</label>
</div> </div>
<input name="btnSubmit" class="button" type="submit" <input name="btnSubmit" class="button" type="submit"
value="'.((!file_exists(GSITEMAP_FILE)) ? $this->l('Generate sitemap file') : $this->l('Update sitemap file')).'" /> value="'.((!file_exists(GSITEMAP_FILE)) ? $this->l('Generate sitemap file') : $this->l('Update sitemap file')).'" />
</form><br /> </form><br />
<h2>'.$this->l('Use cron job to re-build the sitemap:').'</h2> <h2>'.$this->l('Use cron job to re-build the sitemap:').'</h2>
<p> <p>
<b>'.$domain.__PS_BASE_URI__.'modules/gsitemap/gsitemap-cron?&token='.substr(Tools::encrypt('gsitemap/cron'),0,10).'&GSITEMAP_ALL_CMS='.((int)Configuration::get('GSITEMAP_ALL_CMS')).'&GSITEMAP_ALL_PRODUCTS='.((int)Configuration::get('GSITEMAP_ALL_PRODUCTS')).'</b> <b>'.$domain.__PS_BASE_URI__.'modules/gsitemap/gsitemap-cron.php?&token='.substr(Tools::encrypt('gsitemap/cron'),0,10).'&GSITEMAP_ALL_CMS='.((int)Configuration::get('GSITEMAP_ALL_CMS')).'&GSITEMAP_ALL_PRODUCTS='.((int)Configuration::get('GSITEMAP_ALL_PRODUCTS')).'</b>
</p>'; </p>';
} }
public function getContent() public function getContent()
{ {
$this->_html .= '<h2>'.$this->l('Search Engine Optimization').'</h2>
'.$this->l('See').' <a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184&from=40318&rd=1" style="font-weight:bold;text-decoration:underline;" target="_blank">
'.$this->l('this page').'</a> '.$this->l('for more information').'<br /><br />';
if (Tools::isSubmit('btnSubmit')) if (Tools::isSubmit('btnSubmit'))
{ {
$this->_postValidation(); $this->_postValidation();
@@ -438,10 +438,20 @@ XML;
$this->_html .= '<div class="alert error">'.$err.'</div>'; $this->_html .= '<div class="alert error">'.$err.'</div>';
} }
$this->_html .= '
<fieldset>
<legend>'.$this->l('Search Engine Optimization').'</legend>
<br />
'.$this->l('See').' <a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184&from=40318&rd=1" style="font-weight:bold;text-decoration:underline;" target="_blank">
'.$this->l('this page').'</a> '.$this->l('for more information').'
<br />';
$this->_displaySitemap(); $this->_displaySitemap();
$this->_displayForm(); $this->_displayForm();
$this->_html .= '</fieldset>';
return $this->_html; return $this->_html;
} }
} }