2015-07-09 12:56:40 +02:00
|
|
|
<?php
|
|
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
|
|
exit;
|
|
|
|
|
|
|
|
require_once dirname(__FILE__). '/classes/seourl.php';
|
|
|
|
|
|
|
|
class SeoUrl extends Module {
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->name = 'seourl';
|
|
|
|
$this->tab = 'front_office_features';
|
|
|
|
$this->version = '1.0';
|
|
|
|
$this->author = 'Antadis';
|
|
|
|
$this->need_instance = 0;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->displayName = $this->l('SEO Url');
|
|
|
|
$this->description = $this->l('Manage Seo Url');
|
|
|
|
$this->secure_key = Tools::encrypt($this->name);
|
|
|
|
|
|
|
|
$this->confirmUninstall = $this->l('Are you sure ?');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function install() {
|
|
|
|
if (Shop::isFeatureActive())
|
|
|
|
Shop::setContext(Shop::CONTEXT_ALL);
|
|
|
|
|
|
|
|
if (!parent::install() || !$this->registerHook('actionProductDelete')
|
|
|
|
|| !$this->registerHook('seoUrlCmsCategory')
|
2015-07-10 16:29:27 +02:00
|
|
|
|| !$this->registerHook('seoUrlCmsPost')
|
2015-07-09 12:56:40 +02:00
|
|
|
|| !$this->registerHook('actionObjectCmsUpdateAfter')
|
|
|
|
|| !$this->registerHook('actionObjectCmsDeleteAfter')
|
|
|
|
|| !$this->registerHook('displayHeader')
|
|
|
|
|| !$this->registerHook('actionCategoryUpdate')
|
|
|
|
|| !$this->registerHook('addFeatureProduct')
|
|
|
|
|| !$this->registerHook('actionCategoryAdd')
|
|
|
|
|| !$this->registerHook('actionProductSave') )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$res = Db::getInstance()->execute('
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'seourl` (
|
|
|
|
`id_seourl` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
|
`type` tinyint(10) NOT NULL,
|
|
|
|
`id_element` int(11) NOT NULL,
|
|
|
|
PRIMARY KEY (`id_seourl`))
|
|
|
|
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
|
|
|
|
|
|
|
|
if (!$res)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$res = Db::getInstance()->execute('
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'seourl_lang` (
|
|
|
|
`id_seourl` int(11) NOT NULL,
|
|
|
|
`id_lang` int(11) NOT NULL,
|
|
|
|
`id_shop` int(11) NOT NULL,
|
|
|
|
`link_rewrite` VARCHAR(255) NOT NULL,
|
|
|
|
`redirect` text,
|
|
|
|
`canonical` text,
|
|
|
|
PRIMARY KEY (`id_seourl`, `id_lang`))
|
|
|
|
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
|
|
|
|
|
|
|
|
if (!$res)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$res = Db::getInstance()->execute('
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'seourl_shop` (
|
|
|
|
`id_seourl` int(11) NOT NULL,
|
|
|
|
`id_shop` int(11) NOT NULL,
|
|
|
|
PRIMARY KEY (`id_seourl`, `id_shop`))
|
|
|
|
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstall(){
|
|
|
|
$res = Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'seourl_lang`');
|
|
|
|
$res = Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'seourl_shop`');
|
|
|
|
$res &= Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'seourl`');
|
|
|
|
if (!$res || !parent::uninstall())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook ajout/modification url catégorie de CMS
|
|
|
|
*/
|
|
|
|
public function hookseoUrlCmsCategory($params) {
|
|
|
|
$id_shop = Context::getContext()->shop->id;
|
|
|
|
$seo_url = ManageSeoUrl::getByType($params['object']->id, ManageSeoUrl::TYPE_CATEGORY_CMS, FALSE, NULL, $id_shop);
|
|
|
|
$urls = array();
|
|
|
|
|
|
|
|
//Check parent
|
|
|
|
if ($params['object']->id_parent) {
|
|
|
|
$seo_url_parent = ManageSeoUrl::getByType($params['object']->id_parent, ManageSeoUrl::TYPE_CATEGORY_CMS, FALSE, NULL, $id_shop);
|
|
|
|
foreach (Language::getLanguages() as $language) {
|
|
|
|
$id_lang = (int)$language['id_lang'];
|
|
|
|
$urls[$id_lang] = $seo_url_parent->link_rewrite[$id_lang].$params['object']->id.'-'.$params['object']->slug[$id_lang].'/';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach (Language::getLanguages() as $language) {
|
|
|
|
$id_lang = (int)$language['id_lang'];
|
|
|
|
$urls[$id_lang] = $params['object']->id.'-'.$params['object']->slug[$id_lang].'/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$seo_url instanceOf ManageSeoUrl
|
|
|
|
&& !$seo_url->id) {
|
|
|
|
ManageSeoUrl::createUrl(ManageSeoUrl::TYPE_CATEGORY_CMS, $params['object']->id, $urls);
|
|
|
|
} else {
|
|
|
|
$seo_url->link_rewrite = $urls;
|
|
|
|
$seo_url->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 16:29:27 +02:00
|
|
|
/**
|
|
|
|
* Hook ajout/modification url post de CMS
|
|
|
|
*/
|
|
|
|
public function hookseoUrlCmsPost($params) {
|
|
|
|
$id_shop = Context::getContext()->shop->id;
|
|
|
|
$seo_url = ManageSeoUrl::getByType($params['object']->id, ManageSeoUrl::TYPE_POST_CMS, FALSE, NULL, $id_shop);
|
|
|
|
$urls = array();
|
|
|
|
|
|
|
|
$url_category = ManageSeoUrl::getByType($params['object']->id_category, ManageSeoUrl::TYPE_CATEGORY_CMS, FALSE, NULL, $id_shop);
|
|
|
|
foreach (Language::getLanguages() as $language) {
|
|
|
|
$id_lang = (int)$language['id_lang'];
|
|
|
|
$urls[$id_lang] = $url_category->link_rewrite[$id_lang].$params['object']->id.'-'.$params['object']->slug[$id_lang].'.php';
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:58:18 +02:00
|
|
|
if (!$seo_url instanceOf ManageSeoUrl) {
|
2015-07-10 16:29:27 +02:00
|
|
|
ManageSeoUrl::createUrl(ManageSeoUrl::TYPE_POST_CMS, $params['object']->id, $urls);
|
|
|
|
} else {
|
|
|
|
$seo_url->link_rewrite = $urls;
|
|
|
|
$seo_url->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 12:56:40 +02:00
|
|
|
}
|