diff --git a/modules/ant_canonical/ant_canonical.php b/modules/ant_canonical/ant_canonical.php new file mode 100644 index 00000000..eae4b776 --- /dev/null +++ b/modules/ant_canonical/ant_canonical.php @@ -0,0 +1,102 @@ +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); + } + } + +} \ No newline at end of file diff --git a/modules/ant_canonical/index.php b/modules/ant_canonical/index.php new file mode 100755 index 00000000..2b4249b5 --- /dev/null +++ b/modules/ant_canonical/index.php @@ -0,0 +1,36 @@ + +* @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; \ No newline at end of file diff --git a/modules/ant_canonical/views/front/header.tpl b/modules/ant_canonical/views/front/header.tpl new file mode 100644 index 00000000..4da1bb7c --- /dev/null +++ b/modules/ant_canonical/views/front/header.tpl @@ -0,0 +1,3 @@ +{if isset($url)} + +{/if} \ No newline at end of file diff --git a/themes/site_mobile/header.tpl b/themes/site_mobile/header.tpl index fad86931..1eec4a78 100755 --- a/themes/site_mobile/header.tpl +++ b/themes/site_mobile/header.tpl @@ -9,12 +9,12 @@ {/if} {/if} -{if isset($meta_keywords) AND $meta_keywords} + {if isset($meta_keywords) AND $meta_keywords} -{/if} -{if isset($meta_fb_img) AND $meta_fb_img} + {/if} + {if isset($meta_fb_img) AND $meta_fb_img} -{/if} + {/if} @@ -25,8 +25,9 @@ {if isset($page_name) && $page_name == 'authentication'} {/if} + -{if isset($css_files)} - {foreach from=$css_files key=css_uri item=media} - - {/foreach} -{/if} -{if isset($js_files)} - {foreach from=$js_files item=js_uri} - - {/foreach} -{/if} - + {if isset($css_files)} + {foreach from=$css_files key=css_uri item=media} + + {/foreach} + {/if} + {if isset($js_files)} + {foreach from=$js_files item=js_uri} + + {/foreach} + {/if} + {$HOOK_HEADER} @@ -411,7 +412,8 @@ a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1); {/literal} - {include file="$tpl_dir./header-meta-fb.tpl"} + + {include file="$tpl_dir./header-meta-fb.tpl"}