Merge branch 'feature/canonical'
This commit is contained in:
commit
8e55191a35
102
modules/ant_canonical/ant_canonical.php
Normal file
102
modules/ant_canonical/ant_canonical.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?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)
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Real product rewrite link
|
||||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* Real category rewrite link
|
||||
* @param int $id
|
||||
* @param boolean $product
|
||||
* @return string
|
||||
*/
|
||||
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}
|
@ -9,12 +9,12 @@
|
||||
<meta name="description" content="{$meta_description|escape:html:'UTF-8'}" />
|
||||
{/if}
|
||||
{/if}
|
||||
{if isset($meta_keywords) AND $meta_keywords}
|
||||
{if isset($meta_keywords) AND $meta_keywords}
|
||||
<meta name="keywords" content="{$meta_keywords|escape:html:'UTF-8'}" />
|
||||
{/if}
|
||||
{if isset($meta_fb_img) AND $meta_fb_img}
|
||||
{/if}
|
||||
{if isset($meta_fb_img) AND $meta_fb_img}
|
||||
<meta property="og:image" content="{$meta_fb_img|escape:html:'UTF-8'}" />
|
||||
{/if}
|
||||
{/if}
|
||||
<meta name="theme-color" content="#565485">
|
||||
|
||||
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
|
||||
@ -25,8 +25,9 @@
|
||||
{if isset($page_name) && $page_name == 'authentication'}
|
||||
<link rel="canonical" href="{$link->getPageLink('authentication.php', TRUE)}" />
|
||||
{/if}
|
||||
|
||||
<script type="text/javascript">
|
||||
var baseDirSsl = '{$base_dir_ssl}';
|
||||
var baseDirSsl = '{$base_dir_ssl}';
|
||||
var baseDir = '{$content_dir}';
|
||||
var static_token = '{$static_token}';
|
||||
var token = '{$token}';
|
||||
@ -36,17 +37,17 @@
|
||||
var isoLang = "{$lang_iso}";
|
||||
</script>
|
||||
|
||||
{if isset($css_files)}
|
||||
{foreach from=$css_files key=css_uri item=media}
|
||||
<link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />
|
||||
{/foreach}
|
||||
{/if}
|
||||
{if isset($js_files)}
|
||||
{foreach from=$js_files item=js_uri}
|
||||
<script type="text/javascript" src="{$js_uri}"></script>
|
||||
{/foreach}
|
||||
{/if}
|
||||
<script src="{$content_dir}themes/site_mobile/js/global.js"></script>
|
||||
{if isset($css_files)}
|
||||
{foreach from=$css_files key=css_uri item=media}
|
||||
<link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />
|
||||
{/foreach}
|
||||
{/if}
|
||||
{if isset($js_files)}
|
||||
{foreach from=$js_files item=js_uri}
|
||||
<script type="text/javascript" src="{$js_uri}"></script>
|
||||
{/foreach}
|
||||
{/if}
|
||||
<script src="{$content_dir}themes/site_mobile/js/global.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||
<link rel="apple-touch-icon" href="{$base_dir_ssl}img/apple-touch-icon.png" />
|
||||
{$HOOK_HEADER}
|
||||
@ -411,7 +412,8 @@
|
||||
a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
|
||||
</script>
|
||||
{/literal}
|
||||
{include file="$tpl_dir./header-meta-fb.tpl"}
|
||||
|
||||
{include file="$tpl_dir./header-meta-fb.tpl"}
|
||||
</head>
|
||||
|
||||
<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if} class="{$bodyClass}{if $cookie->isLogged()} logged{/if}">
|
||||
|
Loading…
Reference in New Issue
Block a user