name = 'lgcomments';
$this->tab = 'advertising_marketing';
$this->version = '1.6.0';
$this->author = 'Línea Gráfica';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.7');
$this->module_key = '7a311a563a0daa4a8636f6a5ec27c0e6';
$this->bootstrap = true;
$this->is_configurable = true;
$this->initContext();
parent::__construct();
$this->displayName = $this->l('Store Reviews, Product Reviews and Google Rich Snippets');
$this->description = $this->l('Get your own system of reviews about your store and products.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
$this->id_lang = (int)Context::getContext()->language->id;
$this->id_lang = (int)Context::getContext()->language->id;
$this->iso_lang = pSQL(Language::getIsoById($this->id_lang));
$this->stars = LGUtils::getStarsConfig($this);
$this->store_widget = LGUtils::getStoreWidgetConfig($this);
if (version_compare(_PS_VERSION_, '1.7.0', '>=')) {
$this->context->smarty->assign(array(
'content_dir' => _MODULE_DIR_ . $this->name,
));
}
}
/* Retrocompatibility 1.4/1.5 */
private function initContext()
{
$this->context = Context::getContext();
}
public function install()
{
include(dirname(__FILE__) . '/sql/install.php');
if (substr_count(_PS_VERSION_, '1.6') > 0) {
$tab_type = 1;
} else {
$tab_type = 2;
}
// Default value
$default_values = array(
'tab_type' => $tab_type,
'extraright_css_config' => LGUtils::getExtraRightCSSConfig('vertical'),
'subject_cron' => $this->l('The opinion requests have been sent correctly'),
'subject_newreviews' => $this->l('You have received new reviews'),
);
if (!parent::install() ||
!$this->registerHook('header') ||
!$this->registerHook('backOfficeHeader') ||
!$this->registerHook('footer') ||
!$this->registerHook('productTab') ||
!$this->registerHook('productTabContent') ||
!$this->registerHook('displayFooterProduct') ||
!$this->registerHook('extraRight') ||
!$this->registerHook('displayProductListReviews') ||
!$this->registerHook('displayHome') ||
!$this->registerHook('displayCustomerAccount') ||
!$this->registerHook('displayLgStoreCommentSlider') ||
!$this->installModuleTab('AdminLGCommentsStore', $this->l('Store reviews')) ||
!$this->installModuleTab('AdminLGCommentsProducts', $this->l('Products reviews')) ||
!LGUtils::createDefaultConfig($default_values) ||
!LGUtils::createDefaultData() ||
!LGUtils::createDefaultMetas()
) {
return false;
}
if (version_compare(_PS_VERSION_, '1.7.0', '>=')) {
if (!$this->registerHook('actionFrontControllerSetMedia')) {
return false;
}
}
return true;
}
public function hookCustomerAccount()
{
if (version_compare(_PS_VERSION_, '1.7.0', '>=')) {
return $this->display(__FILE__, 'views/templates/front/account_button_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/front/account_button.tpl');
}
}
public function uninstall()
{
include(dirname(__FILE__) . '/sql/uninstall.php');
$sql = 'SELECT `id_tab` FROM `' . _DB_PREFIX_ . 'tab` WHERE `module` = "' . pSQL($this->name) . '"';
$result = Db::getInstance()->ExecuteS($sql);
if ($result && count($result)) {
foreach ($result as $tabData) {
$tab = new Tab($tabData['id_tab']);
if (Validate::isLoadedObject($tab)) {
$tab->delete();
}
}
}
if (substr_count(_PS_VERSION_, '1.6') > 0) {
$id_meta = Db::getInstance()->getValue(
'SELECT id_meta ' .
'FROM ' . _DB_PREFIX_ . 'meta ' .
'WHERE page = "module-lgcomments-reviews"'
);
Db::getInstance()->Execute(
'DELETE FROM ' . _DB_PREFIX_ . 'meta WHERE id_meta = ' . (int)$id_meta
);
Db::getInstance()->Execute(
'DELETE FROM ' . _DB_PREFIX_ . 'meta_lang WHERE id_meta = ' . (int)$id_meta
);
Db::getInstance()->Execute(
'DELETE FROM ' . _DB_PREFIX_ . 'theme_meta WHERE id_meta = ' . (int)$id_meta
);
}
return parent::uninstall();
}
private function installModuleTab($class, $name)
{
$sql = 'SELECT `id_tab` FROM `' . _DB_PREFIX_ . 'tab` WHERE `class_name` = "AdminCatalog"';
$tabParent = (int)(Db::getInstance()->getValue($sql));
if (!is_array($name)) {
$name = self::getMultilangField($name);
}
$tab = new Tab();
$tab->name = $name;
$tab->class_name = $class;
$tab->module = $this->name;
$tab->id_parent = $tabParent;
return $tab->save();
}
private static function getMultilangField($field)
{
$languages = Language::getLanguages();
$res = array();
foreach ($languages as $lang) {
$res[$lang['id_lang']] = $field;
}
return $res;
}
private function formatBootstrap($text)
{
$text = str_replace('