コード例 #1
0
    public function saveThemeConfigs()
    {
        $id_shop = Context::getContext()->shop->id;
        $customName = $id_shop . 'custom';
        //add new file if don't exist
        if (!file_exists($this->themePath . 'css/local/' . $customName . '.css')) {
            if (!is_dir($this->themePath . 'css/local/')) {
                mkdir($this->themePath . 'css/local/', 755);
            }
            LeoFrameworkHelper::writeToCache($this->themePath . 'css/local/', $customName, "", 'css');
        }
        if (!file_exists($this->themePath . 'js/local/' . $customName . '.js')) {
            if (!is_dir($this->themePath . 'js/local/')) {
                mkdir($this->themePath . 'js/local/', 755);
            }
            LeoFrameworkHelper::writeToCache($this->themePath . 'js/local/', $customName, "", 'js');
        }
        $t = $this->themePath . 'css/local/' . $customName . '.css';
        if (is_dir($this->themePath . 'css/local/')) {
            if (is_writeable($t)) {
                $css = trim(Tools::getValue($this->getConfigName('C_CODECSS')));
                if ($css) {
                    LeoFrameworkHelper::writeToCache($this->themePath . 'css/local/', $customName, $css, 'css');
                } else {
                    if (file_exists($t) && filesize($t)) {
                        @unlink($t);
                        LeoFrameworkHelper::writeToCache($this->themePath . 'css/local/', $customName, "", 'css');
                    }
                }
            }
        }
        $t = $this->themePath . 'js/local/' . $customName . '.js';
        if (is_dir($this->themePath . 'js/local/')) {
            if (is_writeable($t)) {
                $js = trim(Tools::getValue($this->getConfigName('C_CODEJS')));
                if ($js) {
                    LeoFrameworkHelper::writeToCache($this->themePath . 'js/local/', $customName, $js, 'js');
                } else {
                    if (file_exists($t) && filesize($t)) {
                        @unlink($t);
                        LeoFrameworkHelper::writeToCache($this->themePath . 'js/local/', $customName, "", 'js');
                    }
                }
            }
        }
        $languages = Language::getLanguages(false);
        $this->makeFieldsOptions();
        $content = '';
        //echo "<pre>";print_r($this->fields_options);die;
        foreach ($this->fields_options as $f) {
            foreach ($f['form']['input'] as $input) {
                if ($input['name'] == $this->getConfigName('C_CODECSS')) {
                    continue;
                }
                if (isset($input['lang'])) {
                    $data = array();
                    foreach ($languages as $lang) {
                        $v = Tools::getValue(trim($input['name']) . '_' . $lang['id_lang']);
                        $data[$lang['id_lang']] = $v ? $v : $input['default'];
                    }
                    Configuration::updateValue(trim($input['name']), $data);
                } else {
                    $v = Tools::getValue($input['name'], Configuration::get($input['name']));
                    $dataSave = $v ? $v : $input['default'];
                    Configuration::updateValue(trim($input['name']), $dataSave);
                    if (trim($input['name']) == $this->getConfigName('listing_mode')) {
                        if (trim($dataSave) == '') {
                            $dataSave = 'grid';
                        }
                        $content .= '
{assign var="LISTING_GRIG_MODE" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('grid_column')) {
                        if (trim($dataSave) == '') {
                            $dataSave = '3';
                        }
                        $content .= '
{assign var="LISTING_PRODUCT_COLUMN" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('grid_column_tablet')) {
                        if (trim($dataSave) == '') {
                            $dataSave = '2';
                        }
                        $content .= '
{assign var="LISTING_PRODUCT_TABLET" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('grid_column_mobile')) {
                        if (trim($dataSave) == '') {
                            $dataSave = '1';
                        }
                        $content .= '
{assign var="LISTING_PRODUCT_MOBILE" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('grid_column_module')) {
                        if (trim($dataSave) == '') {
                            $dataSave = '4';
                        }
                        $content .= '
{assign var="LISTING_PRODUCT_COLUMN_MODULE" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('enable_color')) {
                        $content .= '
{assign var="ENABLE_COLOR" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('enable_wishlist')) {
                        $content .= '
{assign var="ENABLE_WISHLIST" value="' . $dataSave . '" scope="global"}';
                    } elseif (trim($input['name']) == $this->getConfigName('enable_responsive')) {
                        $content .= '{assign var="ENABLE_RESPONSIVE" value="' . $dataSave . '" scope="global"}';
                    }
                }
            }
        }
        if (is_writeable($this->themePath . 'layout/setting.tpl')) {
            $content .= '
{if $LISTING_PRODUCT_COLUMN=="5"}
    {assign var="colValue" value="col-xs-{12/$LISTING_PRODUCT_MOBILE} col-sm-{12/$LISTING_PRODUCT_TABLET} col-md-2-4" scope="global"}
{else}
    {assign var="colValue" value="col-xs-{12/$LISTING_PRODUCT_MOBILE} col-sm-{12/$LISTING_PRODUCT_TABLET} col-md-{12/$LISTING_PRODUCT_COLUMN}" scope="global"}
{/if}';
            LeoFrameworkHelper::writeToCache($this->themePath . 'layout/', 'setting', $content, 'tpl');
        }
    }
コード例 #2
0
 /**
  * Process posting data
  */
 public function postProcess()
 {
     if (Tools::getValue('action') && Tools::getValue('action') == 'savedata' && Tools::getValue('customize')) {
         $data = $_POST;
         //echo "<pre>";print_r($data);die;
         $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);
     }
 }