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'); } public function createAds() { $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(); } } 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) { $idTab = Tab::getIdFromClassName($tabClass); if ($idTab != 0) { $tab = new Tab($idTab); $tab->delete(); return true; } return true; } 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; } } public function runByHook($hook_name) { $page_name = Dispatcher::getInstance()->getController(); return BlockAds::getContentByHook( $hook_name, $page_name, new DateTime(), $this->getIdByPageName($page_name), Context::getContext()->language->id ); } public function hookDisplayBoxPartenaire1($params) { return $this->runByHook('displayBoxPartenaire1'); } public function hookDisplayBoxPartenaire2($params) { return $this->runByHook('displayBoxPartenaire2'); } public function hookDisplayBoxPartenaire3($params) { return $this->runByHook('displayBoxPartenaire3'); } } ?>