Exemplo n.º 1
0
 /**
  * Process posting data
  */
 public function postProcess()
 {
     if (Tools::getValue('action') && Tools::getValue('action') == 'savedata' && Tools::getValue('customize')) {
         $data = LeoFrameworkHelper::getPost(array('action-mode', 'saved_file', 'newfile', 'customize', 'customize_match'), 0);
         $selectors = $data['customize'];
         $matches = $data['customize_match'];
         $output = '';
         $cache = array();
         foreach ($selectors as $match => $customizes) {
             $output .= "\r\n/* customize for {$match} */ \r\n";
             foreach ($customizes as $key => $customize) {
                 if (isset($matches[$match]) && isset($matches[$match][$key])) {
                     $tmp = explode('|', $matches[$match][$key]);
                     $attribute = Tools::strtolower(trim($tmp[1]));
                     if (trim($customize)) {
                         $output .= $tmp[0] . ' { ';
                         if ($attribute == 'background-image') {
                             $output .= $attribute . ':url(' . $customize . ')';
                         } elseif ($attribute == 'font-size') {
                             $output .= $attribute . ':' . $customize . 'px';
                         } else {
                             if (strpos($attribute, 'color') !== false) {
                                 $output .= $attribute . ':#' . $customize;
                             } else {
                                 $output .= $attribute . ':' . $customize;
                             }
                         }
                         $output .= "} \r\n";
                     }
                     $cache[$match][] = array('val' => $customize, 'selector' => $tmp[0], 'attr' => $tmp[1]);
                 }
             }
         }
         if (!empty($data['saved_file'])) {
             if ($data['saved_file'] && file_exists($this->themeCustomizePath . $data['saved_file'] . '.css')) {
                 unlink($this->themeCustomizePath . $data['saved_file'] . '.css');
             }
             if ($data['saved_file'] && file_exists($this->themeCustomizePath . $data['saved_file'] . '.json')) {
                 unlink($this->themeCustomizePath . $data['saved_file'] . '.json');
             }
         }
         if (empty($data['newfile'])) {
             $nameFile = $data['saved_file'] ? $data['saved_file'] : 'profile-' . time();
         } else {
             $nameFile = preg_replace('#\\s+#', '-', trim($data['newfile']));
         }
         if ($data['action-mode'] != 'save-delete') {
             if (!is_dir($this->themeCustomizePath)) {
                 mkdir($this->themeCustomizePath, 0755);
             }
             if (!empty($output)) {
                 LeoFrameworkHelper::writeToCache($this->themeCustomizePath, $nameFile, $output);
             }
             if (!empty($cache)) {
                 LeoFrameworkHelper::writeToCache($this->themeCustomizePath, $nameFile, Tools::jsonEncode($cache), 'json');
             }
         }
         Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token);
     }
 }
Exemplo n.º 2
0
 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();
             # GET POST - BEGIN
             $widget_type = Tools::getValue('widget_type');
             $file_name = _PS_MODULE_DIR_ . 'leotempcp/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 = LeoFrameworkHelper::getPost($keys, 0);
             $keys = array('widget_title');
             $post += LeoFrameworkHelper::getPost($keys, 1);
             $keys = $widget->getConfigKey(0);
             $post += LeoFrameworkHelper::getPost($keys, 0);
             $keys = $widget->getConfigKey(1);
             $post += LeoFrameworkHelper::getPost($keys, 1);
             $keys = $widget->getConfigKey(2);
             $post += LeoFrameworkHelper::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::getValue($fVal . '_' . $language['id_lang'])) {
                                 $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 {
                     $model->clearCaches();
                     if (Tools::isSubmit('saveandstayleotempcp')) {
                         $this->confirmations[] = $this->l('Update successful');
                         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 {
                     $model->clearCaches();
                     if (Tools::isSubmit('saveandstayleotempcp')) {
                         $this->confirmations[] = $this->l('Update successful');
                         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);
                             //remove comment when install theme base
                             //$widValue = str_replace('/prestashop/base-theme/themes/', __PS_BASE_URI__. 'themes/', $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();
 }