Example #1
0
 private function _setGroupData($groupsList, $hook_name)
 {
     foreach ($groupsList as &$group) {
         if (isset($group['columns'])) {
             foreach ($group['columns'] as &$column) {
                 $pages = array();
                 if (isset($column['pages']) && $column['pages']) {
                     $column['pages'] = str_replace(', ', ',', $column['pages']);
                     $pages = explode(',', $column['pages']);
                 }
                 if (isset($column['rows'])) {
                     foreach ($column['rows'] as &$row) {
                         //is a widget
                         if ($row['type'] == '0') {
                             $content = $this->_widgets->renderContent($row['key_widget']);
                             $content['type'] = LeomanagewidgetsHelper::processWidgetType($hook_name, $row['key_widget'], $content['type'], $content['data']);
                             //if ($this->_load_owl_carousel_lib == false)
                             //	$this->_load_owl_carousel_lib = LeomanagewidgetsHelper::enableLoadOwlCarouselLib($content['data']);
                             $row['content'] = $this->getWidgetContent($hook_name, $row['key_widget'], $content['type'], $content['data']);
                             //is a module
                         } else {
                             if (isset($row['module_name']) && isset($row['hook_name']) && $row['module_name'] && $row['hook_name']) {
                                 $row['content'] = $this->execModuleHook($row['hook_name'], array(), $row['module_name'], false, $this->context->shop->id);
                             }
                         }
                     }
                 }
             }
         }
     }
     # validate module
     unset($pages);
     return $groupsList;
 }
 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();
 }
Example #3
0
 private function _setGroupData($groupsList, $hook_name)
 {
     foreach ($groupsList as &$group) {
         if (isset($group["columns"])) {
             foreach ($group["columns"] as &$column) {
                 $pages = array();
                 if (isset($column["pages"]) && $column["pages"]) {
                     $column["pages"] = str_replace(", ", ",", $column["pages"]);
                     $pages = explode(",", $column["pages"]);
                 }
                 if (isset($column["rows"])) {
                     foreach ($column["rows"] as &$row) {
                         //is a widget
                         if ($row["type"] == "0") {
                             $content = $this->_widgets->renderContent($row["key_widget"]);
                             $content['type'] = LeomanagewidgetsHelper::processWidgetType($hook_name, $row["key_widget"], $content['type'], $content['data']);
                             if ($this->_load_owl_carousel_lib == false) {
                                 $this->_load_owl_carousel_lib = LeomanagewidgetsHelper::enableLoadOwlCarouselLib($content['data']);
                             }
                             $row["content"] = $this->getWidgetContent($hook_name, $row["key_widget"], $content['type'], $content['data']);
                             //is a module
                         } else {
                             if (isset($row["module_name"]) && isset($row["hook_name"]) && $row["module_name"] && $row["hook_name"]) {
                                 $row["content"] = $this->execModuleHook($row["hook_name"], array(), $row["module_name"], false, $this->context->shop->id);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $groupsList;
 }