public function postProcess() { if ((Tools::isSubmit('saveleotempcp') || Tools::isSubmit('saveandstayleotempcp')) && Tools::isSubmit('widgets')) { if (!Tools::getValue('widget_name')) { $this->errors[] = Tools::displayError('Widget Name Empty !'); } if (!count($this->errors)) { if (Tools::getValue('id_leowidgets')) { $model = new LeoTempcpWidget((int) Tools::getValue('id_leowidgets')); } else { $model = $this->widget; } $model->loadEngines(); $model->id_shop = Context::getContext()->shop->id; // $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $tmp = array(); $post = LeomanagewidgetsHelper::getPost(); $widget_type = Tools::getValue('widget_type'); # GET POST - BEGIN $widget_type = Tools::getValue('widget_type'); $file_name = _PS_MODULE_DIR_ . 'leomanagewidgets/classes/widget/' . $widget_type . '.php'; require_once $file_name; $class_name = 'LeoWidget' . Tools::ucfirst($widget_type); $widget = new $class_name(); $keys = array('addleowidgets', 'id_leowidgets', 'widget_name', 'widget_type', 'saveandstayleotempcp'); $post = LeomanagewidgetsHelper::getPost($keys, 0); $keys = array('widget_title'); $post += LeomanagewidgetsHelper::getPost($keys, 1); $keys = $widget->getConfigKey(0); $post += LeomanagewidgetsHelper::getPost($keys, 0); $keys = $widget->getConfigKey(1); $post += LeomanagewidgetsHelper::getPost($keys, 1); $keys = $widget->getConfigKey(2); $post += LeomanagewidgetsHelper::getPost($keys, 2); # GET POST - END foreach ($post as $key => $value) { $tmp[$key] = str_replace(array('\'', '\\"'), array("'", '"'), $value); foreach ($this->_langField as $fVal) { if (strpos($key, $fVal) !== false) { foreach ($languages as $language) { if (Tools::getIsset($fVal . '_' . $language['id_lang'])) { $valueLang = Tools::getValue($fVal . '_' . $language['id_lang']); if (empty($valueLang)) { $tmp[$fVal . '_' . $language['id_lang']] = $value; } } } } } } $data = array('id' => Tools::getValue('id_leowidgets'), 'params' => call_user_func('base64' . '_encode', Tools::jsonEncode($tmp)), 'type' => Tools::getValue('widget_type'), 'name' => Tools::getValue('widget_name')); foreach ($data as $k => $v) { $model->{$k} = $v; } if ($model->id) { if (!$model->update()) { $this->errors[] = Tools::displayError('Can not update new widget'); } else { if (Tools::isSubmit('saveandstayleotempcp')) { $this->confirmations[] = $this->l('Update successful'); $model->clearCaches(); Tools::redirectAdmin(self::$currentIndex . '&id_leowidgets=' . $model->id . '&updateleowidgets&token=' . $this->token . '&conf=4'); } else { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . '&conf=4'); } } } else { $model->key_widget = time(); if (!$model->add()) { $this->errors[] = Tools::displayError('Can not add new widget'); } else { if (Tools::isSubmit('saveandstayleotempcp')) { $this->confirmations[] = $this->l('Update successful'); $model->clearCaches(); Tools::redirectAdmin(self::$currentIndex . '&id_leowidgets=' . $model->id . '&updateleowidgets&token=' . $this->token . '&conf=4'); } else { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . '&conf=4'); } } } } } if (Tools::isSubmit('submitBulkcorrectlinkleowidgets')) { $leowidgetsBox = Tools::getValue('leowidgetsBox'); if ($leowidgetsBox) { foreach ($leowidgetsBox as $widgetID) { $model = new LeoTempcpWidget($widgetID); $params = Tools::jsonDecode(call_user_func('base64' . '_decode', $model->params), true); $tmp = array(); foreach ($params as $widKey => $widValue) { foreach ($this->_imageField as $fVal) { if (strpos($widKey, $fVal) !== false && strpos($widValue, 'img') !== false) { // $widValue = str_replace('src="' . __PS_BASE_URI__ . 'modules/', 'src="' . __PS_BASE_URI__ . 'themes/'.$this->_theme_dir.'/img/modules/', $widValue); // $patterns = array('/\/leomanagewidgets\/data\//','/\/leobootstrapmenu\/img\//','/\/leobootstrapmenu\/images\//' // ,'/\/leomanagewidgets\/images\//','/\/leomenusidebar\/images\//'); // $replacements = array('/leomanagewidgets/','/leobootstrapmenu/','/leobootstrapmenu/','/leomanagewidgets/','/leomenusidebar/'); // $widValue = preg_replace($patterns, $replacements, $widValue); $widValue = preg_replace('/\\/themes\\/(\\w+)\\/img/', '/themes/' . $this->_theme_dir . '/img', $widValue); break; } } $tmp[$widKey] = $widValue; } $model->params = call_user_func('base64' . '_encode', Tools::jsonEncode($tmp)); $model->save(); } } } if (Tools::isSubmit('submitBulkinsertLangleowidgets')) { $leowidgetsBox = Tools::getValue('leowidgetsBox'); $id_currentLang = $this->context->language->id; $languages = Language::getLanguages(false); if ($leowidgetsBox) { foreach ($leowidgetsBox as $widgetID) { $model = new LeoTempcpWidget($widgetID); $tmp = Tools::jsonDecode(call_user_func('base64' . '_decode', $model->params), true); $defauleVal = array(); if ($tmp) { foreach ($tmp as $widKey => $widValue) { $defaulArray = explode('_', $widKey); if (strpos($widKey, '_' . $id_currentLang) !== false && $defaulArray[count($defaulArray) - 1] == $id_currentLang) { $defauleVal[$widKey] = $widValue; } } } if ($defauleVal) { foreach ($languages as $lang) { if ($lang['id_lang'] == $id_currentLang) { continue; } foreach ($defauleVal as $widKey => $widValue) { $keyRemove = Tools::substr($widKey, 0, -Tools::strlen('_' . $id_currentLang)); $keyReal = $keyRemove . '_' . $lang['id_lang']; if (!isset($tmp[$keyReal]) || trim($tmp[$keyReal]) == '') { $tmp[$keyReal] = $widValue; } } } } if ($defauleVal) { $model->params = call_user_func('base64' . '_encode', Tools::jsonEncode($tmp)); $model->save(); } } } } if (Tools::isSubmit('submitBulkcorrectContentleowidgets')) { $leowidgetsBox = Tools::getValue('leowidgetsBox'); $id_currentLang = $this->context->language->id; $languages = Language::getLanguages(false); if ($leowidgetsBox) { foreach ($leowidgetsBox as $widgetID) { $model = new LeoTempcpWidget($widgetID); $tmp = @unserialize($model->params); if (!$tmp) { $tmp = Tools::json_decode($model->params, true); } if ($tmp) { $model->params = call_user_func('base64' . '_encode', Tools::jsonEncode($tmp)); $model->save(); } } } } parent::postProcess(); }
public function __construct() { if (file_exists(_PS_MODULE_DIR_ . 'leotempcp')) { $this->_leotype = 1; if (file_exists(_PS_MODULE_DIR_ . 'leotempcp/classes/widgetbase.php')) { require_once _PS_MODULE_DIR_ . 'leotempcp/classes/widgetbase.php'; } if (file_exists(_PS_MODULE_DIR_ . 'leotempcp/classes/widget.php')) { require_once _PS_MODULE_DIR_ . 'leotempcp/classes/widget.php'; } } else { $this->_leotype = 0; if (file_exists(_PS_MODULE_DIR_ . 'leomanagewidgets/classes/widgetbase.php')) { require_once _PS_MODULE_DIR_ . 'leomanagewidgets/classes/widgetbase.php'; } if (file_exists(_PS_MODULE_DIR_ . 'leomanagewidgets/classes/widget.php')) { require_once _PS_MODULE_DIR_ . 'leomanagewidgets/classes/widget.php'; } } if ($this->_leotype == 1) { $this->version = '4.0.0'; $this->_hooksPos = array('displayBanner', 'displayNav', 'displayTop', 'displaySlideshow', 'topNavigation', 'displayTopColumn', 'displayLeftColumn', 'displayHome', 'displayContentBottom', 'displayRightColumn', 'displayBottom', 'displayFooterTop', 'displayfooter', 'displayFooterBottom', 'displayFootNav', 'productTabContent', 'displayFooterProduct', 'displayRightColumnProduct'); $this->_hookAssign = array('rightcolumn', 'leftcolumn', 'topcolumn', 'home', 'top', 'footer', 'nav'); } else { $this->version = '4.0.0'; $this->_hooksPos = array('displayTop', 'displayNav', 'displayTopColumn', 'displayLeftColumn', 'displayHome', 'displayHomeTab', 'displayHomeTabContent', 'displayRightColumn', 'displayfooter', 'displayRightColumnProduct', 'displayLeftColumnProduct', 'productTab'); $this->_hookAssign = array('rightcolumn', 'leftcolumn', 'topcolumn', 'home', 'top', 'footer'); } $this->name = 'leomanagewidgets'; $this->module_key = '233c96e3ba02bcb27be92a2509f19198'; $this->tab = 'front_office_features'; $this->author = 'LeoTheme'; $this->need_instance = 0; $this->secure_key = Tools::encrypt($this->name); $this->bootstrap = true; $this->_themeName = Context::getContext()->shop->getTheme(); parent::__construct(); if ($this->_leotype == 1 && Module::isInstalled($this->name)) { $this_version = Configuration::get('LEO_MANAGERWIDGETS_VERSION') ? Configuration::get('LEO_MANAGERWIDGETS_VERSION') : ''; LeoManagewidgetsInstall::checkVersion($this_version); } //hook name is lower //$this->_hooksException = array('displayRightColumn'=>array("")); $langList = Language::getLanguages(false); $gParam = array('class', 'active', 'hook_name', 'animate_offset', 'delay_animate', 'skin_animate', 'background_style', 'background_style_color', 'background_style_image_url', 'background_style_position', 'background_style_repeat', 'background_style_parallax_speed', 'background_style_parallax_offsetx', 'background_style_parallax_offsety', 'background_style_mouseparallax_strength', 'background_style_mouseparallax_axis', 'background_style_mouseparallax_offsetx', 'background_style_mouseparallax_offsety', 'background_video_source', 'background_video_vid', 'background_video_mp4', 'background_video_webm', 'background_video_ogg', 'background_style_fullwidth'); foreach ($langList as $lang) { $gParam[] = 'title_' . $lang['id_lang']; } $this->_groupField = array('id', 'active', 'hook_name', 'position', 'params' => $gParam); $this->_columnField = array('id', 'active', 'id_group', 'position', 'params' => array('class', 'lg', 'md', 'sm', 'xs', 'sp', 'background', 'pages', 'specific', 'controllerids', 'skinanimate', 'animateoffset', 'delayanimate')); $this->_rowField = array('id', 'id_column', 'position', 'active', 'key_widget', 'module_name', 'hook_name', 'type', 'params' => array()); if (Tools::strtolower(Tools::getValue('controller')) == 'adminmodules' && Tools::getValue('configure') == $this->name) { $leoWidget = new LeoTempcpWidget(); $this->_widgets = $leoWidget->getWidgets(); } $this->displayName = $this->l('Leo Manage Widget'); $this->description = $this->l('Leo Manage Widget support Leo FrameWork Verion 4.0.0'); }