name.'/views/templates/hook/'.$hookname.'.tpl'; $this->smarty->assign($this->getWidgetVariables($hookname, $configuration)); return $this->fetch($template_file, $this->getCacheId()); } public function getWidgetVariables($hookname = null, array $configuration = array()) { $hookname = $hookname; $configuration = $configuration; return null; } /****************************************/ /************ / WIDGET 1.7 **************/ /****************************************/ public static function prestaboostContent($params) { return $params['return']; } public $actions_form = array('add', 'edit'); public $class_used = array( 'table' => array( 'PrestaBoostClass' ), 'dashboard' => array(), 'config' => array(), ); /* this is my fix for php < 5.3 to correct instance dynamic class with string */ public static function createDynInstance($class, $params = array()) { $reflection_class = new ReflectionClass($class); return $reflection_class->newInstanceArgs($params); } public function __construct() { $this->name = 'prestaboost'; $this->tab = 'front_office_features'; $this->version = '4.0.5'; $this->author = 'Prestaboost'; $this->module_key = '353f99305ded8f74983b937500211e55'; $this->bootstrap = true; $this->need_instance = 0; parent::__construct(); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->displayName = $this->l('PrestaBoost'); $this->description = $this->l('Add popups in your store and customize to your liking'); $this->confirmUninstall = $this->l('Warning ! This action definitely uninstall this module !'); $this->cc = 'configure='.$this->name; $this->pp_conf = 'index.php?tab=AdminModules&'.$this->cc.'&token='.Tools::getValue('token'); $this->configurations = array( $this->name.'_token' => md5($this->genererMDP(32)._COOKIE_KEY_), ); } public function postProcess() { $update_process = false; $errors = array(); $warnings = array(); $output = ''; if ((int)Tools::getIsset('success')) { $output .= ' '; } if ((int)Tools::getIsset('undo') || (int)Tools::getIsset('error')) { $output .= ' '; } foreach ($this->class_used['table'] as $object_model) { $pp = $this->pp_conf.'&class='.$object_model; if (Tools::getValue('class') == $object_model) { $definition = ObjectModel::getDefinition($object_model); if (Tools::isSubmit('status'.$definition['table'])) { $process_model = self::createDynInstance($object_model); if (!$process_model->changeState((int)Tools::getValue($definition['primary']))) { $errors[] = $this->l('Could not change status.'); } else { Tools::redirectAdmin($pp.'&success'); } $update_process = true; } if (Tools::isSubmit('newsletter'.$definition['table'])) { $process_model = self::createDynInstance($object_model); if (!$process_model->changeNewsletter((int)Tools::getValue($definition['primary']))) { $errors[] = $this->l('Could not change newsletter.'); } else { Tools::redirectAdmin($pp.'&success'); } $update_process = true; } if (Tools::isSubmit('delete'.$definition['table'])) { $process_model = self::createDynInstance( $object_model, array((int)Tools::getValue($definition['primary'])) ); if (!$process_model->delete()) { $errors[] = $this->l('Could not delete.'); } else { Tools::redirectAdmin($pp.'&success'); } $update_process = true; } if (Tools::isSubmit('submitBulkdelete'.$definition['table'])) { if (Tools::getValue($definition['table'].'Box')) { foreach (Tools::getValue($definition['table'].'Box') as $id) { $process_model = self::createDynInstance($object_model, array((int)$id)); if (!$process_model->delete()) { $errors[] = sprintf($this->l('Could not delete %1$s'), $id); } } if (!count($errors) > 0) { Tools::redirectAdmin($pp.'&success'); } } $update_process = true; } foreach ($this->actions_form as $action) { if (Tools::isSubmit($action)) { if (!Tools::getValue('title_'.(int)$this->context->language->id)) { $errors[] = $this->l('The title must be specified'); } $content = Tools::getValue('content_'.(int)$this->context->language->id); if (!$content) { $errors[] = $this->l('The content or introduction must be specified'); } if (!Tools::getValue('date_start')) { $errors[] = $this->l('The date start must be specified'); } if (!Tools::getValue('date_stop')) { $errors[] = $this->l('The date stop must be specified'); } if (!count($errors)) { switch ($action) { case 'add': $process_model = self::createDynInstance($object_model); $process_model->copyFromPost(); if ($process_model->add()) { Tools::redirectAdmin($pp.'&success'); } break; case 'edit': $process_model = self::createDynInstance( $object_model, array((int)Tools::getValue($definition['primary'])) ); $process_model->copyFromPost(); if ($process_model->update()) { Tools::redirectAdmin( $pp.'&'.$definition['primary'].'='.(int)Tools::getValue( $definition['primary'] ).'&update'.$this->name.'&success' ); } break; } $update_process = true; } } } } } if (count($errors) > 0) { $output .= $this->displayError($errors); } if (count($warnings) > 0) { $output .= $this->displayWarning($warnings); } if ($output != '') { return $output; } if ($update_process) { return $this->displayConfirmation($this->l('Settings updated successfully')); } else { return null; } } public function getContent() { $pathM = AdminController::$currentIndex.'&'.$this->cc.'&token='.Tools::getAdminTokenLite('AdminModules'); $this->context->controller->addCSS($this->_path.'views/css/prestaboost.css'); if (!Tools::getValue('class')) { Tools::redirectAdmin($pathM.'&class=PrestaBoostClass'); } $output = ''; $output .=''; $output .=''; $output .= $this->postProcess(); $output .= $this->displayContent(); return $output; } public function displayContent() { $output = ''; if (Tools::getValue('class') && in_array(Tools::getValue('class'), $this->class_used['table'])) { $current_class = Tools::getValue('class'); if (!class_exists($current_class)) { $output .= $this->displayError($this->l('This class doesn\'t exists: ').$current_class); } else { $object_model = self::createDynInstance($current_class, array()); if (is_object($object_model)) { $definition_lang = $object_model->definitionLang(); if (!Tools::isSubmit('add') && !Tools::isSubmit('edit') && !Tools::getIsset('add'.$definition_lang['tableName']) && !Tools::getIsset('update'.$definition_lang['tableName']) ) { $output .= $object_model->displayList(); } if (Tools::getIsset('add'.$definition_lang['tableName']) || Tools::isSubmit('add')) { $output .= $object_model->displayForm('add'); } if (Tools::getIsset('update'.$definition_lang['tableName']) || Tools::isSubmit('edit')) { $output .= $object_model->displayForm('edit'); } } } } return $output; } public function isOkDisplay() { $id_prestaboost = (int)PrestaBoostClass::getIdFrontPopupPreFiltered(); if ((int)$id_prestaboost > 0) { $prestaboost = new PrestaBoostClass((int)$id_prestaboost, (int)$this->context->language->id); $popup_hash = md5( $prestaboost->id .$prestaboost->date_start .$prestaboost->date_stop .$prestaboost->delay .$prestaboost->expire .$prestaboost->expire_ratio .$prestaboost->theme .$prestaboost->restriction_rules .$prestaboost->restriction_pages .$prestaboost->footer .$prestaboost->title .$prestaboost->content .$prestaboost->newstitle .$prestaboost->boost_colorpicker_content .$prestaboost->boost_colorpicker_modal .$prestaboost->boost_colorpicker_btn .$prestaboost->boost_colorpicker_btn_border .$prestaboost->boost_opacity_content .$prestaboost->boost_opacity_modal .$prestaboost->boost_opacity_btn ); if (!isset($_COOKIE['PrestaBoostCookie'.$popup_hash])) { setcookie( 'PrestaBoostCookie'.$popup_hash, '1', (time() + ((int)$prestaboost->expire_ratio * (int)$prestaboost->expire)) ); parent::_clearCache('header.tpl'); return (int)$id_prestaboost; } } } public function hookDisplayHeader() { if ($id_prestaboost = $this->isOkDisplay()) { $prestaboost = new PrestaBoostClass((int)$id_prestaboost, (int)$this->context->language->id); $this->context->controller->addCss($this->_path.'views/css/bootstrap-modal.css'); $this->context->controller->addCSS($this->_path.'views/css/theme-'.$prestaboost->theme.'.css', 'all'); $this->context->controller->addJS($this->_path.'views/js/prestaboost-popup.js'); } } public function hookDisplayTop() { if ($id_prestaboost = $this->isOkDisplay()) { return $this->displayPopup((int)$this->context->language->id, (int)$id_prestaboost); } } public function hookDisplayBeforeBodyClosingTag() { if ($id_prestaboost = $this->isOkDisplay()) { return $this->displayPopup((int)$this->context->language->id, (int)$id_prestaboost); } } public static function isNotRestrictionPage($restriction_rules, $restriction_pages) { $urls = preg_split("/\r/", $restriction_pages); $urls_ok = array(); $restriction_rules = (int)$restriction_rules; $url_current = Tools::getCurrentUrlProtocolPrefix().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; foreach ($urls as $url) { $url = trim($url); if (preg_match('/^(http|https):\/\/*/i', $url)) { $urls_ok[] = $url; } } $return = null; switch ($restriction_rules) { case 0: // on all pages $return = true; break; case 1: // on all pages, except urls_ok if (in_array($url_current, $urls_ok)) { $return = false; } else { $return = true; } break; case 2: // only on pages in urls_ok if (in_array($url_current, $urls_ok)) { $return = true; } else { $return = false; } break; } return $return; } public function displayFixJSConfirmDuplicate() { $pathM = AdminController::$currentIndex.'&'.$this->cc.'&token='.Tools::getAdminTokenLite('AdminModules'); $urlSupp = '&class=PrestaBoostClass&duplicateprestaboost'; return ' '; } public function displayPopup($id_lang, $id_prestaboost = 0) { $prestaboost = new PrestaBoostClass((int)$id_prestaboost, (int)$id_lang); $this->context->controller->addCSS($this->_path.'views/css/theme-'.$prestaboost->theme.'.css', 'all'); $this->smarty->assign(array( 'adminPreview' => true, 'id_lang' => (int)$id_lang, 'PrestaBoost' => $prestaboost )); // permet d'échaper tout le contenu html / js if (!isset($this->context->smarty->registered_plugins['function']['PrestaBoostContent'])) { smartyRegisterFunction( $this->context->smarty, 'function', 'PrestaBoostContent', array('PrestaBoost', 'prestaboostContent') ); } parent::_clearCache($prestaboost->theme.'.tpl'); return $this->display(__FILE__, $prestaboost->theme.'.tpl'); } public static function scanThemeTpl() { $return = array(); foreach (glob(dirname(__FILE__).'/views/templates/hook/*.{tpl}', GLOB_BRACE) as $file) { if (!is_dir($file)) { $return[] = array( 'id' => basename($file, '.tpl'), 'name' => basename($file, '.tpl') ); } } return $return; } private function genererMDP($longueur = 16) { $mdp = ''; $possible = 'abcdfghijklmnopqrstuvwxyz012346789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $longueur_max = Tools::strlen($possible); if ($longueur > $longueur_max) { $longueur = $longueur_max; } $i = 0; while ($i < $longueur) { $mdp .= Tools::substr($possible, mt_rand(0, $longueur_max - 1), 1); $i++; } return $mdp; } public function displayError($error) { $output = '