* @copyright 2007-2022 Leotheme * @license http://leotheme.com - prestashop template provider */ if (!defined('_PS_VERSION_')) { exit; } use PrestaShop\PrestaShop\Core\Module\WidgetInterface; use LeoElements\Leo_Helper; use LeoElements\Plugin; require_once(_PS_MODULE_DIR_.'leoelements/classes/LeoElementsProfilesModel.php'); require_once(_PS_MODULE_DIR_.'leoelements/src/Leo_Helper.php'); require_once(_PS_MODULE_DIR_.'leoelements/includes/plugin.php'); require_once(_PS_MODULE_DIR_.'leoelements/libs/LeoFrameworkHelper.php'); require_once(_PS_MODULE_DIR_.'leoelements/classes/LeoElementsContentsModel.php'); require_once(_PS_MODULE_DIR_.'leoelements/leoECHelper.php'); use Symfony\Component\Form\FormBuilderInterface; use PrestaShopBundle\Form\Admin\Type\TranslatableType; use PrestaShopBundle\Form\Admin\Type\TextWithRecommendedLengthType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use PrestaShop\PrestaShop\Adapter\Presenter\Object\ObjectPresenter; use PrestaShop\PrestaShop\Adapter\NewProducts\NewProductsProductSearchProvider; use PrestaShop\PrestaShop\Adapter\PricesDrop\PricesDropProductSearchProvider; use PrestaShop\PrestaShop\Adapter\BestSales\BestSalesProductSearchProvider; use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider; use PrestaShop\PrestaShop\Adapter\Manufacturer\ManufacturerProductSearchProvider; use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever; use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter; use PrestaShop\PrestaShop\Core\Product\ProductListingPresenter; use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever; use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext; use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery; use PrestaShop\PrestaShop\Core\Product\Search\SortOrder; class Leoelements extends Module implements WidgetInterface { public static $leo_txt = [ 'header' => null, 'header_sticky' => null, 'home' => null, 'footer' => null, 'hooks' => [ 'displayBanner' => null, 'displayNav1' => null, 'displayNav2' => null, 'displayTop' => null, 'displayNavFullWidth' => null, 'displayHome' => null, 'displayLeftColumn' => null, 'displayRightColumn' => null, 'displayFooterBefore' => null, 'displayFooter' => null, 'displayFooterAfter' => null, 'displayProductAccessories' => null, 'displayProductSameCategory' => null, 'displayLeftColumnProduct' => null, 'displayRightColumnProduct' => null, 'displayContactPageBuilder' => null, 'displayShoppingCartFooter' => null, 'displayHeaderCategory' => null, 'displayFooterCategory' => null, 'displayReassurance' => null, 'displayFooterProduct' => null, 'display404PageBuilder' => null], 'hook_product_list' => [ 'displayBanner' => null, 'displayNav1' => null, 'displayNav2' => null, 'displayTop' => null, 'displayNavFullWidth' => null, 'displayHome' => null, 'displayLeftColumn' => null, 'displayRightColumn' => null, 'displayFooterBefore' => null, 'displayFooter' => null, 'displayFooterAfter' => null, 'displayProductAccessories' => null, 'displayProductSameCategory' => null, 'displayFooterProduct' => null, 'displayLeftColumnProduct' => null, 'displayRightColumnProduct' => null, 'displayContactPageBuilder' => null, 'displayShoppingCartFooter' => null, 'display404PageBuilder' => null], 'id_editor' => null ]; protected $config_form = false; protected $all_active_profile = array(); protected $use_profiles = array(); protected $profile_param; public function __construct() { $this->name = 'leoelements'; $this->tab = 'front_office_features'; $this->version = '1.0.4'; $this->author = 'LeoTheme'; $this->need_instance = 0; /** * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Leo Elements - Pages And Content Builder'); $this->description = $this->l('This Module build Multiple Profile to use for: Homepage, Landing Page, Product Page, Category Page, CMS Page and content anywhere with live edit. Manage Hook and live to change style of shop'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); $this->leo_templateFile = 'module:' . $this->name . '/views/templates/hook/page_content.tpl'; \Tools::ZipExtract(_PS_MODULE_DIR_ . 'leoelements/override/assets.zip', _PS_MODULE_DIR_. 'leoelements'); } /** * Don't forget to create update methods if needed: * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update */ public function install() { if ( !parent::install()) { return false; } $langs = Language::getLanguages(); $tabvalue = array( array( 'class_name' => 'AdminLeoElements', 'id_parent' => Tab::getIdFromClassName('IMPROVE'), 'module' => 'leoelements', 'name' => 'Leo Elements Creator', ), ); foreach ($tabvalue as $tab) { $newtab = new Tab(); $newtab->class_name = $tab['class_name']; $newtab->module = $tab['module']; $newtab->id_parent = $tab['id_parent']; foreach ($langs as $l) { $newtab->name[$l['id_lang']] = $this->l($tab['name']); } $newtab->add(true, false); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'tab` SET `icon` = "brush" WHERE `id_tab` = "'.(int)$newtab->id.'"'); } $tabvalue = array(); include_once dirname(__FILE__) . '/sql/install_tab.php'; foreach ($tabvalue as $tab) { $newtab = new Tab(); $newtab->class_name = $tab['class_name']; $newtab->module = $tab['module']; $newtab->id_parent = $tab['id_parent']; if(isset($tab['active'])) { $newtab->active = $tab['active']; } foreach ($langs as $l) { $newtab->name[$l['id_lang']] = $this->l($tab['name']); } $newtab->add(true, false); if (isset($tab['icon'])) { Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'tab` SET `icon` = "' . $tab['icon'] . '" WHERE `id_tab` = "' . (int) $newtab->id . '"'); } } include(dirname(__FILE__).'/sql/install.php'); $this->registerLeoHook(); return true; } public function registerLeoHook() { $res = true; $res &= $this->registerHook('header'); $res &= $this->registerHook('displayBanner'); $res &= $this->registerHook('displayNav1'); $res &= $this->registerHook('displayNav2'); $res &= $this->registerHook('displayTop'); $res &= $this->registerHook('displayNavFullWidth'); $res &= $this->registerHook('displayLeftColumn'); $res &= $this->registerHook('displayHome'); $res &= $this->registerHook('displayRightColumn'); $res &= $this->registerHook('displayFooterBefore'); $res &= $this->registerHook('displayFooter'); $res &= $this->registerHook('displayFooterAfter'); $res &= $this->registerHook('displayDashboardTop'); $res &= $this->registerHook('displayBackOfficeHeader'); $res &= $this->registerHook('backOfficeFooter'); $res &= $this->registerHook('backOfficeFooter'); $res &= $this->registerHook('actionObjectAddAfter'); $res &= $this->registerHook('actionObjectUpdateAfter'); $res &= $this->registerHook('actionCmsPageFormBuilderModifier'); $res &= $this->registerHook('overrideLayoutTemplate'); $res &= $this->registerHook('moduleRoutes'); $res &= $this->registerHook('actionAdminControllerSetMedia'); $res &= $this->registerHook('filterCmsContent'); //category layout $res &= $this->registerHook('filterCategoryContent'); $res &= $this->registerHook('displayHeaderCategory'); $res &= $this->registerHook('displayFooterCategory'); $res &= $this->registerHook('leoECatConfig'); $res &= $this->registerHook('actionCategoryFormBuilderModifier'); $res &= $this->registerHook('actionAfterUpdateCategoryFormHandler'); $res &= $this->registerHook('actionAfterCreateCategoryFormHandler'); //product layout $res &= $this->registerHook('actionObjectProductUpdateAfter'); $res &= $this->registerHook('filterProductContent'); $res &= $this->registerHook('displayReassurance'); $res &= $this->registerHook('displayFooterProduct'); $res &= $this->registerHook('displayAdminProductsExtra'); $this->registerHook('actionOutputHTMLBefore'); return $res; } public function uninstall() { Configuration::deleteByName('LEOELEMENTS_LIVE_MODE'); include(dirname(__FILE__).'/sql/uninstall.php'); return parent::uninstall(); } public static function getInstance() { static $_instance; if (!$_instance) { $_instance = new Leoelements(); } return $_instance; } /** * Load the configuration form */ public function getContent() { $this->registerHook('actionOutputHTMLBefore'); $dashboard = $this->context->link->getAdminLink('AdminLeoElementsDashboard'); Tools::redirectAdmin( $dashboard ); } /** * Save form data. */ protected function postProcess() { $form_values = $this->getConfigFormValues(); foreach (array_keys($form_values) as $key) { Configuration::updateValue($key, Tools::getValue($key)); } } /** * Add the CSS & JavaScript files you want to be loaded in the BO. */ public function hookDisplayBackOfficeHeader() { Leo_Helper::autoUpdateModule(); if (Tools::getValue('module_name') == $this->name) { $this->context->controller->addJS($this->_path.'views/js/back.js'); $this->context->controller->addCSS($this->_path.'views/css/back.css'); } $request = $GLOBALS['kernel']->getContainer()->get('request_stack')->getCurrentRequest(); $controller_name = $this->context->controller->controller_name; $controllers = [ 'AdminCategories', 'AdminProducts', 'AdminCmsContent', 'AdminManufacturers', 'AdminSuppliers', 'AdminBlogPost' ]; $id_page = ''; if ( in_array( $controller_name, $controllers ) ) { if($controller_name == 'AdminCmsContent') { $id_page = (int) Tools::getValue('id_cms'); if( !$id_page ){ if ( !isset( $request->attributes ) ) { return; } $id_page = (int) $request->attributes->get('cmsPageId'); } $post_type = 'cms'; }elseif ($controller_name == 'AdminCategories') { $id_page = (int) Tools::getValue('id_category'); if( !$id_page ){ if ( !isset( $request->attributes ) ) { return; } $id_page = (int) $request->attributes->get('categoryId'); } $post_type = 'category'; }elseif ($controller_name == 'AdminProducts') { $id_page = (int) Tools::getValue('id_product'); if( !$id_page ){ if ( !isset( $request->attributes ) ) { return; } $id_page = (int) $request->attributes->get('id'); } $post_type = 'product'; } } $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); if (!$id_page) { $this->context->controller->addCSS($this->_path.'views/css/back.css'); $url = $this->context->link->getAdminLink('AdminLeoElementsCreator'); $this->context->smarty->assign(array( 'urlPageBuilder' => $url, 'icon_url' => _MODULE_DIR_.'leoelements/views/img/logo.png', )); } else { $this->context->controller->addCSS($this->_path.'views/css/back.css'); $url = $this->context->link->getAdminLink('AdminLeoElementsCreator').'&post_type=' . $post_type . '&key_related=' . $id_page . '&id_lang=' . $id_lang; $this->context->smarty->assign(array( 'urlPageBuilder' => $url, 'icon_url' => _MODULE_DIR_.'leoelements/views/img/logo.png', )); } return $this->fetch(_PS_MODULE_DIR_ .'/'. $this->name . '/views/templates/admin/backoffice_header.tpl'); } public function hookActionAdminControllerSetMedia() { $this->autoRestoreSampleData(); $this->unregisterHook('actionAdminControllerSetMedia'); } /** * Add the CSS & JavaScript files you want to be added on the FO. */ public function hookHeader() { Leo_Helper::reset_post_var(); $GLOBALS['leoelements'] = array(); $post_type = Tools::getValue( 'post_type' ); if( (int)Tools::getValue( 'id_post' ) && Leo_Helper::is_preview_mode() && in_array( $post_type, array( 'header', 'home', 'footer', 'hook', 'hook_product_list', 'hook_category_layout', 'hook_product_layout' ) ) ){ $id_post = (int)Tools::getValue( 'id_post' ); // self::$leo_txt['id_editor'] = $id_post; // Leo_Helper::$id_editor = self::$leo_txt['id_editor']; Leo_Helper::$id_editor = $id_post; Leo_Helper::$post_var['id_editor'] = $id_post; } if (!$this->all_active_profile) { $model = new LeoElementsProfilesModel(); $this->all_active_profile = $model->getAllProfileByShop(); } $this->use_profiles = LeoElementsProfilesModel::getActiveProfile('index', $this->all_active_profile); if (!$this->use_profiles) { return ''; } if (!isset($this->use_profiles['params'])) { return ''; } $this->profile_param = json_decode($this->use_profiles['params'], true); if (Tools::getValue('controller') == 'index' || Tools::getValue('controller') == 'appagebuilderhome') { if (!empty($this->use_profiles) && isset($this->use_profiles['profile_key'])) { $this->context->smarty->assign(array( 'leo_class' => $this->use_profiles['profile_key'], 'leo_class_home' => (isset($this->use_profiles['active']) && $this->use_profiles['active'] == 1) ? 'leo-active' : '', )); } } $id_profile = (int)Tools::getValue('id_profile',0); if($id_profile){ foreach ($this->all_active_profile as $key => $profile) { if($profile['id_leoelements_profiles'] == $id_profile) { # GET FROM DATABASE $this->use_profiles = $this->all_active_profile[$key]; } } } if(isset($this->use_profiles['params'])) { $params = json_decode($this->use_profiles['params'], true); } else { return ''; } $this->use_profiles['displayBanner'] = isset($this->use_profiles['displayBanner']) ? $this->use_profiles['displayBanner'] : 0; $this->use_profiles['displayNav1'] = isset($this->use_profiles['displayNav1']) ? $this->use_profiles['displayNav1'] : 0; $this->use_profiles['displayNav2'] = isset($this->use_profiles['displayNav2']) ? $this->use_profiles['displayNav2'] : 0; $this->use_profiles['displayTop'] = isset($this->use_profiles['displayTop']) ? $this->use_profiles['displayTop'] : 0; $this->use_profiles['displayNavFullWidth'] = isset($this->use_profiles['displayNavFullWidth']) ? $this->use_profiles['displayNavFullWidth'] : 0; $this->use_profiles['displayHome'] = isset($this->use_profiles['displayHome']) ? $this->use_profiles['displayHome'] : 0; $this->use_profiles['displayLeftColumn'] = isset($this->use_profiles['displayLeftColumn']) ? $this->use_profiles['displayLeftColumn'] : 0; $this->use_profiles['displayRightColumn'] = isset($this->use_profiles['displayRightColumn']) ? $this->use_profiles['displayRightColumn'] : 0; $this->use_profiles['displayFooterBefore'] = isset($this->use_profiles['displayFooterBefore']) ? $this->use_profiles['displayFooterBefore'] : 0; $this->use_profiles['displayFooter'] = isset($this->use_profiles['displayFooter']) ? $this->use_profiles['displayFooter'] : 0; $this->use_profiles['displayFooterAfter'] = isset($this->use_profiles['displayFooterAfter']) ? $this->use_profiles['displayFooterAfter'] : 0; $params['displayHeaderCategory'] = isset($params['displayHeaderCategory']) ? $params['displayHeaderCategory'] : 0; $params['displayFooterCategory'] = isset($params['displayFooterCategory']) ? $params['displayFooterCategory'] : 0; $params['displayReassurance'] = isset($params['displayReassurance']) ? $params['displayReassurance'] : 0; $params['displayLeftColumnProduct'] = isset($params['displayLeftColumnProduct']) ? $params['displayLeftColumnProduct'] : 0; $params['displayFooterProduct'] = isset($params['displayFooterProduct']) ? $params['displayFooterProduct'] : 0; self::$leo_txt['hooks']['displayBanner'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayBanner']); self::$leo_txt['hooks']['displayNav1'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayNav1']); self::$leo_txt['hooks']['displayNav2'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayNav2']); self::$leo_txt['hooks']['displayTop'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayTop']); self::$leo_txt['hooks']['displayNavFullWidth'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayNavFullWidth']); self::$leo_txt['hooks']['displayHome'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayHome']); self::$leo_txt['hooks']['displayLeftColumn'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayLeftColumn']); self::$leo_txt['hooks']['displayRightColumn'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayRightColumn']); self::$leo_txt['hooks']['displayFooterBefore'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayFooterBefore']); self::$leo_txt['hooks']['displayFooter'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayFooter']); self::$leo_txt['hooks']['displayFooterAfter'] = LeoElementsContentsModel::getIdByKey($this->use_profiles['displayFooterAfter']); self::$leo_txt['hooks']['displayHeaderCategory'] = LeoElementsContentsModel::getIdByKey($params['displayHeaderCategory']); self::$leo_txt['hooks']['displayFooterCategory'] = LeoElementsContentsModel::getIdByKey($params['displayFooterCategory']); self::$leo_txt['hooks']['displayLeftColumnProduct'] = LeoElementsContentsModel::getIdByKey($params['displayLeftColumnProduct']); self::$leo_txt['hooks']['displayReassurance'] = LeoElementsContentsModel::getIdByKey($params['displayReassurance']); self::$leo_txt['hooks']['displayFooterProduct'] = LeoElementsContentsModel::getIdByKey($params['displayFooterProduct']); if(Tools::getIsset('cw_hook') && Tools::getValue('cw_hook') && Tools::getIsset('id_post') && in_array(Tools::getValue('id_post'), self::$leo_txt['hooks'])) { $this->use_profiles[ Tools::getValue('cw_hook')] = 0; self::$leo_txt['hooks'][ Tools::getValue('cw_hook')] = null; foreach (self::$leo_txt['hooks'] as $key => &$hook) { if($hook == Tools::getValue('id_post')){ $hook = null; } } } $post_type = Tools::getValue( 'post_type' ); if( (int)Tools::getValue( 'id_post' ) && Leo_Helper::is_preview_mode() && in_array( $post_type, array( 'hook' ) ) ){ $id_post = (int)Tools::getValue( 'id_post' ); $key_related = Tools::getValue( 'key_related' ); self::$leo_txt['hooks'][$key_related] = $id_post; self::$leo_txt['id_editor'] = $id_post; } $this->context->controller->addJS($this->_path.'/views/js/front.js'); // $this->context->controller->addCSS($this->_path.'views/css/front.css'); $uri = 'modules/leoelements/views/css/common.css'; $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8001)); $uri = 'modules/leoelements/views/css/front.css'; $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8002)); // cms $this->context->controller->addCSS($this->_path.'assets/lib/eicons/css/elementor-icons.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/font-awesome/css/font-awesome.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/font-awesome/css/fontawesome.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/font-awesome/css/regular.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/font-awesome/css/solid.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/font-awesome/css/brands.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/line-awesome/line-awesome.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/pe-icon/Pe-icon-7-stroke.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/animations/animations.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/flatpickr/flatpickr.min.css'); $this->context->controller->addCSS($this->_path.'assets/css/widgets.min.css'); $this->context->controller->addCSS($this->_path.'assets/lib/e-select2/css/e-select2.min.css'); $this->context->controller->addCSS($this->_path.'assets/css/frontend.css'); $this->context->controller->addCSS($this->_path.'assets/css/editor-preview.min.css'); $this->context->controller->addCSS($this->_path.'assets/css/leo-preview.min.css'); $this->context->controller->addCSS($this->_path.'assets/css/function.css'); $this->context->controller->addJS($this->_path.'assets/js/frontend-modules.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/waypoints/waypoints.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/flatpickr/flatpickr.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/imagesloaded/imagesloaded.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/jquery-numerator/jquery-numerator.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/swiper/swiper.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/dialog/dialog.min.js'); $this->context->controller->addJS($this->_path.'assets/lib/countdown/countdown.min.js'); $this->context->controller->addJS($this->_path.'assets/js/widgets.js'); // leotheme add more $this->context->controller->addJS($this->_path.'assets/lib/slick/slick.js'); $this->context->controller->addJS($this->_path.'assets/js/frontend-modules.min.js'); $this->context->controller->addJS($this->_path.'assets/js/frontend.js'); $this->context->controller->addJS($this->_path.'assets/lib/inline-editor/js/inline-editor.min.js'); $this->context->controller->addJS($this->_path.'assets/js/instafeed.min.js'); $this->context->controller->addJS($this->_path.'assets/js_own/function.js'); $this->context->controller->addJS($this->_path.'views/js/countdown.js'); $languages = []; $data_languages = $this->getListLanguages(); $currencies = []; $data_currencies = $this->getListCurrencies(); if( $data_languages ){ foreach( $data_languages['languages'] as $language ){ $languages[$language['id_lang']] = $this->context->link->getLanguageLink($language['id_lang']); } $languages['length'] = count( $data_languages['languages'] ); } if( $data_currencies ){ foreach( $data_currencies['currencies'] as $currency ){ $currencies[$currency['id']] = $currency['url']; } $currencies['length'] = count( $data_currencies['currencies'] ); } Media::addJsDef([ 'elementorFrontendConfig' => Plugin::instance()->frontend->get_init_settings(), 'opLeoElements' => [ 'ajax' => $this->context->link->getModuleLink('leoelements', 'ajax', ['token'=>Tools::getToken()], null, null, null, true), 'contact' => $this->context->link->getModuleLink('leoelements', 'contact', [], null, null, null, true), 'subscription' => $this->context->link->getModuleLink('leoelements', 'subscription', [], null, null, null, true), 'cart' => $this->context->link->getModuleLink('leoelements', 'cart', [], null, null, null, true), 'all_results_product' => $this->l('View all product results'), 'no_products' => $this->l('No products found'), 'languages' => $languages, 'currencies' => $currencies ] ]); $controller = Dispatcher::getInstance()->getController(); $pl_layout = ''; //check product list switch ($controller) { case "category": $id_category = Tools::getValue('id_category'); $category = new Category($id_category); $clayout = ''; $category->leoe_layout_mobile = 'category2043272848'; $category->leoe_layout_tablet = 'category2043272848'; $category->leoe_layout = 'category2043272848'; //get category layou if(Tools::getIsset('layout')) { $clayout = Tools::getValue('layout'); } else { if (Context::getContext()->isMobile() && isset($category->leoe_layout_mobile) && $category->leoe_layout_mobile) { $clayout = $category->leoe_layout_mobile; } else if(Context::getContext()->isTablet() && isset($category->leoe_layout_tablet) && $category->leoe_layout_tablet) { $clayout = $category->leoe_layout_tablet; } else { if(isset($category->leoe_layout) && $category->leoe_layout) { $clayout = $category->leoe_layout; } else { //get from profile if (Context::getContext()->isMobile() && isset($params['category_layout_mobile']) && $params['category_layout_mobile']) { $clayout = $params['category_layout_mobile']; } else if(Context::getContext()->isTablet() && isset($params['category_layout_tablet']) && $params['category_layout_tablet']) { $clayout = $params['category_layout_tablet']; } else { $clayout = $params['category_layout']; } } } } //found category layout if($clayout) { $params['c_config'] = $this->getCategoryConfig($clayout); if (Context::getContext()->isMobile() && $params['c_config']['product_list_mobile']) { $pl_layout = $params['c_config']['product_list_mobile']; } else if(Context::getContext()->isTablet() && $params['c_config']['product_list_tablet']) { $pl_layout = $params['c_config']['product_list_tablet']; } else { $pl_layout = $params['c_config']['product_list']; } } if(!isset($params['c_config']) || !$params['c_config']) { $params['c_config'] = leoECHelper::defaultConfig()['category']; } break; case "pricesdrop": if ($params['pricedrop_layout']) { $pl_layout = $params['pricedrop_layout']; } break; case "newproducts": if ($params['newproduct_layout']) { $pl_layout = $params['newproduct_layout']; } break; case "bestsales": if ($params['bestsales_layout']) { $pl_layout = $params['bestsales_layout']; } break; case "search": if ($params['search_layout']) { $pl_layout = $params['search_layout']; } break; case "manufacture": if ($params['manufacture_layout']) { $pl_layout = $params['manufacture_layout']; } break; default: } //find from profile if(!$pl_layout) { if (Context::getContext()->isMobile() && $params['productlist_layout_mobile']) { $pl_layout = $params['productlist_layout_mobile']; } else if(Context::getContext()->isTablet() && $params['productlist_layout_tablet']) { $pl_layout = $params['productlist_layout_tablet']; } else { $pl_layout = $params['productlist_layout']; } } if($pl_layout || Tools::getIsset('plist_key')) { if(Tools::getIsset('plist_key')) { $pl_layout = Tools::getValue('plist_key'); } $params['pl_config'] = $this->getProductListConfig($pl_layout); $params['pl_key'] = $pl_layout; if (file_exists(_PS_THEME_DIR_.'modules/leoelements/views/templates/front/products/'.$pl_layout.'.tpl')) { $params['pl_url'] = 'module:/leoelements/views/templates/front/products/'.$pl_layout.'.tpl'; } } if (!isset($params['pl_config']) || !$params['pl_config']) { $params['pl_config'] = leoECHelper::defaultConfig()['product_list']; } Media::addJsDef([ 'opLeoElementsList' => $params['pl_config'], 'homeSize' => Image::getSize(ImageType::getFormattedName('home')), ]); $use_leo_gallery = 0; if (isset($params['thumb_product_layout']['use_leo_gallery'])) { $use_leo_gallery = $params['thumb_product_layout']['use_leo_gallery']; } elseif (Context::getContext()->isTablet() && isset($params['thumb_product_layout_tablet']['use_leo_gallery'])) { $use_leo_gallery = $params['thumb_product_layout_tablet']['use_leo_gallery']; } elseif (Context::getContext()->isMobile() && isset($params['thumb_product_layout_mobile']['use_leo_gallery'])) { $use_leo_gallery = $params['thumb_product_layout_mobile']['use_leo_gallery']; } if ($controller == 'product') { if(Tools::getIsset('layout')) { $params['pdeail_layout'] = Tools::getValue('layout'); if (Module::isInstalled('leogallery')) { // check for demo layout when gallery layout is used require_once(_PS_MODULE_DIR_.'leoelements/classes/LeoElementsProductsModel.php'); $layout_data = LeoElementsProductsModel::getProductProfileByKey($params['pdeail_layout']); if (strpos($layout_data['class_detail'], 'product_image_gallery') === false) { $params_layout = json_decode($layout_data['params'], true); if (isset($params_layout['gridLeft'])) { foreach ($params_layout['gridLeft'] as $group) { if (isset($group['columns'])) { foreach ($group['columns'] as $columns) { if (isset($columns['sub'])) { foreach ($columns['sub'] as $sub) { $layout_detail_data[] = $data_column = $sub['form']; break; } } if ($data_column) break; } } if ($data_column) break; } } $use_leo_gallery = (isset($data_column['use_leo_gallery']) && $data_column['use_leo_gallery']) ? 1 : 0; } else { $use_leo_gallery = 0; } } } else { $product = new Product(Tools::getValue('id_product')); if(isset($product->leoe_layout) && $product->leoe_layout && $product->leoe_layout != 'default') { $params['pdeail_layout'] = $product->leoe_layout; } if(Context::getContext()->isTablet() && isset($product->leoe_layout_tablet) && $product->leoe_layout_tablet && $product->leoe_layout_tablet != 'default') { $params['pdeail_layout'] = $product->leoe_layout_tablet; } if (Context::getContext()->isMobile() && isset($product->leoe_layout_mobile) && $product->leoe_layout_mobile && $product->leoe_layout_mobile != 'default') { $params['pdeail_layout'] = $product->leoe_layout_mobile; } } } if(!isset($params['pdeail_layout']) || !$params['pdeail_layout']) { $params['pdeail_layout'] = $params['productdetail_layout']; if(Context::getContext()->isTablet() && $params['productdetail_layout_tablet']) { $params['pdeail_layout'] = $params['productdetail_layout_tablet']; } if (Context::getContext()->isMobile() && $params['productdetail_layout_mobile']) { $params['pdeail_layout'] = $params['productdetail_layout_mobile']; } } $params['pdetail_url'] = ''; if(isset($params['pdeail_layout']) && $params['pdeail_layout'] && file_exists(_PS_THEME_DIR_.'modules/leoelements/views/templates/front/details/'.$params['pdeail_layout'].'.tpl')) { $params['pdetail_url'] = 'module:/leoelements/views/templates/front/details/'.$params['pdeail_layout'].'.tpl'; } if (!$params['pdeail_layout']) { $use_leo_gallery = $params['use_leo_gallery_default']; } if ($use_leo_gallery && !Module::isInstalled('leogallery')) { $use_leo_gallery = 0; } if (!$use_leo_gallery) { $this->context->controller->addJqueryPlugin('fancybox'); $this->context->controller->addJS($this->_path.'views/js/jquery.elevateZoom-3.0.8.min.js'); } Media::addJsDef([ 'use_leo_gallery' => $use_leo_gallery ? 1 : 0, ]); # LOAD FONT $uri = 'modules/leoelements/views/css/'.'font-custom-'.$this->use_profiles['profile_key'].'-'.Context::getContext()->shop->id.'.css'; if (file_exists(_PS_THEME_DIR_.$uri)) { $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8001)); } $uri = leoECHelper::getCssDir().'profiles/'.$this->use_profiles['profile_key'].'.css'; if ((file_exists(_PS_THEME_DIR_.$uri) && filesize(_PS_THEME_DIR_.$uri)) || (file_exists(_PS_THEME_DIR_.'assets/css/'.$uri) && filesize(_PS_THEME_DIR_.'assets/css/'.$uri))) { $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8001)); } $uri = leoECHelper::getJsDir().'profiles/'.$this->use_profiles['profile_key'].'.js'; if (file_exists(_PS_THEME_DIR_.$uri)) { $this->context->controller->addJS($uri); } foreach (array('header', 'content', 'footer') as $csp) { $uri = leoECHelper::getCssDir().'positions/'.$csp.$this->use_profiles[$csp].'.css'; $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8001)); $uri = leoECHelper::getJsDir().'positions/'.$csp.$this->use_profiles[$csp].'.js'; if ((file_exists(_PS_THEME_DIR_.$uri) && filesize(_PS_THEME_DIR_.$uri)) || (file_exists(_PS_THEME_DIR_.'assets/css/'.$uri) && filesize(_PS_THEME_DIR_.'assets/css/'.$uri))) { $this->context->controller->addJS($uri); } } if (file_exists(_PS_THEME_DIR_.$uri)) { $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8000)); } // check sitemap if ($controller == 'sitemap') { $profiles = $this->all_active_profile; require_once(_PS_MODULE_DIR_.'leoelements/libs/LeoFriendlyUrl.php'); if (!empty($profiles)) { foreach ($profiles as $key => &$profile) { $leo_friendly_url = LeoFriendlyUrl::getInstance(); $link = $this->context->link; $idLang = $this->context->language->id; $idShop = null; $relativeProtocol = false; $params_profile = json_decode($profile['params'], true); if (!isset($params_profile['show_sitemap']) || !$params_profile['show_sitemap'] || !isset($profile['friendly_url']) || !$profile['friendly_url']) { unset($profiles[$key]); } else { $url = $link->getBaseLink($idShop, null, $relativeProtocol).$leo_friendly_url->getLangLink($idLang, null, $idShop).$profile['friendly_url'].'.html'; $profile['url'] = $url; } } } $this->context->smarty->assign('leo_sitemap_profiles', $profiles); } if ($controller == 'index' || $controller == 'appagebuilderhome') { $this->context->smarty->assign(array( 'fullwidth_hook' => $params['fullwidth_index_hook'], )); } else { $this->context->smarty->assign(array( 'fullwidth_hook' => $params['fullwidth_other_hook'], )); } // breadcrumbImage $params['leobcimg'] = $this->getBreadcrumbImage($params); $panel_tool = Configuration::get('LEOELEMENTS_PANEL_TOOL'); if($panel_tool) { $uri = 'modules/leoelements/views/css/paneltool.css'; $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8000)); $this->context->controller->addJS($this->_path.'views/js/webfont.js'); $this->context->controller->addJS($this->_path.'views/js/paneltool.js'); $uri = 'modules/leoelements/views/css/colorpicker/css/colorpicker.css'; $this->context->controller->registerStylesheet(sha1($uri), $uri, array('media' => 'all', 'priority' => 8000)); $uri = 'modules/leoelements/views/js/colorpicker/js/colorpicker.js'; $this->context->controller->registerJavascript(sha1($uri), $uri, array('position' => 'bottom', 'priority' => 8000)); $product_layout_link = ''; if (Tools::getValue('id_product')) { $id_product = Tools::getValue('id_product'); } else { $sql = 'SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p '.Shop::addSqlAssociation('product', 'p').' AND product_shop.`visibility` IN ("both", "catalog") AND product_shop.`active` = 1 ORDER BY p.`id_product` ASC'; $first_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $id_product = isset($first_product['id_product']) ? $first_product['id_product'] : ''; } if (Tools::getValue('id_category')) { $id_category = Tools::getValue('id_category'); } else { $first_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` c WHERE `active` = 1 AND `id_category` > 2'); $id_category = isset($first_category['id_category']) ? $first_category['id_category'] : ''; } $leo_panel['product_link'] = $id_product ? $this->context->link->getProductLink($id_product, null, null, null, null, null) : '#'; $leo_panel['category_link'] = $id_category ? $this->context->link->getCategoryLink($id_category) : '#'; $leo_panel['font_url'] = _PS_BASE_URL_.__PS_BASE_URI__.'themes/'._THEME_NAME_.'/assets/fonts/'; $leo_panel['profile'] = $this->all_active_profile; $leo_panel['pdetail'] = LeoElementsProfilesModel::getAllProductDetail(); $leo_panel['plist'] = LeoElementsProfilesModel::getAllProductList(); $leo_panel['category'] = LeoElementsProfilesModel::getAllCategory(); $leo_panel['positions'] = LeoElementsProfilesModel::getAllPosition(); foreach ($leo_panel['positions'] as $key => &$lp_positions) { foreach ($lp_positions as $key => &$lp_position) { $lp_id_post = ''; $lp_params = json_decode($lp_position['params'], true); if (is_array($lp_params)) { foreach ($lp_params as $lp_key => $lp_param) { $lp_id_post = LeoElementsContentsModel::getIdByKey($lp_param); } } $lp_position['demo_url'] = ''; if($lp_id_post) { $lp_position['demo_url'] = Context::getContext()->link->getModuleLink('leoelements', 'creator') . '?post_type=hook&id_post='.$lp_id_post.'&id_lang='.$this->context->language->id; } } } $leo_panel['fonts'] = array(array( 'label' => $this->l('Available fonts'), 'options' => LeoElementsProfilesModel::getFontFamily() ), array( 'label' => $this->l('Uploaded fonts'), 'options' => LeoElementsProfilesModel::getFontFamilyUploaded() ), array( 'label' => $this->l('Google fonts'), 'options' => LeoElementsProfilesModel::getFontFamilyGoogle() )); $leo_panel['font_configs'] = array( 'font_family_base'=>$this->l('Font Base'), 'font_family_heading'=>$this->l('Font Family Heading'), 'font_family_slider'=>$this->l('Font Slider'), 'font_family_heading'=>$this->l('Font Heading'), 'font_family_senary'=>$this->l('Font Senary'), 'font_family_septenary'=>$this->l('Font Septenary')); $leo_panel['color_configs'] = array( array( 'label' => $this->l('Theme Color'), 'config' => array('theme_color_default'=>$this->l('Color Default'), // 'theme_color_secondary'=>$this->l('Color Secondary'), 'theme_color_tertiary'=>$this->l('Color Tertiary'), 'theme_color_senary'=>$this->l('Color Senary') ), ), array( 'label' => $this->l('Text Color'), 'config' => array('headings_color'=> $this->l('Headings Color'),'link_color'=>$this->l('Link Color'), 'link_color_hover'=>$this->l('Link Hover Color'), 'text_color'=>$this->l('Text Color'), 'price_color'=>$this->l('Price Color')), ), array( 'label' => $this->l('Button Color'), 'config' => array('btn_bg'=>$this->l('Button Background'), 'btn_bg_hover'=>$this->l('Button Hover Background'), 'btn_color'=>$this->l('Button Color'), 'btn_color_hover'=>$this->l('Button Hover Color')), ), array( 'label' => $this->l('Product Items'), 'config' => array('product_background'=>$this->l('Product Background'), 'product_name_color'=>$this->l('Product Name Color'), 'product_name_color_hover'=>$this->l('Product Name Hover Color'), 'product_price_color'=>$this->l('Product Price Color'), 'product_regular_price_color'=>$this->l('Product Regular Price Color'), 'product_button_bg'=>$this->l('Product Button Background'), 'product_button_bg_hover'=>$this->l('Product Button Hover Background'), 'product_button_color'=>$this->l('Product Button Color'), 'product_button_color_hover'=>$this->l('Product Button Hover Color')), ), array( 'label' => $this->l('Product Flags'), 'config' => array('on_sale_badge_background'=>$this->l('On Sale Badge Background'), 'on_sale_badge_color'=>$this->l('On Sale Badge Color'), 'new_badge_background'=>$this->l('New Badge Background'), 'new_badge_color'=>$this->l('New Badge Color'), 'sale_badge_background'=>$this->l('Sale Badge Background'), 'sale_badge_color'=>$this->l('Sale Badge Color'), 'online_only_background'=>$this->l('Online Only Background'), 'online_only_color'=>$this->l('Online Only Color'), 'pack_badge_background'=>$this->l('Pack Badge Background'), 'pack_badge_color'=>$this->l('Pack Badge Color')), ), array( 'label' => $this->l('Boxes (including Sidebars)'), 'config' => array('block_background'=>$this->l('Block Background'), 'block_inner_background'=>$this->l('Block Inner Background'), 'block_heading_bg'=>$this->l('Block Heading Background'), 'block_heading_color'=>$this->l('Block Heading Color')), ) ); $this->context->smarty->assign(array( 'leo_panel' => $leo_panel )); } $page_name = leoECHelper::getPageName(); if (version_compare(Configuration::get('PS_INSTALL_VERSION'), '8.0.0', '>=')) { $page = $this->smarty->smarty->getTemplateVars('page'); } else { $page = $this->smarty->smarty->getVariable('page')->value; } if (isset($this->use_profiles['meta_title']) && $this->use_profiles['meta_title'] && $page_name == 'index') { $page['meta']['title'] = $this->use_profiles['meta_title']; } if (isset($this->use_profiles['meta_description']) && $this->use_profiles['meta_description'] && $page_name == 'index') { $page['meta']['description'] = $this->use_profiles['meta_description']; } if (isset($this->use_profiles['meta_keywords']) && $this->use_profiles['meta_keywords'] && $page_name == 'index') { $page['meta']['keywords'] = $this->use_profiles['meta_keywords']; } $this->smarty->smarty->assign('page', $page); # REPLACE LINK FOR MULILANGUAGE $controller = Dispatcher::getInstance()->getController(); if ($controller == 'appagebuilderhome') { Media::addJsDef(array('approfile_multilang_url' => LeoElementsProfilesModel::getAllProfileRewrite($this->use_profiles['id_leoelements_profiles']))); } $this->context->smarty->assign(array( 'profile' => $this->use_profiles, 'profile_params' => $params, 'LEO_PANELTOOL' => $panel_tool, 'IS_RTL' => $this->context->language->is_rtl, 'LEO_RTL' => $this->context->language->is_rtl, 'LEO_THEMENAME' => _THEME_NAME_, 'tpl_theme_dir' => trim(_PS_THEME_DIR_, '/'), 'isMobile' => Context::getContext()->isMobile(), )); $this->header_content = $this->display(__FILE__, 'header.tpl'); return $this->header_content . ' ' . $this->getWidgetCSS(); } public function getWidgetCSS () { $css_unique = ''; $controller = Dispatcher::getInstance()->getController(); if (!empty($this->context->controller->php_self)) { $controller = $this->context->controller->php_self; } $controller = Tools::strtolower( $controller ); if( !Leo_Helper::is_preview_mode() ) { # DEFAULT $css_unique .= Plugin::instance()->frontend->parse_global_css_code(); } if( Leo_Helper::$id_post && Validate::isLoadedObject( new LeoElementsContentsModel( Leo_Helper::$id_post, Leo_Helper::$id_lang ) ) ){ # SPECIAL PAGE if( Leo_Helper::$id_post != Leo_Helper::$id_editor ){ $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayBanner']) && self::$leo_txt['hooks']['displayBanner'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayBanner'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayBanner'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayBanner']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayNav1']) && self::$leo_txt['hooks']['displayNav1'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayNav1'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayNav1'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayNav1']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayNav2']) && self::$leo_txt['hooks']['displayNav2'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayNav2'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayNav2'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayNav2']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayTop']) && self::$leo_txt['hooks']['displayTop'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayTop'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayTop'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayTop']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayNavFullWidth']) && self::$leo_txt['hooks']['displayNavFullWidth'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayNavFullWidth'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayNavFullWidth'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayNavFullWidth']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayHome']) && self::$leo_txt['hooks']['displayHome'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayHome'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayHome'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayHome']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayLeftColumn']) && self::$leo_txt['hooks']['displayLeftColumn'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayLeftColumn'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayLeftColumn'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayLeftColumn']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayRightColumn']) && self::$leo_txt['hooks']['displayRightColumn'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayRightColumn'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayRightColumn'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayRightColumn']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayFooterBefore']) && self::$leo_txt['hooks']['displayFooterBefore'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayFooterBefore'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayFooterBefore'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayFooterBefore']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayFooter']) && self::$leo_txt['hooks']['displayFooter'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayFooter'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayFooter'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayFooter']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayFooterAfter']) && self::$leo_txt['hooks']['displayFooterAfter'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayFooterAfter'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayFooterAfter'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayFooterAfter']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } # CATEGORY PAGE - BEGIN if( isset(self::$leo_txt['hooks']['displayHeaderCategory']) && self::$leo_txt['hooks']['displayHeaderCategory'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayHeaderCategory'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayHeaderCategory'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayHeaderCategory']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( isset(self::$leo_txt['hooks']['displayFooterCategory']) && self::$leo_txt['hooks']['displayFooterCategory'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayFooterCategory'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayFooterCategory'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayFooterCategory']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } # CATEGORY PAGE - END # PRODUCT PAGE - BEGIN if( $controller == 'product' && isset(self::$leo_txt['hooks']['displayReassurance']) && self::$leo_txt['hooks']['displayReassurance'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayReassurance'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayReassurance'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayReassurance']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } if( $controller == 'product' && isset(self::$leo_txt['hooks']['displayFooterProduct']) && self::$leo_txt['hooks']['displayFooterProduct'] && Validate::isLoadedObject( new LeoElementsContentsModel( self::$leo_txt['hooks']['displayFooterProduct'], Leo_Helper::$id_lang ) ) ){ if( self::$leo_txt['hooks']['displayFooterProduct'] != self::$leo_txt['id_editor'] ){ Leo_Helper::$id_post = self::$leo_txt['hooks']['displayFooterProduct']; $css_unique .= Plugin::instance()->frontend->parse_post_css_code( Leo_Helper::$id_post ); } } # PRODUCT PAGE - END Leo_Helper::reset_post_var(); $this->smarty->assign( ['css_unique' => $css_unique] ); return $this->fetch( 'module:' . $this->name . '/views/templates/hook/css_unique.tpl' ); } public function getProductListConfig($pllayout) { $cacheId = 'leoelements::getProductListConfig_' . md5($pllayout); if (!Cache::isStored($cacheId)) { $sql = 'SELECT * FROM `'._DB_PREFIX_.'leoelements_product_list`'.' WHERE plist_key= "'.pSQL($pllayout, true).'"'; $result = Db::getInstance()->executeS($sql); if($result) { $params = json_decode($result[0]['params'], 1); $params['class'] = $result[0]['class']; } else { $params = array(); } Cache::store($cacheId, $params); } else { $params = Cache::retrieve($cacheId); } return $params; } public function getCategoryConfig($clayout) { $cacheId = 'leoelements::getCategoryConfig_' . md5($clayout) . time(); if (!Cache::isStored($cacheId)) { $sql = 'SELECT * FROM `'._DB_PREFIX_.'leoelements_category`'.' WHERE clist_key= "'.pSQL($clayout, true).'"'; $result = Db::getInstance()->executeS($sql); $params = array(); if($result) { $params = json_decode($result[0]['params'], 1); $params['class'] = $result[0]['class']; } Cache::store($cacheId, $params); } else { $params = Cache::retrieve($cacheId); } return $params; } public function renderWidget($hookName = null, array $config = array()) { $disable_cache = false; if (defined('_PS_ADMIN_DIR_')) { $disable_cache = true; } //some hook need disable cache get from config of profile // $disable_cache_hook = isset($this->profile_param['disable_cache_hook']) ? $this->profile_param['disable_cache_hook'] : LeoECSetting::getCacheHook(3); $disable_cache_hook = isset($this->profile_param['disable_cache_hook']) ? $this->profile_param['disable_cache_hook'] : array(); if (isset($disable_cache_hook[$hookName]) && $disable_cache_hook[$hookName]) { $disable_cache = true; } //disable cache when submit newletter if (Tools::isSubmit('submitNewsletter')) { $disable_cache = true; } //disable cache if (!Configuration::get('PS_SMARTY_CACHE')) { $disable_cache = true; } if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'leoelements') && strpos($_SERVER['HTTP_REFERER'], 'creator')) { $disable_cache = true; } if ( Tools::getIsset('front_token')) { $disable_cache = true; } //run without cache no create cache if ($disable_cache) { $this->smarty->assign(array('content' => $this->renderWidget2($hookName, $config))); return $this->fetch($this->leo_templateFile); } else { $cache_id = $this->getCacheId($hookName); if (!$this->isCached($this->leo_templateFile, $cache_id)) { $this->smarty->assign(array('content' => $this->renderWidget2($hookName, $config))); } return $this->fetch($this->leo_templateFile, $cache_id); } } public function getWidgetVariables($hookName = null, array $configuration = []) { if( !isset( Leo_Helper::$id_post ) || !Leo_Helper::$id_post ){ return; } $content = ''; if( Leo_Helper::$id_post && Validate::isLoadedObject( new LeoElementsContentsModel( Leo_Helper::$id_post, Leo_Helper::$id_lang ) ) ) { $content .= Plugin::instance()->frontend->get_builder_content( Leo_Helper::$id_post, (int) Tools::getValue('content_only') ); } Leo_Helper::reset_post_var(); return $content; } public function hookOverrideLayoutTemplate($params) { Leo_Helper::reset_post_var(); if ( !Leo_Helper::$id_post || isset( self::$leo_overrided[ Leo_Helper::$id_post ] ) ) { return; } self::$leo_overrided[ Leo_Helper::$id_post ] = true; switch ( Leo_Helper::$post_type ) { case 'category': case 'product': $content = $this->context->smarty->tpl_vars[Leo_Helper::$post_type]; $content_replace = &$this->context->smarty->tpl_vars[Leo_Helper::$post_type]; $content->value['description'] .= $this->_filterPageContent(); $content_replace = $content; break; } } public $leo_templateFile; public static $leo_overrided = []; public function hookFilterCmsContent($params) { // $params['object']['content'] = '
' . "\n"; //// echo 'all_active_profile'; //// print_r($this->all_active_profile); // echo 'use_profiles'; // print_r($this->use_profiles); // echo '' . "\n"; // die(); //process nomal cache for each hook //create folder cache for each home by id or buy home name if (!isset($this->use_profiles['id_leoelements_profiles'])) { $this->use_profiles = LeoElementsProfilesModel::getActiveProfile('index', $this->all_active_profile); } $cache_array[] = $this->use_profiles['id_leoelements_profiles']; //set cache for each hook in profile $cache_array[] = $hookName; //kiem tra xem module confg if ($this->use_profiles && isset($this->use_profiles[$hookName]) && $this->use_profiles[$hookName]) { $current_page = leoECHelper::getPageName(); $iscached = 0; //check cache in sub page if (($current_page == "category" || $current_page == 'product')) { if (isset($this->use_profiles[$hookName]['nocategory'])) { if (in_array(Tools::getValue('id_category'), $this->use_profiles[$hookName]['nocategory'])) { $cache_array[] = Tools::getValue('id_category'); $iscached = 1; } } if (isset($this->use_profiles[$hookName]['nocategoryproduct'])) { if (in_array(Tools::getValue('id_category'), $this->use_profiles[$hookName]['nocategoryproduct'])) { $cache_array[] = Tools::getValue('id_category'); $iscached = 1; } } if (!$iscached && $current_page == "category" && isset($this->use_profiles[$hookName]['categoryproduct'])) { if (in_array(Tools::getValue('id_category'), $this->use_profiles[$hookName]['categoryproduct'])) { $cache_array[] = Tools::getValue('id_category'); $iscached = 1; } } if (!$iscached && $current_page == "category" && isset($this->use_profiles[$hookName]['categoryproductmain'])) { if (in_array(Tools::getValue('id_category'), $this->use_profiles[$hookName]['categoryproductmain'])) { $cache_array[] = Tools::getValue('id_category'); $iscached = 1; } } //product in no category if (!$iscached && $current_page == "product" && isset($this->use_profiles[$hookName]['nocategoryproduct'])) { $procate = Product::getProductCategoriesFull(Tools::getValue('id_product')); $procheck = 0; foreach ($procate as $proc) { if (in_array($proc['id_category'], $this->use_profiles[$hookName]['nocategoryproduct'])) { $procheck = 1; } } if ($procheck == 1) { $cache_array[] = 'product_'.Tools::getValue('id_product'); $iscached = 1; } } //product in category if (!$iscached && $current_page == "product" && isset($this->use_profiles[$hookName]['categoryproduct'])) { $procate = Product::getProductCategoriesFull(Tools::getValue('id_product')); $procheck = 0; foreach ($procate as $proc) { if (in_array($proc['id_category'], $this->use_profiles[$hookName]['categoryproduct'])) { $procheck = 1; } } if ($procheck == 1) { $cache_array[] = 'product_'.Tools::getValue('id_product'); $iscached = 1; } } //product in main category if (!$iscached && $current_page == "product" && isset($this->use_profiles[$hookName]['categoryproduct'])) { $procate = new Product(Tools::getValue('id_product')); if (in_array($procate['id_category_default'], $this->use_profiles[$hookName]['categoryproduct'])) { $cache_array[] = 'product_'.Tools::getValue('id_product'); $iscached = 1; } } } //cache big page if (!$iscached && isset($this->use_profiles[$hookName][$current_page])) { $cache_array[] = $current_page; $iscached = 1; } //cache big page not show if (!$iscached && isset($this->use_profiles[$hookName]['exception']) && in_array($cache_array, $this->use_profiles[$hookName]['exception'])) { //show but not in controller $cache_array[] = $current_page; $iscached = 1; } //random in product carousel if (isset($this->use_profiles[$hookName]['productCarousel'])) { $random = round(rand(1, max(Configuration::get('APPAGEBUILDER_PRODUCT_MAX_RANDOM'), 1))); $cache_array[] = "p_carousel_$random"; } if (isset($this->use_profiles[$hookName][$current_page])) { $cache_array[] = $current_page; if ($current_page != 'index' && $cache_id = LeoECSetting::getControllerId($current_page, $this->use_profiles[$hookName][$current_page])) { $cache_array[] = $cache_id; } } else if (isset($this->use_profiles[$hookName]['nocategory']) || isset($this->use_profiles[$hookName]['categoryproduct'])) { if (in_array(Tools::getValue('id_category'), $this->use_profiles[$hookName]['nocategory'])) { $cache_array[] = Tools::getValue('id_category'); } } else if (isset($this->use_profiles[$hookName]['categoryproduct']) && ($current_page == "category" || $current_page == 'product')) { if ($current_page == 'category') { if (!LeoECSetting::getControllerId($current_page, $this->use_profiles[$hookName]['categoryproduct'])) { $cache_array[] = Tools::getValue('id_category'); } } else { $procate = Product::getProductCategoriesFull(Tools::getValue('id_product')); $procheck = 0; foreach ($procate as $proc) { if (in_array($proc['id_category'], $this->use_profiles[$hookName]['categoryproduct'])) { $procheck = 1; } } if ($procheck == 0) { $cache_array[] = Tools::getValue('id_product'); } } } } if (Tools::getValue('plist_key')&& Tools::getIsset('leopanelchange')) { $cache_array[] = 'plist_key_'.Tools::getValue('plist_key'); } if (Tools::getValue('header') && Tools::getIsset('leopanelchange') && (in_array($hookName, LeoECSetting::getHook('header')) || $hookName == 'leoECatConfig|header')) { $cache_array[] = 'header_'.Tools::getValue('header'); } if (Tools::getValue('content')&& Tools::getIsset('leopanelchange') && (in_array($hookName, LeoECSetting::getHook('content')) || $hookName == 'leoECatConfig|content')) { $cache_array[] = 'content_'.Tools::getValue('content'); } if (Tools::getValue('product')&& Tools::getIsset('leopanelchange') && (in_array($hookName, LeoECSetting::getHook('product')) || $hookName == 'leoECatConfig|product')) { $cache_array[] = 'product_'.Tools::getValue('product'); } if (Tools::getValue('footer') && Tools::getIsset('leopanelchange') && (in_array($hookName, LeoECSetting::getHook('footer')) || $hookName == 'leoECatConfig|footer')) { $cache_array[] = 'footer_'.Tools::getValue('footer'); } if (Context::getContext()->isTablet()) { $cache_array[] = "tablet"; } elseif (Context::getContext()->isMobile()) { $cache_array[] = "mobile"; }else{ $cache_array[] = "desktop"; } return parent::getCacheId().'|'.implode('|', $cache_array); } public function aProduct( $id_product ) { $products = []; $id_lang = (int)$this->context->language->id; $id_shop = (int)$this->context->shop->id; $product = new Product( $id_product, false, $id_lang, $id_shop, $this->context ); // echo '
' . "\n"; // print_r($product); // echo '' . "\n"; // die(); // dump($product); // die('a'); if ( Validate::isLoadedObject($product) ) { $product->id_product = (int)$id_product; $products[]= (array)$product; }else{ return; } $products = $this->convertProducts( $products ); return $products[0]; } public function hookActionOutputHTMLBefore(&$params) { # LEO OPTIMIZE - BEGIN if (file_exists(_PS_MODULE_DIR_.'leoelements/libs/LeoOptimization.php')) { require_once(_PS_MODULE_DIR_.'leoelements/libs/LeoOptimization.php'); if (class_exists('LeoOptimization')) { $params['runtime'] = 1; LeoOptimization::getInstance()->processOptimization($params); } } # LEO OPTIMIZE - END } }