* @copyright 2013 WebInColor * @version 2.8 * @link http://www.webincolor.fr/ * @since File available since Release 1.0 */ if (!defined('_PS_VERSION_')) exit; class Ekomi extends Module { private $_html = ''; private $_postErrors = array(); public $_ekomi_object; public $id_lang; public $iso_lang; function __construct() { $this->name = 'ekomi'; $this->tab = 'advertising_marketing'; $this->author = 'Web In Color'; $this->version = '2.8'; $this->need_instance = 0; $this->module_key = '0fbd74e72a982dfbb3ee49f3ccec117a'; parent::__construct(); $this->displayName = $this->l('eKomi'); $this->description = $this->l('Adds an eKomi block, Ekomi product reviews'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (self::isInstalled($this->name)) { $this->id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $this->iso_lang = pSQL(Language::getIsoById($this->id_lang)); /* Check Mail Directory */ if (!is_dir('../modules/'.$this->name.'/mails/'.$this->iso_lang.'/')) $this->warning .= $this->l('directory').' "'.$this->iso_lang.'" does not exist '.'../modules/'.$this->name.'/mails/'.$this->iso_lang.'/'; } if($this->getVersion() > 1.4) $this->default_hook = 'displayFooter'; else $this->default_hook = 'footer'; //including Ekomi Class $path = dirname(__FILE__); if (strpos(__FILE__, 'Module.php') !== false) $path .= '/../modules/'.$this->name; if($this->getVersion() > 1.4) include_once($path.'/lib/ekomi_class.php'); else include_once($path.'/lib/ekomi_class_backward.php'); /* Backward compatibility */ if (_PS_VERSION_ < '1.5' AND _PS_VERSION_ >= '1.4') require(_PS_MODULE_DIR_.$this->name.'/backward_compatibility/backward.php'); // Retrocompatibility $this->initContext(); } // Retrocompatibility 1.4/1.5 private function initContext() { if(!$this->context->shop->id) $this->context->shop->id = 1; } public function install() { include(dirname(__FILE__).'/sql/install.php'); foreach ($sql as $s) if (!Db::getInstance()->execute($s)) return false; if($this->getVersion() > 1.4) return (parent::install() AND $this->registerHook('displayFooter') AND $this->registerHook('displayHeader') AND $this->registerHook('actionOrderStatusUpdate') AND $this->registerHook('displayProductTab') AND $this->registerHook('displayProductTabContent')); else return (parent::install() AND $this->registerHook('footer') AND $this->registerHook('header') AND $this->registerHook('updateOrderStatus') AND $this->registerHook('productTab') AND $this->registerHook('productTabContent')); } public function uninstall() { include(dirname(__FILE__).'/sql/uninstall.php'); foreach ($sql as $s) if (!Db::getInstance()->execute($s)) return false; if (!parent::uninstall()) return false; return true; } public function getVersion(){ if(_PS_VERSION_ > 1.3 AND _PS_VERSION_ <= 1.4) return 1.4; if(_PS_VERSION_ > 1.4 AND _PS_VERSION_ >= 1.6) return 1.5; return 1.3; } public function fetchTemplate($path, $name, $extension = false) { return $this->display(__FILE__,$path.$name.'.'.($extension ? $extension : 'tpl')); } public function getContent() { $ekomiObj = EkomiObject::getByIdShop($this->context->shop->id); if(!Validate::isLoadedObject($ekomiObj)) Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'ekomi`(`id_ekomi`,`id_shop`,`display_block`,`display_reviews`,`picto`,`sending`,`range`,`hook`,`id_state`) VALUES (\'\','.$this->context->shop->id.',0,0,\'1-star-yellow\',0,0,\''.$this->default_hook.'\',5);'); if($this->getVersion() > 1.4) $this->_html = ''; else $this->_html = ''; $this->_html .= '
'; if($this->getVersion() <= 1.4) $this->_html .= ''; if(!extension_loaded('soap')) $this->_html .= $this->displayError($this->l('php-soap extension is not loaded. Thank you to contact your network administrator.')); if (Tools::isSubmit('submitEkomi')) { $ekomiObj = EkomiObject::getByIdShop($this->context->shop->id); $ekomiObj->copyFromPost(); $ekomiObj->update(); if($this->getVersion() > 1.4) { if ($this->isRegisteredInHook('displayFooter')) $this->unregisterHook('displayFooter'); if ($this->isRegisteredInHook('displayLeftColumn')) $this->unregisterHook('displayLeftColumn'); if ($this->isRegisteredInHook('displayRightColumn')) $this->unregisterHook('displayRightColumn'); } else { if ($this->isRegisteredInHook('footer')) $this->unregisterHook('footer'); if ($this->isRegisteredInHook('leftColumn')) $this->unregisterHook('leftColumn'); if ($this->isRegisteredInHook('rightColumn')) $this->unregisterHook('rightColumn'); } $this->registerHook(Tools::getValue('hook')); $this->_html .= '