Canonical module : add a meta balise
This commit is contained in:
parent
eeba2d78a8
commit
ae95bf66d9
96
modules/ant_canonical/ant_canonical.php
Normal file
96
modules/ant_canonical/ant_canonical.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Ant_Canonical extends Module
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ant_canonical';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->author = 'Antadis';
|
||||
$this->version = '1.0';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Canonical');
|
||||
$this->description = $this->l('Generate canonical url to remove duplicate content');
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
// Register hooks
|
||||
if(!(parent::install())
|
||||
|| !$this->registerHook('header')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hookHeader($params)
|
||||
{
|
||||
if(!_PS_MOBILE_){
|
||||
return false;
|
||||
}
|
||||
|
||||
global $cookie, $smarty, $page_name, $site_version;
|
||||
|
||||
switch ($site_version) {
|
||||
case 'es':
|
||||
$tld = 'es';
|
||||
break;
|
||||
case 'com':
|
||||
case 'fr':
|
||||
default:
|
||||
$tld = 'com';
|
||||
break;
|
||||
}
|
||||
|
||||
$domain = Configuration::get('PS_SSL_ENABLED') ?
|
||||
Configuration::get('PS_SHOP_DOMAIN_SSL') : Configuration::get('PS_SHOP_DOMAIN');
|
||||
$host = str_replace('bebeboutik.com', 'bebeboutik.'.$tld, $domain);
|
||||
$host = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$host;
|
||||
|
||||
// Page category
|
||||
if ($page_name == 'category') {
|
||||
$id_category = Tools::getValue('id_category');
|
||||
$category = new Category($id_category, $cookie->id_lang);
|
||||
if (Validate::isLoadedObject($category)) {
|
||||
$smarty->assign(array('url' => $host.'/'.$this->getLinkRewriteCategory($id_category)));
|
||||
}
|
||||
}
|
||||
|
||||
// Page product
|
||||
if ($page_name == 'product') {
|
||||
$id_product = Tools::getValue('id_product');
|
||||
$smarty->assign(array('url' => $host.'/'.$this->getLinkRewriteProduct($id_product)));
|
||||
}
|
||||
|
||||
return self::display(__FILE__, 'views/front/header.tpl');
|
||||
}
|
||||
|
||||
|
||||
private function getLinkRewriteProduct($id)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$product = new Product($id);
|
||||
return $this->getLinkRewriteCategory($product->id_category_default, true)
|
||||
.'/'.$id.'-'.$product->link_rewrite[$cookie->id_lang];
|
||||
}
|
||||
|
||||
private function getLinkRewriteCategory($id, $product = false)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if ($product === false) {
|
||||
return $id.'-'.Category::getLinkRewrite($id, $cookie->id_lang);
|
||||
} else {
|
||||
return Category::getLinkRewrite($id, $cookie->id_lang);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
36
modules/ant_canonical/index.php
Executable file
36
modules/ant_canonical/index.php
Executable file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* 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 http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7233 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
3
modules/ant_canonical/views/front/header.tpl
Normal file
3
modules/ant_canonical/views/front/header.tpl
Normal file
@ -0,0 +1,3 @@
|
||||
{if isset($url)}
|
||||
<link rel="canonical" href="{$url}" />
|
||||
{/if}
|
Loading…
Reference in New Issue
Block a user