155 lines
4.4 KiB
PHP
Executable File
155 lines
4.4 KiB
PHP
Executable File
<?php
|
|
|
|
require_once('classes/AntLandingPage.php');
|
|
class Antadismarketing_landingpage extends Module
|
|
{
|
|
|
|
public function __construct($name = null, Context $context = null)
|
|
{
|
|
$this->name = 'antadismarketing_landingpage';
|
|
$this->tab = 'others';
|
|
$this->version = '0.1';
|
|
$this->author = 'Antadis';
|
|
$this->need_instance = 0;
|
|
$this->module_key = "";
|
|
|
|
parent::__construct($name, $context);
|
|
|
|
$this->displayName = $this->l('Antadis marketing landing page');
|
|
$this->description = $this->l('Antadis marketing landing page');
|
|
$this->confirmUninstall = $this->l('are you sur to uninstall ?');
|
|
|
|
$this->currentIndex = 'index.php?controller=AdminModules';
|
|
$this->base_config_url = $this->currentIndex .'&configure=' . $this->name . '&token=' . Tools::getValue('token');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (!parent::install()
|
|
|| !$this->installDb()
|
|
|| !$this->installTab()
|
|
|| !mkdir(_PS_IMG_DIR_.'landingpage')
|
|
|| !$this->registerHook('ModuleRoutes')
|
|
){
|
|
$this->uninstall();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function installDb()
|
|
{
|
|
//MULTI CREATE A TESTER
|
|
try {
|
|
Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.'ant_marketing_landingpage (
|
|
`id_landingpage` int(11) NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(150) DEFAULT NULL,
|
|
`content_type` int(11) NOT NULL,
|
|
`cfg` text,
|
|
`active` int(11) NOT NULL,
|
|
`subscribe` int(11) NOT NULL,
|
|
`date_add` datetime NOT NULL,
|
|
PRIMARY KEY (`id_landingpage`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
|
|
|
|
Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS ps_ant_marketing_landingpage_lang (
|
|
`id_landingpage` int(11) NOT NULL,
|
|
`id_lang` int(11) NOT NULL,
|
|
`url` VARCHAR(150),
|
|
`content` TEXT,
|
|
`meta_title` VARCHAR(150),
|
|
`meta_description` TEXT NOT NULL,
|
|
`content_return` TEXT NOT NULL,
|
|
PRIMARY KEY (`id_landingpage`, `id_lang`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
|
|
|
|
Db::getInstance()->execute('
|
|
CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.'ant_marketing_landingpage_extra (
|
|
`id_landingpage` int(11) NOT NULL,
|
|
`displaytag` tinyint DEFAULT 0,
|
|
PRIMARY KEY (`id_landingpage`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
|
|
|
|
return true;
|
|
} catch(Exception $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function installTab()
|
|
{
|
|
$parent_tab = Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE id_parent = 0 AND class_name = "AdminAntMarketing"');
|
|
if(!$parent_tab)
|
|
$parent_tab = self::createTab($parent_tab, $this->name, 'Antadis Marketing', 'AdminAntMarketing');
|
|
|
|
if(!self::createTab($parent_tab, $this->name, 'Landing page', 'AdminAntMarketingLandingPage'))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static function createTab($id_parent, $module, $name, $class_name)
|
|
{
|
|
$Tab = new Tab();
|
|
$Tab->module = $module;
|
|
foreach(Language::getLanguages(true) as $languages)
|
|
{
|
|
$Tab->name[$languages["id_lang"]] = $name;
|
|
}
|
|
|
|
$Tab->id_parent = $id_parent;
|
|
$Tab->class_name = $class_name;
|
|
$r = $Tab->save();
|
|
|
|
if($r === false)
|
|
return false;
|
|
|
|
return $Tab->id;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function uninstall()
|
|
{
|
|
if(!parent::uninstall()){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function hookModuleRoutes()
|
|
{
|
|
$urls_landing_page = AntLandingPage::getAllUrl();
|
|
if($urls_landing_page !== false && count($urls_landing_page) > 0)
|
|
{
|
|
$urls_string = array();
|
|
foreach($urls_landing_page as $url_landing_page)
|
|
$urls_string[] = $url_landing_page['url'];
|
|
|
|
$urls_string = implode('|', $urls_string);
|
|
|
|
$ModuleRoutes = array(
|
|
'module-antadismarketing_landingpage-landingpage' => array(
|
|
'controller' => 'landingpage',
|
|
'rule' => '{url}',
|
|
'keywords' => array(
|
|
'url' => array('regexp' => $urls_string, 'param' => 'url')
|
|
),
|
|
'params' => array(
|
|
'fc' => 'module',
|
|
'module' => 'antadismarketing_landingpage',
|
|
'controller' => 'landingpage'
|
|
)
|
|
)
|
|
);
|
|
|
|
return $ModuleRoutes;
|
|
}
|
|
|
|
return array();
|
|
}
|
|
} |