2015-08-12 14:10:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!defined('_CAN_LOAD_FILES_')) {
|
2015-10-23 14:46:01 +02:00
|
|
|
exit;
|
2015-08-12 14:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
require(dirname(__FILE__).'/classes/BlockAds.php');
|
|
|
|
require(dirname(__FILE__).'/classes/Publication.php');
|
|
|
|
|
|
|
|
class Blockadshooks extends Module
|
|
|
|
{
|
2015-10-23 14:46:01 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->name = 'blockadshooks';
|
|
|
|
$this->tab = 'other';
|
|
|
|
$this->version = '1.0';
|
|
|
|
$this->author = 'Antadis';
|
|
|
|
$this->need_instance = 0;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->displayName = $this->l('Block ads hooks');
|
|
|
|
$this->description = $this->l('Display ads in your website');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function install()
|
|
|
|
{
|
|
|
|
$return = true;
|
|
|
|
|
|
|
|
include(dirname(__FILE__).'/sql/sql-install.php');
|
|
|
|
foreach ($sql as $s)
|
|
|
|
{
|
|
|
|
if (!Db::getInstance()->execute($s))
|
|
|
|
$return=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($return === true)
|
|
|
|
$this->createAds();
|
|
|
|
|
|
|
|
return $return
|
|
|
|
&& parent::install()
|
|
|
|
&& $this->createAdminTabs()
|
|
|
|
&& $this->registerHook('displayBoxPartenaire1')
|
|
|
|
&& $this->registerHook('displayBoxPartenaire2')
|
|
|
|
&& $this->registerHook('displayBoxPartenaire3');
|
2015-10-21 17:10:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 14:46:01 +02:00
|
|
|
public function createAds()
|
2015-10-21 17:10:46 +02:00
|
|
|
{
|
2015-10-23 14:46:01 +02:00
|
|
|
$adsArray = array(
|
|
|
|
array(
|
|
|
|
'hook_name' => 'displayBoxPartenaire1',
|
|
|
|
'label' => 'Pub partenaire 1',
|
|
|
|
'width' => '250',
|
|
|
|
'height' => '250',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'hook_name' => 'displayBoxPartenaire2',
|
|
|
|
'label' => 'Pub partenaire 2',
|
|
|
|
'width' => '250',
|
|
|
|
'height' => '250',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'hook_name' => 'displayBoxPartenaire3',
|
|
|
|
'label' => 'Pub partenaire 3',
|
|
|
|
'width' => '250',
|
|
|
|
'height' => '250',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($adsArray as $adsTmp)
|
|
|
|
{
|
|
|
|
$ads = new BlockAds();
|
|
|
|
foreach($adsTmp as $k => $v)
|
|
|
|
$ads->$k = $v;
|
|
|
|
|
|
|
|
$ads->save();
|
|
|
|
}
|
2015-10-21 17:10:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 14:46:01 +02:00
|
|
|
public function uninstall()
|
|
|
|
{
|
|
|
|
$return = true;
|
|
|
|
|
|
|
|
include(dirname(__FILE__).'/sql/sql-uninstall.php');
|
|
|
|
foreach ($sqlu as $s)
|
|
|
|
{
|
|
|
|
if (!Db::getInstance()->execute($s))
|
|
|
|
$return=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return
|
|
|
|
&& parent::uninstall()
|
|
|
|
&& self::uninstallTab('AdminAds')
|
|
|
|
&& self::uninstallTab('AdminAdsPublication');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function uninstallTab($tabClass)
|
2015-10-21 17:10:46 +02:00
|
|
|
{
|
2015-10-23 14:46:01 +02:00
|
|
|
$idTab = Tab::getIdFromClassName($tabClass);
|
|
|
|
if ($idTab != 0)
|
|
|
|
{
|
|
|
|
$tab = new Tab($idTab);
|
|
|
|
$tab->delete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-10-21 17:10:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 14:46:01 +02:00
|
|
|
public static function createTab($id_parent, $module, $name, $class_name, $status=True)
|
|
|
|
{
|
|
|
|
$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;
|
|
|
|
$tab->active = $status;
|
|
|
|
$r = $tab->save();
|
|
|
|
|
|
|
|
if ($r === False)
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return $tab->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createAdminTabs()
|
|
|
|
{
|
|
|
|
$parent_tab = Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE id_parent = 0 AND class_name = "AdminCmsPs"');
|
|
|
|
if(!$parent_tab)
|
|
|
|
$parent_tab = self::createTab(0, $this->name, $this->l('Gestion des publicités'), 'AdminAds');
|
|
|
|
|
|
|
|
return (
|
|
|
|
!!self::createTab($parent_tab, $this->name, $this->l('Gestion des emplacements publicitaires'), 'AdminAds')
|
|
|
|
&& !!self::createTab($parent_tab, $this->name, $this->l('Gestion des publicités'), 'AdminAdsPublication')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getContent()
|
|
|
|
{
|
|
|
|
Tools::redirectAdmin($this->context->link->getAdminLink('AdminAds'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIdByPageName($page_name)
|
|
|
|
{
|
|
|
|
switch($page_name)
|
|
|
|
{
|
|
|
|
case 'postcms':
|
|
|
|
return Context::getContext()->controller->postcms->id;
|
|
|
|
break;
|
|
|
|
case 'postedito':
|
|
|
|
return Context::getContext()->controller->postedito->id;
|
|
|
|
break;
|
|
|
|
case 'categorycms':
|
|
|
|
return Context::getContext()->controller->categorycms->id;
|
|
|
|
break;
|
|
|
|
default: return null; break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 17:10:46 +02:00
|
|
|
|
2015-10-23 14:46:01 +02:00
|
|
|
public function runByHook($hook_name)
|
|
|
|
{
|
|
|
|
$page_name = Dispatcher::getInstance()->getController();
|
2015-11-17 14:35:27 +01:00
|
|
|
|
|
|
|
if ($page_name == 'category'
|
|
|
|
|| $page_name == 'product'
|
|
|
|
|| $page_name == 'order'
|
|
|
|
) {
|
|
|
|
$page_name = 'homestore';
|
|
|
|
}
|
|
|
|
|
2015-10-23 14:46:01 +02:00
|
|
|
$publicite = BlockAds::getContentByHook(
|
|
|
|
$hook_name,
|
|
|
|
$page_name,
|
|
|
|
new DateTime(),
|
|
|
|
$this->getIdByPageName($page_name),
|
|
|
|
Context::getContext()->language->id
|
|
|
|
);
|
2015-11-17 10:12:52 +01:00
|
|
|
|
2015-10-23 14:46:01 +02:00
|
|
|
if ($publicite['link']) {
|
|
|
|
$this->smarty->assign(array(
|
|
|
|
'link' => $publicite['content'],
|
|
|
|
'id' => $publicite['id']
|
|
|
|
));
|
|
|
|
return $this->display(__FILE__, 'ads.tpl');
|
|
|
|
} else {
|
|
|
|
return $publicite['content'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayBoxPartenaire1($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayBoxPartenaire1');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayBoxPartenaire2($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayBoxPartenaire2');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayBoxPartenaire3($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayBoxPartenaire3');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayPubliciteTop($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayPubliciteTop');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayHomeRight1($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayHomeRight1');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayHomeRight2($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayHomeRight2');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookDisplayPubliciteRight($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayPubliciteRight');
|
|
|
|
}
|
2015-10-23 16:05:08 +02:00
|
|
|
|
2015-10-30 14:45:51 +01:00
|
|
|
public function hookDisplayPubliciteRightBottom($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayPubliciteRightBottom');
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:05:08 +02:00
|
|
|
public function hookDisplayPubliciteBottom($params)
|
|
|
|
{
|
|
|
|
return $this->runByHook('displayPubliciteBottom');
|
|
|
|
}
|
|
|
|
|
2015-08-12 14:10:25 +02:00
|
|
|
}
|