* @copyright 2012-2018 NetReviews SAS * @license NetReviews * @version Release: $Revision: 7.8.9 * @date 07/08/2019 * International Registered Trademark & Property of NetReviews SAS */ if (!defined('_PS_VERSION_')) { exit; } require_once _PS_MODULE_DIR_.'netreviews/NetReviewsModel.php'; class NetReviews extends Module { public $_html = null; public $iso_lang = null; public $id_lang = null; public $group_name = null; public $stats_product; public function __construct() { $this->name = 'netreviews'; $this->tab = 'advertising_marketing'; $this->version = '7.8.9'; $this->author = 'NetReviews'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Verified Reviews'); $this->description = $this->l('Collect service and product reviews with Verified Reviews. Display reviews on your shop and win the trust of your visitors, to increase your revenue.'); $this->secure_key = Tools::encrypt($this->name); $this->module_key = 'd63d28acbac0a249ec17b6394ac5a841'; if (self::isInstalled($this->name)) { $this->id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $this->iso_lang = pSQL(Language::getIsoById($this->id_lang)); } $this->confirmUninstall = sprintf($this->l('Are you sure you want to uninstall %s module?'), $this->displayName); $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.7.99.99'); if (isset($this->context)){ $this->current_shop_id = $this->context->shop->getContextShopID(); }else{ // _PS_VERSION_ < 1.4 $this->current_shop_id = ''; } if (Configuration::get('AV_MULTILINGUE', null, null, $this->current_shop_id) == 'checked') { $this->id_lang = $this->context->language->id; $this->iso_lang = pSQL(Language::getIsoById($this->id_lang)); $this->group_name = $this->getIdConfigurationGroup($this->iso_lang); } $this->all_multishops_reviews = false; $this->all_languages_reviews = false; // Retrocompatibility // if (version_compare(_PS_VERSION_, '1.5', '<') && version_compare(_PS_VERSION_, '1.4', '>=')) { // $this->initContext(); // } } public function install($keep = true) { if ($keep) { if (!($query = $this->createTables())) { $this->context->controller->errors[] = sprintf($this->l('SQL ERROR : %s | Query can\'t be executed. Maybe, check SQL user permissions.'), $query); } Configuration::updateValue('AV_IDWEBSITE', ''); Configuration::updateValue('AV_CLESECRETE', ''); Configuration::updateValue('AV_LIGHTWIDGET', '1'); // simple stars by default Configuration::updateValue('AV_MULTILINGUE', '0'); Configuration::updateValue('AV_MULTISITE', ''); Configuration::updateValue('AV_PROCESSINIT', ''); Configuration::updateValue('AV_ORDERSTATESCHOOSEN', ''); Configuration::updateValue('AV_DELAY', ''); Configuration::updateValue('AV_DELAY_PRODUIT', '0'); Configuration::updateValue('AV_GETPRODREVIEWS', ''); Configuration::updateValue('AV_DISPLAYPRODREVIEWS', ''); Configuration::updateValue('AV_CSVFILENAME', 'Export_NetReviews_01-01-1970-default.csv'); Configuration::updateValue('AV_SCRIPTFLOAT', ''); Configuration::updateValue('AV_SCRIPTFLOAT_ALLOWED', ''); Configuration::updateValue('AV_SCRIPTFIXE', ''); Configuration::updateValue('AV_SCRIPTFIXE_ALLOWED', ''); Configuration::updateValue('AV_GOUPINFO', ''); Configuration::updateValue('AV_URLCERTIFICAT', ''); Configuration::updateValue('AV_FORBIDDEN_EMAIL', ''); Configuration::updateValue('AV_CODE_LANG', ''); Configuration::updateValue('AV_SNIPPETSITETYPE', '3'); // Type of RS Configuration::updateValue('AV_DISPLAYSNIPPETSITE', ''); // RS enabled by defaut Configuration::updateValue('AV_RICHSNIPPETSWEBSITE', ''); // website has its own RS enabled by defaut Configuration::updateValue('AV_NBOFREVIEWS', '10'); Configuration::updateValue('AV_STARCOLOR', 'FFCD00'); Configuration::updateValue('AV_PRODUCTUNIGINFO', ''); Configuration::updateValue('AV_NBOPRODUCTS', ''); Configuration::updateValue('AV_MINAMOUNTPRODUCTS', ''); if (version_compare(_PS_VERSION_, '1.7', '>')) { Configuration::updateValue('AV_EXTRA_OPTION', '2'); //hookDisplayProductButtons } else { Configuration::updateValue('AV_EXTRA_OPTION', '0'); //hookExtraright } Configuration::updateValue('AV_ORDER_UPDATE', ''); Configuration::updateValue('AV_DISPLAYSTARPLIST', '0'); Configuration::updateValue('AV_TABSHOW', '1'); Configuration::updateValue('AV_FORMAT_IMAGE', ''); Configuration::updateValue('AV_TABNEWNAME', ''); Configuration::updateValue('AV_STARSHOMESHOW', '1'); Configuration::updateValue('AV_NRESPONSIVE', '0'); Configuration::updateValue('AV_HELPFULHIDE', ''); Configuration::updateValue('AV_MEDIAHIDE', ''); } if (version_compare(_PS_VERSION_, '1.5', '>=')) { if (parent::install() == false || !$this->registerHook('productTab') || !$this->registerHook('productTabContent') || !$this->registerHook('header') || !$this->registerHook('footer') || !$this->registerHook('displayProductButtons') || !$this->registerHook('displayProductPriceBlock') || !$this->registerHook('displayRightColumnProduct') || !$this->registerHook('displayLeftColumnProduct') || !$this->registerHook('displayProductExtraContent') || !$this->registerHook('displayBeforeBodyClosingTag') || !$this->registerHook('displayProductListReviews') || !$this->registerHook('displayFooterProduct') || !$this->registerHook('displayRightColumn') || !$this->registerHook('displayLeftColumn') || !$this->registerHook('ExtraNetreviews') || !$this->registerHook('TabcontentNetreviews') || !$this->registerHook('GlobalnoteNetreviews') || !$this->registerHook('CategorystarsNetreviews') || !$this->registerHook('CategorysummaryNetreviews') || !$this->registerHook('actionOrderStatusPostUpdate') || !$this->registerHook('actionValidateOrder')) return false; return true; } else { if (parent::install() == false || !$this->registerHook('productTab') || !$this->registerHook('productTabContent') || !$this->registerHook('header') || !$this->registerHook('footer') || !$this->registerHook('rightColumn') || !$this->registerHook('leftColumn') || !$this->registerHook('extraRight') || !$this->registerHook('extraLeft') || !$this->registerHook('OrderConfirmation') || !$this->registerHook('updateOrderStatus')) return false; return true; } } public function uninstall($keep = true) { $sql = 'SELECT name FROM '._DB_PREFIX_."configuration where name like 'AV_%'"; if ($results = Db::getInstance()->ExecuteS($sql)) { foreach ($results as $row) { Configuration::deleteByName($row['name']); } } if (!parent::uninstall() || ($keep && !$this->deleteTables()) || !$this->unregisterHook('productTab') || !$this->unregisterHook('productTabContent') || !$this->unregisterHook('header') || !$this->unregisterHook('footer') || !$this->unregisterHook('displayProductButtons') || !$this->unregisterHook('displayProductPriceBlock') || !$this->unregisterHook('displayRightColumnProduct') || !$this->unregisterHook('displayLeftColumnProduct') || !$this->unregisterHook('displayProductExtraContent') || !$this->unregisterHook('displayBeforeBodyClosingTag') || !$this->unregisterHook('displayProductListReviews') || !$this->unregisterHook('displayFooterProduct') || !$this->unregisterHook('displayRightColumn') || !$this->unregisterHook('displayLeftColumn') || !$this->unregisterHook('ExtraNetreviews') || !$this->unregisterHook('TabcontentNetreviews') || !$this->unregisterHook('GlobalnoteNetreviews') || !$this->unregisterHook('CategorystarsNetreviews') || !$this->unregisterHook('CategorysummaryNetreviews') || !$this->unregisterHook('actionOrderStatusPostUpdate') || !$this->unregisterHook('actionValidateOrder')) return false; return true; } public function createTables() { $sql = array(); $sql[] = 'DROP TABLE IF EXISTS '._DB_PREFIX_.'av_products_reviews;'; $sql[] = 'DROP TABLE IF EXISTS '._DB_PREFIX_.'av_products_average;'; $sql[] = 'DROP TABLE IF EXISTS '._DB_PREFIX_.'av_orders;'; $sql[] = 'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.'av_products_reviews ( `id_product_av` varchar(36) NOT NULL, `ref_product` varchar(20) NOT NULL, `rate` varchar(5) NOT NULL, `review` text NOT NULL, `customer_name` varchar(30) NOT NULL, `horodate` text NOT NULL, `horodate_order` text NOT NULL, `discussion` text NULL, `helpful` int(7) DEFAULT 0, `helpless` int(7) DEFAULT 0, `media_full` text NULL, `iso_lang` varchar(5) DEFAULT "0", `id_shop` int(2) DEFAULT 0, PRIMARY KEY (`id_product_av`,`iso_lang`,`id_shop`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'; $sql[] = 'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.'av_products_average ( `id_product_av` varchar(36) NOT NULL, `ref_product` varchar(20) NOT NULL, `rate` varchar(5) NOT NULL, `nb_reviews` int(10) NOT NULL, `horodate_update` text NOT NULL, `iso_lang` varchar(5) DEFAULT "0", `id_shop` int(2) DEFAULT 0, PRIMARY KEY (`ref_product`,`iso_lang`,`id_shop`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'; $sql[] = 'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.'av_orders ( `id_order` int(11) NOT NULL, `id_shop` int(2) DEFAULT 0, `flag_get` int(2) DEFAULT NULL, `horodate_get` varchar(25) DEFAULT NULL, `id_order_state` int(5) DEFAULT NULL, `iso_lang` varchar(5) DEFAULT "0", `horodate_now` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id_order`,`iso_lang`,`id_shop`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'; foreach ($sql as $query) { if (Db::getInstance()->execute($query) == false) { return $query; } } } public function reset() { if (!$this->uninstall(false)) { return false; } if (!$this->install(false)) { return false; } return true; } public function deleteTables() { return Db::getInstance()->execute(' DROP TABLE IF EXISTS `'._DB_PREFIX_.'av_orders`, `'._DB_PREFIX_.'av_products_reviews`, `'._DB_PREFIX_.'av_products_average`'); } /** * Load the configuration form */ public function getContent() { if (version_compare(_PS_VERSION_, '1.6', '<')) { $this->addFiles('avisverifies-style-back-old', 'css'); } $this->addFiles('avisverifies-admin', 'css'); if (!empty($_POST)) { $this->postProcess(); } if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 1 && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP)) { $this->_html .= $this->displayError($this->l('Multistore feature is enabled. Please choose above the store to configure.')); return $this->_html; } $o_av = new NetReviewsModel(); $nb_reviews = $o_av->getTotalReviews(); $nb_reviews_average = $o_av->getTotalReviewsAverage(); $nb_orders = $o_av->getTotalOrders(); $current_avisverifies_idwebsite = array(); $current_avisverifies_clesecrete = array(); $order_statut_list = OrderState::getOrderStates((int)Configuration::get('PS_LANG_DEFAULT')); $multisite = Configuration::get('AV_MULTISITE'); if (!empty($multisite)) { $idshop = $this->context->shop->getContextShopID(); } else { $idshop = null; // if multishop but only one shop enabled or non multishop } $current_avisverifies_idwebsite['root'] = Configuration::get('AV_IDWEBSITE', null, null, $idshop); $current_avisverifies_clesecrete['root'] = Configuration::get('AV_CLESECRETE', null, null, $idshop); $languages = Language::getLanguages(true); foreach ($languages as $lang) { $current_avisverifies_idwebsite[$lang['iso_code']] = ""; $current_avisverifies_clesecrete[$lang['iso_code']] = ""; $language_group_name = $this->getIdConfigurationGroup($lang['iso_code']); if (!Configuration::get('AV_IDWEBSITE'.$language_group_name, null, null, $idshop)) { Configuration::updateValue('AV_IDWEBSITE'.$language_group_name, '', false, null, $idshop); } elseif ($language_group_name) { $current_avisverifies_idwebsite[$lang['iso_code']] = Configuration::get('AV_IDWEBSITE'.$language_group_name, null, null, $idshop); } if (!Configuration::get('AV_CLESECRETE'.$language_group_name, null, null, $idshop)) { Configuration::updateValue('AV_CLESECRETE'.$language_group_name, '', false, null, $idshop); } elseif ($language_group_name) { $current_avisverifies_clesecrete[$lang['iso_code']] = Configuration::get('AV_CLESECRETE'.$language_group_name, null, null, $idshop); } } // update av_groupinfo Configuration::updateValue('AV_GOUPINFO', json_encode($current_avisverifies_idwebsite)); $keycheck = NetReviewsModel::getMultiShopValues("AV_GOUPINFO"); $keycheck_result = array(); $keycheck = json_encode(array_map("json_decode",$keycheck)); $keycheck = json_decode($keycheck,true); foreach ($keycheck as $k => $value_keycheck) { if($value_keycheck){ foreach ($value_keycheck as $lang_check => $value) { if ($lang_check != "root" && $value!=""){ $keycheck_result[] = $value; } } } } if (!empty($keycheck_result) && (count($keycheck_result) !== count(array_unique($keycheck_result)))){ $this->_html .= $this->displayError($this->l('Each idWebsite and key can be used only once, pleack check your current informations')); } if (version_compare(_PS_VERSION_, '1.5', '<') && version_compare(_PS_VERSION_, '1.4', '>=')) { global $currentIndex; $url_back = $currentIndex.'&configure=netreviews&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module=advertising_marketing&module_name=netreviews'; } elseif (version_compare(_PS_VERSION_, '1.5', '>=')) { $url_back = (($this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&tab_module='. $this->tab.'&conf=4&module_name='.$this->name)); } else { $url_back =""; } $use_image = false; $use_star_format_image = Configuration::get('AV_FORMAT_IMAGE', null, null, $idshop); if (version_compare(_PS_VERSION_, '1.4', '>=') && $use_star_format_image != '1') { $stars_file = 'avisverifies-stars-font.tpl'; } else { $stars_file = 'avisverifies-stars-image.tpl'; $use_image = true; } $demo_rate = 4.5; $average_rate_percent = array(); $average_rate_percent['floor'] = floor($demo_rate) - 1; $average_rate_percent['decimals'] = ($demo_rate - floor($demo_rate))*20; $customized_star_color = (Configuration::get('AV_STARCOLOR', null, null, $idshop))?Configuration::get('AV_STARCOLOR', null, null, $idshop):"FFCD00"; //default #FFCD00 if (version_compare(_PS_VERSION_, '1.6.1', '>=') || method_exists($this, 'getPossibleHooksList')) { $hook_list = $this->getPossibleHooksList(); }else{ if(version_compare(_PS_VERSION_, '1.5', '<')){ $currentidshop = null; }else{ $currentidshop = $this->context->shop->getContextShopID(); } $hook_list = $o_av->listRegisteredHooks($this->id,$currentidshop); } $this->smartyAssign(array( 'base_url' => __PS_BASE_URI__ , 'current_avisverifies_urlapi' => Configuration::get('AV_URLAPI', null, null, $idshop), 'current_lightwidget_checked' => Configuration::get('AV_LIGHTWIDGET', null, null, $idshop), 'current_multilingue_checked' => Configuration::get('AV_MULTILINGUE', null, null, $idshop), 'current_starproductlist_checked' => Configuration::get('AV_DISPLAYSTARPLIST', null, null, $idshop), 'current_snippets_website_global_checked' => Configuration::get('AV_SNIPPETSITETYPE', null, null, $idshop), 'current_snippets_site_checked' => Configuration::get('AV_DISPLAYSNIPPETSITE', null, null, $idshop), 'richSnippetsWebsite_checked' => Configuration::get('AV_RICHSNIPPETSWEBSITE', null, null, $idshop), 'avisverifies_nb_reviews' => Configuration::get('AV_NBOFREVIEWS', null, null, $idshop), 'avisverifies_stars_custom_color' => Configuration::get('AV_STARCOLOR', null, null, $idshop), 'productuniqueginfo_checked' => Configuration::get('AV_PRODUCTUNIGINFO', null, null, $idshop), 'customized_star_color' => $customized_star_color, 'avisverifies_nb_products' => Configuration::get('AV_NBOPRODUCTS', null, null, $idshop), 'avisverifies_amount_min_products' => Configuration::get('AV_MINAMOUNTPRODUCTS', null, null, $idshop), 'avisverifies_extra_option' => Configuration::get('AV_EXTRA_OPTION', null, null, $idshop), 'avisverifies_orders_doublecheck' => Configuration::get('AV_ORDER_UPDATE', null, null, $idshop), 'current_nresponsive_checked' => Configuration::get('AV_NRESPONSIVE', null, null, $idshop), 'current_hidehelpful_checked' => Configuration::get('AV_HELPFULHIDE', null, null, $idshop), 'current_hidemedia_checked' => Configuration::get('AV_MEDIAHIDE', null, null, $idshop), 'avisverifies_rename_tag' => Configuration::get('AV_TABNEWNAME', null, null, $idshop), 'tabshow_checked' => Configuration::get('AV_TABSHOW', null, null, $idshop), 'stars_image' => Configuration::get('AV_FORMAT_IMAGE', null, null, $idshop), 'starshome_checked' => Configuration::get('AV_STARSHOMESHOW', null, null, $idshop), 'current_avisverifies_idwebsite' => $current_avisverifies_idwebsite, 'current_avisverifies_clesecrete' => $current_avisverifies_clesecrete, 'version' => $this->version, 'version_ps' => _PS_VERSION_, 'order_statut_list' => $order_statut_list, 'languages' => $languages, 'debug_nb_reviews' => $nb_reviews['nb_reviews'], 'debug_nb_reviews_average' => $nb_reviews_average['nb_reviews_average'], 'debug_nb_orders_flagged' => $nb_orders['flagged']['nb'], 'debug_nb_orders_not_flagged' => $nb_orders['not_flagged']['nb'], 'debug_nb_orders_all' => $nb_orders['all']['nb'], 'av_path' => $this->_path, 'shop_name' => Configuration::get('PS_SHOP_NAME'), //(!empty($this->context->shop->name))?$this->context->shop->name:"", 'url_back' => $url_back, 'stars_dir' => _PS_ROOT_DIR_.'/modules/netreviews/views/templates/hook/sub/'.$stars_file, 'use_image' => $use_image, 'average_rate_percent' => $average_rate_percent, 'av_rate_percent_int' => ($demo_rate) ? round($demo_rate * 20) : 100, 'hook_list' => $hook_list )); $tpl = 'avisverifies-backoffice'; $this->_html .= $this->displayTemplate($tpl); return $this->_html; } /** * Save configuration form. */ private function postProcess() { if (Tools::isSubmit('submit_export')) { try { $o_av = new NetReviewsModel; $header_colums = 'id_order;reference;order_amount;email;firstname;lastname;date_order;payment_method;carrer;delay;id_product;category;description;ean13;upc;mpn;brand;product_url;image_product_url;order_state_id;order_state;iso_lang;id_shop'."\r\n"; $return_export = $o_av->export($header_colums, $this->context->shop->getContextShopID()); if (file_exists($return_export[2])) { $this->_html .= $this->displayConfirmation(sprintf($this->l('%s orders have been exported.'), $return_export[1]).' '.$this->l('Click here to download the file').''); } else { $this->_html .= $this->displayError($this->l('Writing on the server is not allowed. Please assign write permissions to the folder netreviews').$return_export[2]); } } catch (Exception $e) { $this->_html .= $this->displayError($e->getMessage()); } } if (Tools::isSubmit('submit_configuration')) { $id_website_current = trim(Tools::getValue('avisverifies_idwebsite')); $cle_secrete_current = trim(Tools::getValue('avisverifies_clesecrete')); Configuration::updateValue('AV_MULTILINGUE', Tools::getValue('avisverifies_multilingue'), false, null, $this->context->shop->getContextShopID()); Configuration::updateValue('AV_IDWEBSITE', $id_website_current, false, null, $this->context->shop->getContextShopID()); Configuration::updateValue('AV_CLESECRETE', $cle_secrete_current , false, null, $this->context->shop->getContextShopID()); Configuration::updateValue('AV_MULTISITE',$this->current_shop_id); if (Configuration::get('AV_MULTILINGUE', null, null, $this->context->shop->getContextShopID()) == 'checked') { $sql = ' SELECT name FROM '._DB_PREFIX_."configuration where (name like 'AV_GROUP_CONF_%' OR name like 'AV_IDWEBSITE_%' OR name like 'AV_CLESECRETE_%') AND id_shop = '".$this->context->shop->getContextShopID()."' "; $idshop_conf = true; if ($results = Db::getInstance()->ExecuteS($sql)) { foreach ($results as $row) { Configuration::deleteFromContext($row['name']); } } else { $idshop_conf = false; // if multishop but only one shop enabled or non multishop $sql_without_idshop = ' SELECT name FROM '._DB_PREFIX_."configuration where (name like 'AV_GROUP_CONF_%' OR name like 'AV_IDWEBSITE_%' OR name like 'AV_CLESECRETE_%')"; if ($results = Db::getInstance()->ExecuteS($sql_without_idshop)) { foreach ($results as $row) { Configuration::deleteFromContext($row['name']); } } } Configuration::updateValue('AV_MULTISITE', $idshop_conf); // in case that it's not multishop while configurated as multishop $languages = Language::getLanguages(true); $this->setIdConfigurationGroup($languages, $idshop_conf); } } if (Tools::isSubmit('submit_advanced')) { Configuration::updateValue('AV_LIGHTWIDGET', Tools::getValue('avisverifies_lightwidget'), false, null, $this->current_shop_id); Configuration::updateValue('AV_DISPLAYSNIPPETSITE', Tools::getValue('netreviews_snippets_site'), false, null, $this->current_shop_id); Configuration::updateValue('AV_SNIPPETSITETYPE', Tools::getValue('netreviews_snippets_website_global'), false, null, $this->current_shop_id); Configuration::updateValue('AV_RICHSNIPPETSWEBSITE', Tools::getValue('avisverifies_checkRichSnippetsWebsite_show'), false, null, $this->current_shop_id); Configuration::updateValue('AV_NBOFREVIEWS', Tools::getValue('avisverifies_nb_reviews'), false, null, $this->current_shop_id); Configuration::updateValue('AV_STARCOLOR', Tools::getValue('avisverifies_stars_custom_color'), false, null, $this->current_shop_id); Configuration::updateValue('AV_PRODUCTUNIGINFO', Tools::getValue('avisverifies_productuniqueginfo'), false, null, $this->current_shop_id); Configuration::updateValue('AV_NBOPRODUCTS', Tools::getValue('avisverifies_nb_products'), false, null, $this->current_shop_id); Configuration::updateValue('AV_MINAMOUNTPRODUCTS', Tools::getValue('avisverifies_amount_min_products'), false, null, $this->current_shop_id); Configuration::updateValue('AV_TABNEWNAME', Tools::getValue('avisverifies_rename_tag'), false, null, $this->current_shop_id); Configuration::updateValue('AV_EXTRA_OPTION', Tools::getValue('avisverifies_extra_option'), false, null, $this->current_shop_id); Configuration::updateValue('AV_ORDER_UPDATE', Tools::getValue('avisverifies_orders_doublecheck'), false, null, $this->current_shop_id); Configuration::updateValue('AV_DISPLAYSTARPLIST', Tools::getValue('avisverifies_star_productlist'), false, null, $this->current_shop_id); Configuration::updateValue('AV_TABSHOW', Tools::getValue('avisverifies_tab_show'), false, null, $this->current_shop_id); Configuration::updateValue('AV_FORMAT_IMAGE', Tools::getValue('avisverifies_stars_image'), false, null, $this->current_shop_id); Configuration::updateValue('AV_STARSHOMESHOW', Tools::getValue('avisverifies_starshome_show'), false, null, $this->current_shop_id); Configuration::updateValue('AV_HELPFULHIDE', Tools::getValue('avisverifies_hidehelpful'), false, null, $this->current_shop_id); Configuration::updateValue('AV_MEDIAHIDE', Tools::getValue('avisverifies_hidemedia'), false, null, $this->current_shop_id); Configuration::updateValue('AV_NRESPONSIVE', Tools::getValue('avisverifies_nresponsive'), false, null, $this->current_shop_id); } if (Tools::isSubmit('submit_addhooklist')) { if ( !$this->registerHook('productTab') || !$this->registerHook('productTabContent') || !$this->registerHook('header') || !$this->registerHook('footer') || !$this->registerHook('displayProductButtons') || !$this->registerHook('displayProductPriceBlock') || !$this->registerHook('displayRightColumnProduct') || !$this->registerHook('displayLeftColumnProduct') || !$this->registerHook('displayProductExtraContent') || !$this->registerHook('displayBeforeBodyClosingTag') || !$this->registerHook('displayProductListReviews') || !$this->registerHook('displayFooterProduct') || !$this->registerHook('displayRightColumn') || !$this->registerHook('displayLeftColumn') || !$this->registerHook('ExtraNetreviews') || !$this->registerHook('TabcontentNetreviews') || !$this->registerHook('GlobalnoteNetreviews') || !$this->registerHook('CategorystarsNetreviews') || !$this->registerHook('CategorysummaryNetreviews') || !$this->registerHook('actionOrderStatusPostUpdate') || !$this->registerHook('actionValidateOrder')) return false; return true; } if (Tools::isSubmit('submit_purge')) { $query_id_shop = ""; if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 1) { $query_id_shop = ' AND oav.id_shop = '.(int)$this->current_shop_id; } $query = ' SELECT oav.id_order, o.date_add as date_order,o.id_customer FROM '._DB_PREFIX_.'av_orders oav LEFT JOIN '._DB_PREFIX_.'orders o ON oav.id_order = o.id_order LEFT JOIN '._DB_PREFIX_.'order_history oh ON oh.id_order = o.id_order WHERE (oav.flag_get IS NULL OR oav.flag_get = 0)' .$query_id_shop; $orders_list = Db::getInstance()->ExecuteS($query); if (!empty($orders_list)) { foreach ($orders_list as $order) { /* Set orders as getted */ Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'av_orders SET horodate_get = "'.time().'", flag_get = 1 WHERE id_order = '.(int)$order['id_order']); } $this->_html .= $this->displayConfirmation(sprintf($this->l('The orders has been purged for %s'), $this->context->shop->name)); } else { $this->_html .= $this->displayError(sprintf($this->l('No orders to purged for %s'), $this->context->shop->name)); } } } /** * Allow to add the widget flottant code to the hook header in front office if configurated * * Return widget flottant code if configurated * * @return javascript string in hook header */ public function hookDisplayHeader() { $this->addFiles('avisverifies-style', 'css'); $this->addFiles('avisverifies-tpl', 'js'); $avisverifies_scriptfloat_allowed = Configuration::get('AV_SCRIPTFLOAT_ALLOWED'.$this->group_name, null, null, $this->current_shop_id); $av_scriptflottant = Configuration::get('AV_SCRIPTFLOAT'.$this->group_name, null, null, $this->current_shop_id); $widget_flottant_code = ""; if ((strpos(Tools::strtolower($av_scriptflottant), 'null') != true || Tools::strlen($av_scriptflottant) > 10) && $avisverifies_scriptfloat_allowed === "yes") { $widget_flottant_code .= "\n".Tools::stripslashes(html_entity_decode($av_scriptflottant)); } return $widget_flottant_code; } /** * Integration stars on category page used 3 hooks, * hookCategorystarsNetreviews (parent hook) * hookDisplayProductListReviews * hookDisplayProductPriceBlock @params[type]=before_price */ public function hookCategorystarsNetreviews($params) { $show_stars_home = Configuration::get('AV_STARSHOMESHOW', null, null, $this->current_shop_id); // 1 or null in defaut if ((property_exists($this->context->controller, 'php_self') && 'index' != $this->context->controller->php_self) || $show_stars_home != 0) { $id_product = (int)$params['product']['id_product']; $avisverifies_display_stars = Configuration::get('AV_DISPLAYSTARPLIST', null, null, $this->current_shop_id); if (!isset($id_product) || empty($id_product) || !isset($avisverifies_display_stars) || empty($avisverifies_display_stars)) { return ; } $o_av = new NetReviewsModel(); $stats_product = (!isset($this->stats_product) || empty($this->stats_product)) ? $o_av->getStatsProduct($id_product, $this->group_name, $this->current_shop_id) : $this->stats_product; if ($this->all_multishops_reviews || $this->all_languages_reviews){ // override rate & nb_reviews $language_group = ($this->all_languages_reviews)?null:$this->group_name; $shop_id_group = ($this->all_multishops_reviews)?null:$this->current_shop_id; $reviews = $o_av->getProductReviews($id_product, $language_group, $shop_id_group, 0, 1, 'horodate_DESC', 0, false); $num_reviews = count($reviews); if ($num_reviews < 1 || !$avisverifies_display_stars) { return ; } $somme_rate = 0; foreach ($reviews as $review) { $somme_rate += $review['rate']; } $stats_product['rate'] = $somme_rate / $num_reviews; $stats_product['nb_reviews'] = $num_reviews; } if (!isset($stats_product['nb_reviews']) || $stats_product['nb_reviews'] == 0) { return ; } $average_rate_percent = array(); $average_rate_percent['floor'] = floor($stats_product['rate']) - 1; $average_rate_percent['decimals'] = ($stats_product['rate'] - floor($stats_product['rate']))*20; $lang_id = (isset($this->context->language->id) && !empty($this->context->language->id))?(int)$this->context->language->id:1; if (version_compare(_PS_VERSION_, '1.5', '>=')) { $product = new Product((int)$id_product, false, $lang_id); }else{ $product = new Product((int)$id_product); } $product_name = is_array($product->name)?$product->name[$lang_id]:$product->name; $use_star_format_image = Configuration::get('AV_FORMAT_IMAGE', null, null, $this->current_shop_id); $customized_star_color = (Configuration::get('AV_STARCOLOR', null, null, $this->current_shop_id))?Configuration::get('AV_STARCOLOR', null, null, $this->current_shop_id):"FFCD00"; //default #FFCD00 $this->smartyAssign(array( 'av_nb_reviews' => $stats_product['nb_reviews'], 'av_rate' => $stats_product['rate'], 'average_rate_percent' => $average_rate_percent, 'av_rate_percent_int' => ($stats_product['rate']) ? round($stats_product['rate'] * 20) : 100, 'link_product' => (isset($params['product']['link'])?$params['product']['link']:''), 'use_star_format_image' => $use_star_format_image, 'average_rate' => round($stats_product['rate'], 1), 'product_name' => !empty($product_name)? $product_name: 'product name', 'product_description' => $product->description_short[$lang_id], 'customized_star_color' => $customized_star_color )); $tpl = 'avisverifies-categorystars'; return $this->displayTemplate($tpl); } } public function hookDisplayProductListReviews($params) { if (version_compare(_PS_VERSION_, '1.7', '<')) { return $this->hookCategorystarsNetreviews($params); } } public function hookDisplayProductPriceBlock($params) { if (version_compare(_PS_VERSION_, '1.7', '>')) { if ($params['type'] == "before_price") { return $this->hookCategorystarsNetreviews($params); } } } /** * Rich snippet positions: * AV_DISPLAYSNIPPETPRODUIT * Position 1 : Footer - Product * Position 2 : Extraright - AggregateRating (Default) * Position 3 : Extraright - Product * Position 4 : Tabcontent - AggregateRating * Position 5 : Tabcontent - Product * * AV_SNIPPETSITETYPE * 1 Microdata * 2 JSON-LD (product footer + site) * 3 Review-aggregate */ public function hookDisplayFooterProduct($params) { /* if (Configuration::get('AV_DISPLAYSNIPPETSITE', null, null, $this->current_shop_id) == '1' && Configuration::get('AV_DISPLAYSNIPPETPRODUIT', null, null, $this->current_shop_id) == '1') { //rich snippets actived $id_product = (int)Tools::getValue('id_product'); $o_av = new NetReviewsModel(); $stats_product = (!isset($this->stats_product) || empty($this->stats_product)) ? $o_av->getStatsProduct($id_product, $this->group_name, $this->current_shop_id) : $this->stats_product; $lang_id = (isset($this->context->language->id) && !empty($this->context->language->id))?(int)$this->context->language->id:1; $product = new Product((int)$id_product); $p_description = (isset($product->description_short[$lang_id]))?$product->description_short[$lang_id]:array_values($product->description_short)[0]; $product_description = ($p_description)?strip_tags($p_description):""; $url_page = NetReviewsModel::getUrlProduct($product->id, $lang_id); $url_image = NetReviewsModel::getUrlImageProduct($product->id, null, $lang_id); $sku = $product->reference; $mpn = $product->supplier_reference; $gtin_upc = (isset($product->upc) && !empty($product->upc))?$product->upc:''; $gtin_ean = $product->ean13; $product_price = $product->getPrice(true, null, 2); $product_name = is_array($product->name)?$product->name[$lang_id]:$product->name; $brand_name =''; $manufacturer = new Manufacturer($product->id_manufacturer, (int)$this->id_lang); if (isset($manufacturer->name)) { $brand_name = $manufacturer->name; } $this->smartyAssign(array( 'count_reviews' => !empty($stats_product)?$stats_product['nb_reviews']:false, 'average_rate' => !empty($stats_product)?round($stats_product['rate'], 1):false, 'product_id' => $id_product, 'product_name' => !empty($product_name)? $product_name: 'product name', 'product_description' => $product_description, 'product_price' => !empty($product_price)? $product_price: 0, 'product_quantity' => $product->quantity, 'product_url' => !empty($url_page)? $url_page: false, 'url_image' => !empty($url_image)? $url_image: false, 'sku' => !empty($sku)? $sku: false, 'mpn' => !empty($mpn)? $mpn: false, 'gtin_upc' => !empty($gtin_upc)? $gtin_upc: false, 'gtin_ean' => !empty($gtin_ean)? $gtin_ean: false, 'brand_name' => !empty($brand_name)? $brand_name: false, )); $tpl = 'avisverifies-product-snippets'; return $this->displayTemplate($tpl); } */ } /** * Allow to display the fixed widget */ public function hookDisplayFooter() { $av_scriptfixe_allowed = Configuration::get('AV_SCRIPTFIXE_ALLOWED'.$this->group_name, null, null, $this->current_shop_id); //$avisverifies_scriptfloat_allowed = Configuration::get('AV_SCRIPTFLOAT_ALLOWED'.$this->group_name, null, null, $this->current_shop_id); $av_scriptfixe_position = Configuration::get('AV_SCRIPTFIXE_POSITION'.$this->group_name, null, null, $this->current_shop_id); $av_scriptfixe = Configuration::get('AV_SCRIPTFIXE'.$this->group_name, null, null, $this->current_shop_id); //$av_scriptflottant = Configuration::get('AV_SCRIPTFLOAT'.$this->group_name, null, null, $this->current_shop_id); $widget_fix_av = ""; //$widget_flottant_code = ""; if ((strpos(Tools::strtolower($av_scriptfixe), 'null') != true || Tools::strlen($av_scriptfixe) > 10) && $av_scriptfixe_allowed === "yes" && $av_scriptfixe_position === 'footer') { $widget_fix_av = "\n\n
"; } /* if ((strpos(Tools::strtolower($av_scriptflottant), 'null') != true || Tools::strlen($av_scriptflottant) > 10) && $avisverifies_scriptfloat_allowed === "yes") { $widget_flottant_code .= "\n".Tools::stripslashes(html_entity_decode($av_scriptflottant)); }*/ return $widget_fix_av; } /** * allow to display a overview of a category, * {hook h='CategorysummaryNetreviews'} to be added in category.tpl */ public function hookCategorysummaryNetreviews($params) { // $av_idshop = $this->current_shop_id; // // $lang_id = (empty($this->id_lang))?1:$this->id_lang; // $current_page_name = $this->context->controller->php_self; // if (($current_page_name == 'manufacturer' || $current_page_name == 'category' )) { // // find the list of the id in a manufacturer // if ($current_page_name == 'manufacturer') { // $id_manufacturer=(int)Tools::getValue('id_manufacturer'); // $manu = new Manufacturer($id_manufacturer, $this->context->language->id); // $name_subject=$manu->name; // $description_subject = $manu->description; // $sql = 'SELECT id_product FROM '._DB_PREFIX_.'product where id_manufacturer="'.$id_manufacturer.'"'; // } elseif ($current_page_name == 'category') { // $id_category=(int)Tools::getValue('id_category'); // $cat = new Category($id_category, $this->context->language->id); // $name_subject=$cat->name; // $description_subject = $cat->description; // $sql = 'SELECT * FROM '._DB_PREFIX_.'category_product where id_category="'.$id_category.'"'; // } // $results = Db::getInstance()->ExecuteS($sql); // // predefine the stats of the reviews, contains the number and the total of the rates // $stats_product = array('nb_reviews'=>0,'somme'=>0); // $price_sum = 0; // $products_info = array(); // foreach ($results as $row) { // $id_product=(int)$row['id_product']; // // $products_info[$id_product]['name'] = $this->getProductName($id_product, $lang_id); // $products_info[$id_product]['price'] = round(Product::getPriceStatic($id_product), 2); // $price_sum += $products_info[$id_product]['price']; // $o_av = new NetReviewsModel(); // $reviews = $o_av->getProductReviews($id_product, $this->group_name, $av_idshop, false, 0); // foreach ($reviews as $review) { // // calculate the number of review and the total of the rates // $stats_product['nb_reviews']++; // $stats_product['somme'] = $stats_product['somme'] + $review['rate']; // } // } // if(isset($review)){ // $num_products = (count($results) > 0)? count($results):1; // $price_average = $price_sum / $num_products; // $average_rate_percent = array(); // $average_rate_percent['floor'] = floor($review['rate']) - 1; // $average_rate_percent['decimals'] = ($review['rate'] - floor($review['rate']))*20; // $use_star_format_image = Configuration::get('AV_FORMAT_IMAGE', null, null, $av_idshop); // if (version_compare(_PS_VERSION_, '1.4', '>=') && $use_star_format_image != '1') { // $stars_file = 'avisverifies-stars-font.tpl'; // } else { // $stars_file = 'avisverifies-stars-image.tpl'; // $use_image = true; // } // $brand = Configuration::get('PS_SHOP_NAME'); // // calcul de la moyen // if ($stats_product['nb_reviews'] > 0) { // $stats_product['rate'] = $stats_product['somme'] / $stats_product['nb_reviews']; // $this->smartyAssign(array( // 'modules_dir' => _MODULE_DIR_, // 'count_reviews' => $stats_product['nb_reviews'], // 'average_rate' => round($stats_product['rate'], 1), // 'average_rate_percent' => $average_rate_percent, // 'nom_category'=>strip_tags($name_subject), // 'description_category'=> !empty($description_subject)? strip_tags($description_subject): false, // 'page_name'=>$current_page_name, // 'price_average'=>$price_average, // 'stars_dir' => _PS_ROOT_DIR_.'/modules/netreviews/views/templates/hook/sub/'.$stars_file, // 'logo_lang' => $this->iso_lang, //$this->context->language->iso_code, // 'brand' => $brand, //$this->context->language->iso_code, // 'products_av'=> $products_info // )); // $tpl = 'avisverifies-category-summary'; // return $this->displayTemplate($tpl); // } // } // } } /** * allow to display a overview of the website, * {hook h='GlobalnoteNetreviews'} to be added in header.tpl */ public function HookGlobalnoteNetreviews() { $rate_site = Configuration::get('AV_RATE_SITE', null, null, $this->current_shop_id); $nb_site = Configuration::get('AV_AVIS_SITE', null, null, $this->current_shop_id); $horodate = Configuration::get('AV_HORODATE_LASTGET', null, null, $this->current_shop_id); $av_idwebsite = Configuration::get('AV_IDWEBSITE'.$this->group_name, null, null, $this->current_shop_id); $shop_name = Configuration::get('PS_SHOP_NAME'); $use_image = false; $ex_datas = array(); if (empty($rate_site) or empty($nb_site) or empty($horodate) or (($horodate + 86400) < time())) { $nb_site = null; $rate_site = null; $url = "https://cl.avis-verifies.com/".$this->iso_lang."/cache/".Tools::substr($av_idwebsite, 0, 1)."/".Tools::substr($av_idwebsite, 1, 1)."/".Tools::substr($av_idwebsite, 2, 1)."/".$av_idwebsite."/AWS/".$av_idwebsite."_infosite.txt"; $url ="https://cl.avis-verifies.com/fr/cache/5/b/2/5b242ef5-bb8a-73d4-21be-6fd5dc3b4b9b/AWS/5b242ef5-bb8a-73d4-21be-6fd5dc3b4b9b_infosite.txt"; $file_headers = @get_headers($url); if (strpos($file_headers[0], "200")) { $datas = NetReviewsModel::avFileGetContents($url); $ex_datas = explode(";", $datas); if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 1) { Configuration::updateValue('AV_HORODATE_LASTGET', time(), false, null, $this->current_shop_id); Configuration::updateValue('AV_AVIS_SITE', $ex_datas[0], false, null, $this->current_shop_id); Configuration::updateValue('AV_RATE_SITE', $ex_datas[1], false, null, $this->current_shop_id); } else { Configuration::updateValue('AV_HORODATE_LASTGET', time()); Configuration::updateValue('AV_AVIS_SITE', $ex_datas[0]); Configuration::updateValue('AV_RATE_SITE', $ex_datas[1]); } $nb_site = $ex_datas[0]; $rate_site = $ex_datas[1]; } } else { $use_star_format_image = Configuration::get('AV_FORMAT_IMAGE', null, null, $this->current_shop_id); if (version_compare(_PS_VERSION_, '1.4', '>=') && $use_star_format_image != '1') { $stars_file = 'avisverifies-stars-font.tpl'; } else { $stars_file = 'avisverifies-stars-image.tpl'; $use_image = true; } $average_rate_percent = array(); $average_rate_percent['floor'] = floor($rate_site) - 1; $average_rate_percent['decimals'] = ($rate_site - floor($rate_site))*20; $this->smartyAssign(array( 'av_site_rating_avis' => $nb_site, 'stars_dir' => _PS_ROOT_DIR_.'/modules/netreviews/views/templates/hook/sub/'.$stars_file, 'use_image' => $use_image, 'av_site_rating_rate' => round($rate_site, 1), 'shop_name' => $shop_name, 'average_rate_percent' => $average_rate_percent, 'modules_dir' => _MODULE_DIR_ )); $tpl = 'header_av_site'; return $this->displayTemplate($tpl); } } /** * * @param $params * @return string|void */ public function hookActionValidateOrder($params) { //$process_init = Configuration::get('AV_PROCESSINIT'); $id_website = configuration::get('AV_IDWEBSITE'.$this->group_name, null, null, $this->current_shop_id); $secret_key = configuration::get('AV_CLESECRETE'.$this->group_name, null, null, $this->current_shop_id); $code_lang = configuration::get('AV_CODE_LANG'.$this->group_name, null, null, $this->current_shop_id); $code_lang = (!empty($code_lang)) ? $code_lang : 'undef'; if (empty($id_website) || empty($secret_key)) { return; } $o_av = new NetReviewsModel(); if (version_compare(_PS_VERSION_, '1.5', '<')) { $id_order = Tools::getValue('id_order'); $order = new Order((int)($id_order)); $order_total = (100 * $order->total_paid); } else { $o_order = $params['order']; $id_order = $o_order->id; $order_total = ($o_order->total_paid) ? (100 * $o_order->total_paid) : 0; if (!empty($o_order->id_shop)) { $o_av->id_shop = $o_order->id_shop; } } if (isset($id_order) && !empty($id_order)) { $o_av->id_order = (int)$id_order; $o_av->iso_lang = pSQL(Language::getIsoById($this->id_lang)); //pSQL(Language::getIsoById($o_order->id_lang)); $o_av->saveOrderToRequest(); return ""; } } /** * This code is added for having possiblities of double check * if not all orders are registered */ public function hookActionOrderStatusPostUpdate($params) { $id_website = configuration::get('AV_IDWEBSITE'.$this->group_name, null, null, $this->current_shop_id); $secret_key = configuration::get('AV_CLESECRETE'.$this->group_name, null, null, $this->current_shop_id); $code_lang = configuration::get('AV_CODE_LANG'.$this->group_name, null, null, $this->current_shop_id); $code_lang = (!empty($code_lang)) ? $code_lang : 'undef'; if (empty($id_website) || empty($secret_key)) { return; } $double_check_orders = Configuration::get('AV_ORDER_UPDATE', null, null, $this->current_shop_id); if (isset($double_check_orders) && ($double_check_orders == "1")) { $o_av = new NetReviewsModel(); if (version_compare(_PS_VERSION_, '1.5', '<')) { $id_order = Tools::getValue('id_order'); // $order = new Order((int)($id_order)); } else { $id_order = (int)$params['id_order']; if (isset($params['cart']->id_shop) && !empty($params['cart']->id_shop)) { $o_av->id_shop = $params['cart']->id_shop; } } if (isset($id_order) && !empty($id_order)) { $o_av->id_order = (int)$id_order; $o_av->iso_lang = pSQL(Language::getIsoById($this->id_lang)); //pSQL(Language::getIsoById($o_order->id_lang)); $o_av->saveOrderToRequest(); return ""; } } } public function hookDisplayRightColumn() { $av_scriptfixe_allowed = Configuration::get('AV_SCRIPTFIXE_ALLOWED'.$this->group_name, null, null, $this->current_shop_id); $av_scriptfixe_position = Configuration::get('AV_SCRIPTFIXE_POSITION'.$this->group_name, null, null, $this->current_shop_id); $av_scriptfixe = Configuration::get('AV_SCRIPTFIXE'.$this->group_name, null, null, $this->current_shop_id); if ($av_scriptfixe_allowed != 'yes' || $av_scriptfixe_position != 'right') { return; } if ((strpos(Tools::strtolower($av_scriptfixe), 'null') != true || Tools::strlen($av_scriptfixe) > 10) && $av_scriptfixe_allowed === "yes") { return "\n\n