// Blocklayered: fix SEO problem + Adding nofollow option on the header

This commit is contained in:
mDeflotte
2012-02-27 16:37:23 +00:00
parent 1942f0ad91
commit b65ee8dfd4
4 changed files with 85 additions and 26 deletions
+8 -6
View File
@@ -455,12 +455,14 @@ function getUrlParams()
function updateProductUrl() function updateProductUrl()
{ {
// Adding the filters to URL product // Adding the filters to URL product
$.each($('ul#product_list li.ajax_block_product .product_img_link,'+ if (typeof(param_product_url) != 'undefined') {
'ul#product_list li.ajax_block_product h3 a,'+ $.each($('ul#product_list li.ajax_block_product .product_img_link,'+
'ul#product_list li.ajax_block_product .product_desc a,'+ 'ul#product_list li.ajax_block_product h3 a,'+
'ul#product_list li.ajax_block_product .lnk_view'), function() { 'ul#product_list li.ajax_block_product .product_desc a,'+
$(this).attr('href', $(this).attr('href') + param_product_url); 'ul#product_list li.ajax_block_product .lnk_view'), function() {
}); $(this).attr('href', $(this).attr('href') + param_product_url);
});
}
} }
/** /**
* Copy of the php function utf8_decode() * Copy of the php function utf8_decode()
+74 -17
View File
@@ -477,7 +477,7 @@ class BlockLayered extends Module
$smarty->assign('categoryNameComplement', $title); $smarty->assign('categoryNameComplement', $title);
$this->getProducts($selectedFilters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range); $this->getProducts($selectedFilters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range);
// Need a nofollow on the pagination links? // Need a nofollow on the pagination links?
//$smarty->assign('no_follow', $filterBlock['nofollow']); $smarty->assign('no_follow', $filterBlock['no_follow']);
} }
public function hookAfterSaveProduct($params) public function hookAfterSaveProduct($params)
@@ -1031,14 +1031,26 @@ class BlockLayered extends Module
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'layered_price_index` WHERE `id_product` = '.(int)$idProduct.' AND `id_shop` = '.(int)$id_shop); Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'layered_price_index` WHERE `id_product` = '.(int)$idProduct.' AND `id_shop` = '.(int)$id_shop);
if (Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')) if (Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX'))
$maxTaxRate = Db::getInstance()->getValue(' {
SELECT max(t.rate) max_rate if (version_compare(_PS_VERSION_,'1.5','>'))
FROM `'._DB_PREFIX_.'product` p $maxTaxRate = Db::getInstance()->getValue('
LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group) SELECT max(t.rate) max_rate
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (tr.id_tax_rules_group = trg.id_tax_rules_group) FROM `'._DB_PREFIX_.'product_tax_rules_group_shop` p
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1) LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group)
WHERE id_product = '.(int)$idProduct.' LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (tr.id_tax_rules_group = trg.id_tax_rules_group)
GROUP BY id_product'); LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1)
WHERE id_product = '.(int)$idProduct.'
GROUP BY id_product');
else
$maxTaxRate = Db::getInstance()->getValue('
SELECT max(t.rate) max_rate
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (tr.id_tax_rules_group = trg.id_tax_rules_group)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1)
WHERE id_product = '.(int)$idProduct.'
GROUP BY id_product');
}
else else
$maxTaxRate = 0; $maxTaxRate = 0;
@@ -1205,13 +1217,18 @@ class BlockLayered extends Module
{ {
case 'price': case 'price':
case 'weight': case 'weight':
return '<meta name="robots" content="noindex,nofollow"/>'; $smarty->assign('nobots', true);
$smarty->assign('nofollow', true);
return;
case 'id_attribute_group': case 'id_attribute_group':
foreach ($val as $attr) foreach ($val as $attr)
{ {
$attr_id = preg_replace('/_\d+$/', '', $attr); $attr_id = preg_replace('/_\d+$/', '', $attr);
if (in_array($attr_id, $attributes) || in_array(array('id_attribute_group' => $attr_id), $attribute_group_list)) if (in_array($attr_id, $attributes) || in_array(array('id_attribute_group' => $attr_id), $attribute_group_list)) {
return '<meta name="robots" content="noindex,nofollow"/>'; $smarty->assign('nobots', true);
$smarty->assign('nofollow', true);
return;
}
$attributes[] = $attr_id; $attributes[] = $attr_id;
} }
break; break;
@@ -1219,14 +1236,20 @@ class BlockLayered extends Module
foreach ($val as $feat) foreach ($val as $feat)
{ {
$feat_id = preg_replace('/_\d+$/', '', $feat); $feat_id = preg_replace('/_\d+$/', '', $feat);
if (in_array($feat_id, $features) || in_array(array('id_feature' => $feat_id), $feature_list)) if (in_array($feat_id, $features) || in_array(array('id_feature' => $feat_id), $feature_list)) {
return '<meta name="robots" content="noindex,nofollow"/>'; $smarty->assign('nobots', true);
$smarty->assign('nofollow', true);
return;
}
$features[] = $feat_id; $features[] = $feat_id;
} }
break; break;
default: default:
if (count($val) > 1) if (count($val) > 1) {
return '<meta name="robots" content="noindex,nofollow"/>'; $smarty->assign('nobots', true);
$smarty->assign('nofollow', true);
return;
}
break; break;
} }
} }
@@ -2938,6 +2961,29 @@ class BlockLayered extends Module
} }
} }
// All non indexable attribute and feature
$nonIndexable = array();
// Get all non indexable attribute groups
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT public_name
FROM `'._DB_PREFIX_.'attribute_group_lang` agl
LEFT JOIN `'._DB_PREFIX_.'layered_indexable_attribute_group` liag
ON liag.id_attribute_group = agl.id_attribute_group
WHERE indexable IS NULL OR indexable = 0
AND id_lang = '.(int)$cookie->id_lang) as $attribute)
$nonIndexable[] = Tools::link_rewrite($attribute['public_name']);
// Get all non indexable features
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT name
FROM `'._DB_PREFIX_.'feature_lang` fl
LEFT JOIN `'._DB_PREFIX_.'layered_indexable_feature` lif
ON lif.id_feature = fl.id_feature
WHERE indexable IS NULL OR indexable = 0
AND id_lang = '.(int)$cookie->id_lang) as $attribute)
$nonIndexable[] = Tools::link_rewrite($attribute['name']);
//generate SEO link //generate SEO link
$paramSelected = ''; $paramSelected = '';
@@ -2986,6 +3032,7 @@ class BlockLayered extends Module
$paramSelected .= '/page-'.$this->page; $paramSelected .= '/page-'.$this->page;
$blackList = array('weight','price'); $blackList = array('weight','price');
$nofollow = false;
foreach ($filterBlocks as &$typeFilter) foreach ($filterBlocks as &$typeFilter)
{ {
$filterName = (!empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name']); $filterName = (!empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name']);
@@ -2994,6 +3041,7 @@ class BlockLayered extends Module
{ {
foreach ($typeFilter['values'] as $key => $values) foreach ($typeFilter['values'] as $key => $values)
{ {
$nofollow = false;
$optionCheckedCloneArray = $optionCheckedArray; $optionCheckedCloneArray = $optionCheckedArray;
// If not filters checked, add parameter // If not filters checked, add parameter
@@ -3002,13 +3050,17 @@ class BlockLayered extends Module
{ {
// Update parameter filter checked before // Update parameter filter checked before
if (array_key_exists(Tools::link_rewrite($filterName), $optionCheckedArray)) if (array_key_exists(Tools::link_rewrite($filterName), $optionCheckedArray))
{
$optionCheckedCloneArray[Tools::link_rewrite($filterName)] = $optionCheckedCloneArray[Tools::link_rewrite($filterName)].'-'.str_replace('-', '_', Tools::link_rewrite($valueName)); $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = $optionCheckedCloneArray[Tools::link_rewrite($filterName)].'-'.str_replace('-', '_', Tools::link_rewrite($valueName));
$nofollow = true;
}
else else
$optionCheckedCloneArray[Tools::link_rewrite($filterName)] = '-'.str_replace('-', '_', Tools::link_rewrite($valueName)); $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = '-'.str_replace('-', '_', Tools::link_rewrite($valueName));
} }
else else
{ {
// Remove selected parameters // Remove selected parameters
$optionCheckedCloneArray[Tools::link_rewrite($filterName)] = str_replace('-'.str_replace('-', '_', Tools::link_rewrite($valueName)), '', $optionCheckedCloneArray[Tools::link_rewrite($filterName)]);
if (empty($optionCheckedCloneArray[Tools::link_rewrite($filterName)])) if (empty($optionCheckedCloneArray[Tools::link_rewrite($filterName)]))
unset($optionCheckedCloneArray[Tools::link_rewrite($filterName)]); unset($optionCheckedCloneArray[Tools::link_rewrite($filterName)]);
} }
@@ -3017,11 +3069,16 @@ class BlockLayered extends Module
$parameters .= '/'.str_replace('-', '_', $keyGroup).$valueGroup; $parameters .= '/'.str_replace('-', '_', $keyGroup).$valueGroup;
// Check if there is an non indexable attribute or feature in the url // Check if there is an non indexable attribute or feature in the url
foreach ($nonIndexable as $value)
if (strpos($parameters, '/'.$value) !== false)
$nofollow = true;
// Write link by mode rewriting // Write link by mode rewriting
if (!Configuration::get('PS_REWRITING_SETTINGS')) if (!Configuration::get('PS_REWRITING_SETTINGS'))
$typeFilter['values'][$key]['link'] = $linkBase.'&selected_filters='.$parameters; $typeFilter['values'][$key]['link'] = $linkBase.'&selected_filters='.$parameters;
else else
$typeFilter['values'][$key]['link'] = $linkBase.$parameters; $typeFilter['values'][$key]['link'] = $linkBase.$parameters;
$typeFilter['values'][$key]['rel'] = ($nofollow) ? 'nofollow' : '';
} }
} }
} }
@@ -3047,7 +3104,7 @@ class BlockLayered extends Module
'title_values' => $titleValues, 'title_values' => $titleValues,
'current_friendly_url' => htmlentities($paramSelected), 'current_friendly_url' => htmlentities($paramSelected),
'param_product_url' => htmlentities($param_product_url), 'param_product_url' => htmlentities($param_product_url),
//'nofollow' => !empty($paramSelected) || $nofollow 'no_follow' => (!empty($paramSelected) || $nofollow)
); );
return $cache; return $cache;
+2 -2
View File
@@ -99,7 +99,7 @@ param_product_url = '';
{if !$value.nbr} {if !$value.nbr}
{$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a> {$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a>
{else} {else}
<a href="{$value.link}">{$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a> <a href="{$value.link}" rel="{$value.rel}">{$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a>
{/if} {/if}
</label> </label>
</li> </li>
@@ -120,7 +120,7 @@ param_product_url = '';
{if !$value.nbr} {if !$value.nbr}
{$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a> {$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a>
{else} {else}
<a href="{$value.link}">{$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a> <a href="{$value.link}" rel="{$value.rel}">{$value.name|escape:html:'UTF-8'}{if $layered_show_qties}<span> ({$value.nbr})</span>{/if}</a>
{/if} {/if}
</label> </label>
</li> </li>
+1 -1
View File
@@ -36,7 +36,7 @@
{/if} {/if}
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<meta name="generator" content="PrestaShop" /> <meta name="generator" content="PrestaShop" />
<meta name="robots" content="{if isset($nobots)}no{/if}index,follow" /> <meta name="robots" content="{if isset($nobots)}no{/if}index,{if isset($nofollow) && $nofollow}no{/if}follow" />
<link rel="icon" type="image/vnd.microsoft.icon" href="{$favicon_url}?{$img_update_time}" /> <link rel="icon" type="image/vnd.microsoft.icon" href="{$favicon_url}?{$img_update_time}" />
<link rel="shortcut icon" type="image/x-icon" href="{$favicon_url}?{$img_update_time}" /> <link rel="shortcut icon" type="image/x-icon" href="{$favicon_url}?{$img_update_time}" />
<script type="text/javascript"> <script type="text/javascript">