Ejemplo n.º 1
0
 /**
  * @param SimpleXMLElement $xml
  * @param bool             $theme_dir only used if the theme directory to import is already located on the shop
  *
  * @return string|Theme return theme on success, otherwise the error as a string is returned
  */
 protected function importThemeXmlConfig(SimpleXMLElement $xml, $theme_dir = false)
 {
     $themes = Theme::getThemes();
     $name = strval($xml->variations->variation[0]['name']);
     $new_theme = new Theme();
     $new_theme->name = $name;
     $new_theme->directory = strval($xml->variations->variation[0]['directory']);
     if ($theme_dir) {
         $new_theme->name = $theme_dir;
         $new_theme->directory = $theme_dir;
     }
     foreach ($themes as $theme_object) {
         if ($theme_object->name == $new_theme->name) {
             return $this->l('Theme already installed.');
         }
     }
     $new_theme->product_per_page = Configuration::get('PS_PRODUCTS_PER_PAGE');
     if (isset($xml->variations->variation[0]['product_per_page'])) {
         $new_theme->product_per_page = intval($xml->variations->variation[0]['product_per_page']);
     }
     $new_theme->responsive = false;
     if (isset($xml->variations->variation[0]['responsive'])) {
         $new_theme->responsive = (bool) strval($xml->variations->variation[0]['responsive']);
     }
     $new_theme->default_left_column = true;
     $new_theme->default_right_column = true;
     if (isset($xml->variations->variation[0]['default_left_column'])) {
         $new_theme->default_left_column = (bool) strval($xml->variations->variation[0]['default_left_column']);
     }
     if (isset($xml->variations->variation[0]['default_right_column'])) {
         $new_theme->default_right_column = (bool) strval($xml->variations->variation[0]['default_right_column']);
     }
     $metas_xml = array();
     if ($xml->metas->meta) {
         foreach ($xml->metas->meta as $meta) {
             $meta_id = Db::getInstance()->getValue('SELECT id_meta FROM ' . _DB_PREFIX_ . 'meta WHERE page=\'' . pSQL($meta['meta_page']) . '\'');
             if ((int) $meta_id > 0) {
                 $tmp_meta = array();
                 $tmp_meta['id_meta'] = (int) $meta_id;
                 $tmp_meta['left'] = intval($meta['left']);
                 $tmp_meta['right'] = intval($meta['right']);
                 $metas_xml[] = $tmp_meta;
             }
         }
     } else {
         $metas = Db::getInstance()->executeS('SELECT id_meta FROM ' . _DB_PREFIX_ . 'meta');
         foreach ($metas as $meta) {
             $tmp_meta['id_meta'] = (int) $meta['id_meta'];
             $tmp_meta['left'] = 1;
             $tmp_meta['right'] = 1;
             $metas_xml[] = $tmp_meta;
         }
     }
     if (!is_dir(_PS_ALL_THEMES_DIR_ . $new_theme->directory)) {
         mkdir(_PS_ALL_THEMES_DIR_ . $new_theme->directory);
     }
     $new_theme->add();
     if ($new_theme->id > 0) {
         $new_theme->updateMetas($metas_xml);
     } else {
         return $this->l('Error while installing theme');
     }
     return $new_theme;
 }
 public function initContent()
 {
     $this->checkMobileNeeds();
     $themes = array();
     foreach (Theme::getThemes() as $theme) {
         $themes[] = $theme->directory;
     }
     foreach (scandir(_PS_ALL_THEMES_DIR_) as $theme_dir) {
         if ($theme_dir[0] != '.' && Validate::isDirName($theme_dir) && is_dir(_PS_ALL_THEMES_DIR_ . $theme_dir) && file_exists(_PS_ALL_THEMES_DIR_ . $theme_dir . '/preview.jpg') && !in_array($theme_dir, $themes)) {
             $theme = new Theme();
             $theme->name = $theme->directory = $theme_dir;
             $theme->add();
         }
     }
     $content = '';
     if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) {
         list($width, $height, $type, $attr) = getimagesize(_PS_IMG_DIR_ . Configuration::get('PS_LOGO'));
         Configuration::updateValue('SHOP_LOGO_HEIGHT', (int) round($height));
         Configuration::updateValue('SHOP_LOGO_WIDTH', (int) round($width));
     }
     $this->content .= $content;
     return parent::initContent();
 }
 protected function importThemeXmlConfig(SimpleXMLElement $xml, $theme_dir = false)
 {
     $attr = $xml->attributes();
     $th_name = (string) $attr->name;
     if ($this->isThemeInstalled($th_name)) {
         return array(sprintf($this->l('Theme %s already installed.'), $th_name));
     }
     $new_theme_array = array();
     foreach ($xml->variations->variation as $variation) {
         $name = strval($variation['name']);
         $new_theme = new Theme();
         $new_theme->name = $name;
         $new_theme->directory = strval($variation['directory']);
         if ($theme_dir) {
             $new_theme->name = $theme_dir;
             $new_theme->directory = $theme_dir;
         }
         if ($this->isThemeInstalled($new_theme->name)) {
             continue;
         }
         $new_theme->product_per_page = Configuration::get('PS_PRODUCTS_PER_PAGE');
         if (isset($variation['product_per_page'])) {
             $new_theme->product_per_page = intval($variation['product_per_page']);
         }
         $new_theme->responsive = false;
         if (isset($variation['responsive'])) {
             $new_theme->responsive = (bool) strval($variation['responsive']);
         }
         $new_theme->default_left_column = true;
         $new_theme->default_right_column = true;
         if (isset($variation['default_left_column'])) {
             $new_theme->default_left_column = (bool) strval($variation['default_left_column']);
         }
         if (isset($variation['default_right_column'])) {
             $new_theme->default_right_column = (bool) strval($variation['default_right_column']);
         }
         $fill_default_meta = true;
         $metas_xml = array();
         if ($xml->metas->meta) {
             foreach ($xml->metas->meta as $meta) {
                 $meta_id = Db::getInstance()->getValue('SELECT id_meta FROM ' . _DB_PREFIX_ . 'meta WHERE page=\'' . pSQL($meta['meta_page']) . '\'');
                 if ((int) $meta_id > 0) {
                     $tmp_meta = array();
                     $tmp_meta['id_meta'] = (int) $meta_id;
                     $tmp_meta['left'] = intval($meta['left']);
                     $tmp_meta['right'] = intval($meta['right']);
                     $metas_xml[(int) $meta_id] = $tmp_meta;
                 }
             }
             $fill_default_meta = false;
             if (count($xml->metas->meta) < (int) Db::getInstance()->getValue('SELECT count(*) FROM ' . _DB_PREFIX_ . 'meta')) {
                 $fill_default_meta = true;
             }
         }
         if ($fill_default_meta == true) {
             $metas = Db::getInstance()->executeS('SELECT id_meta FROM ' . _DB_PREFIX_ . 'meta');
             foreach ($metas as $meta) {
                 if (!isset($metas_xml[(int) $meta['id_meta']])) {
                     $tmp_meta['id_meta'] = (int) $meta['id_meta'];
                     $tmp_meta['left'] = $new_theme->default_left_column;
                     $tmp_meta['right'] = $new_theme->default_right_column;
                     $metas_xml[(int) $meta['id_meta']] = $tmp_meta;
                 }
             }
         }
         if (!is_dir(_PS_ALL_THEMES_DIR_ . $new_theme->directory)) {
             if (!mkdir(_PS_ALL_THEMES_DIR_ . $new_theme->directory)) {
                 return sprintf($this->l('Error while creating %s directory'), _PS_ALL_THEMES_DIR_ . $new_theme->directory);
             }
         }
         $new_theme->add();
         if ($new_theme->id > 0) {
             $new_theme->updateMetas($metas_xml);
             $new_theme_array[] = $new_theme;
         } else {
             $new_theme_array[] = sprintf($this->l('Error while installing theme %s'), $new_theme->name);
         }
     }
     return $new_theme_array;
 }
Ejemplo n.º 4
0
    private function displayForm3()
    {
        $res = true;
        $theme_directory = Tools::getValue('theme_directory');
        $xml = simplexml_load_file(_IMPORT_FOLDER_ . XMLFILENAME);
        $this->xml = $xml;
        if ($this->selected_variations && count($this->selected_variations) > 0) {
            $ok = array();
            foreach ($this->selected_variations as $variation) {
                if ($variation == $this->default_theme) {
                    continue;
                }
                if ($variation != $theme_directory) {
                    $theme_directory = $variation;
                }
                if (empty($theme_directory)) {
                    $theme_directory = str_replace(' ', '', (string) $this->xml['name']);
                }
                if (_PS_VERSION_ < '1.5') {
                    self::recurseCopy(_IMPORT_FOLDER_ . 'themes/' . $variation, _PS_ALL_THEMES_DIR_ . $variation);
                    if (file_exists(_PS_ALL_THEMES_DIR_ . $variation)) {
                        $ok[] = $variation;
                    }
                } else {
                    $target_dir = _PS_ALL_THEMES_DIR_ . $theme_directory;
                    $res &= self::recurseCopy(_IMPORT_FOLDER_ . 'themes/' . $variation, $target_dir);
                    $new_theme = new Theme();
                    $new_theme->name = (string) $this->xml['name'];
                    $new_theme->directory = $theme_directory;
                    $name_exist = true;
                    // Check name theme
                    $themes = $new_theme->getThemes();
                    foreach ($themes as $row) {
                        if ($row->name == $new_theme->name) {
                            $name_exist &= false;
                        }
                    }
                    if ($name_exist) {
                        $res &= $new_theme->add();
                    }
                    if ($res) {
                        $ok[] = $variation;
                    }
                }
            }
            if (count($ok) > 0) {
                $msg = $this->l('The following themes were successfully imported:') . '<ul><i>';
                foreach ($ok as $row) {
                    $msg .= '<li> ' . $row . '</li>';
                }
                $msg .= '</i></ul>';
                $this->_msg = parent::displayConfirmation($msg);
            }
        }
        self::getModules();
        if (file_exists(_IMPORT_FOLDER_ . 'doc') && count($xml->docs->doc) != 0) {
            self::loadDocForm();
        }
        $this->_html .= '<fieldset>';
        if ($this->to_install && count($this->to_install) > 0) {
            $var = '';
            foreach ($this->to_install as $row) {
                if (file_exists(_IMPORT_FOLDER_ . 'modules/' . $row)) {
                    $module_already_exists = file_exists(_PS_MODULE_DIR_ . $row);
                    $var .= '<input type="checkbox" name="modulesToExport[]" id="' . $row . '" value="' . $row . '" checked="checked" />
						<label style="display:bock;float:none" for="' . $row . '">' . $row . ($module_already_exists ? ' <span style="font-size:0.8em;color:red;">' . $this->l('Warning: a module with the same name already exists.') . '</span>' : '') . '</label><br />';
                }
            }
            if ($var != '') {
                $this->_html .= '
					<fieldset>
						<legend>' . $this->l('Select the theme\'s modules you wish to install') . '</legend>
						<p class="margin-form">' . $var . '</p>
					</fieldset>
					<p>&nbsp;</p>';
            }
        }
        $var = '';
        if (is_array($this->to_enable) && !empty($this->to_enable)) {
            $list_to_disabled = array_diff($this->native_modules, $this->to_enable);
        } else {
            $list_to_disabled = $this->native_modules;
        }
        foreach ($list_to_disabled as $row) {
            $obj = Module::getInstanceByName($row);
            if (Validate::isLoadedObject($obj)) {
                if (!file_exists(_IMPORT_FOLDER_ . 'modules/' . $row) && $obj->tab == 'front_office_features') {
                    $var .= '<input type="checkbox" name="modulesToDisable[]" id="' . $row . '" value="' . $row . '" checked="checked" />
						<label style="display:bock;float:none" for="' . $row . '">' . $row . '</label><br />';
                }
            }
        }
        if (!empty($var)) {
            $this->_html .= '
				<fieldset>
					<legend>' . $this->l('Select the modules which must be disabled for this theme') . '</legend>
					<p class="margin-form">' . $var . '</p>
				</fieldset>
				<p>&nbsp;</p>';
        }
        $this->_html .= '
			<fieldset>
				<legend>' . $this->l('Native modules configuration') . '</legend>
				<p>' . $this->l('This option determines which existing native modules have to be enabled/disabled.') . '</p>
				<ul class="margin-form" style="list-style:none">
					<li>
						<input type="radio" name="nativeModules" value="1" id="nativemoduleconfig1"/>
						<label style="display:bock;float:none" for="nativemoduleconfig1">' . $this->l('Keep my current configuration') . '</label>
					</li>
					<li>
						<input type="radio" name="nativeModules" value="2" id="nativemoduleconfig2" checked="checked" />
						<label style="display:bock;float:none" for="nativemoduleconfig2">' . $this->l('Use the theme\'s configuration (recommended)') . '</label>
					</li>
					<li>
						<input type="radio" name="nativeModules" value="3" id="nativemoduleconfig3" />
						<label style="display:bock;float:none" for="nativemoduleconfig3">' . $this->l('Use both my configuration and the theme\'s configuration') . '</label>
					</li>
				</ul>
			</fieldset>
			<p>&nbsp;</p>';
        if ($this->context->shop->isFeatureActive()) {
            $helper_form = new HelperForm();
            $this->_html .= '
			<fieldset>
				<legend>' . $this->l('Select the shop that will use this theme:') . '</legend>
				<div class="margin-form">' . $helper_form->renderAssoShop() . '</div>
			</fieldset>
			<p>&nbsp;</p>';
        }
        $this->_html .= '
			<p class="clear">&nbsp;</p>
			<input type="submit" class="button" name="prevThemes" value="' . $this->l('Previous') . '" />
			<input type="submit" class="button" name="submitModules" value="' . $this->l('Next') . '" />
		</fieldset>
		</form>';
    }
Ejemplo n.º 5
0
    private function displayForm3()
    {
        $res = true;
        $theme_directory = Tools::getValue('theme_directory');
        $xml = simplexml_load_file(_IMPORT_FOLDER_ . XMLFILENAME);
        $this->xml = $xml;
        if ($this->selected_variations && count($this->selected_variations) > 0) {
            $ok = array();
            foreach ($this->selected_variations as $variation) {
                if ($variation == $this->default_theme) {
                    continue;
                }
                if ($variation != $theme_directory) {
                    $theme_directory .= $variation;
                }
                if (empty($theme_directory)) {
                    $theme_directory = str_replace(' ', '', (string) $this->xml['name']);
                }
                $target_dir = _PS_ALL_THEMES_DIR_ . $theme_directory;
                $res &= self::recurseCopy(_IMPORT_FOLDER_ . 'themes/' . $variation, $target_dir);
                $new_theme = new Theme();
                $new_theme->name = (string) $this->xml['name'];
                $new_theme->directory = $theme_directory;
                $name_exist = true;
                // Check name theme
                $themes = $new_theme->getThemes();
                foreach ($themes as $row) {
                    if ($row->name == $new_theme->name) {
                        $name_exist &= false;
                    }
                }
                if ($name_exist) {
                    $res &= $new_theme->add();
                }
                if ($res) {
                    $ok[] = $variation;
                }
            }
            if (count($ok) > 0) {
                $msg = $this->l('The following themes were successfully imported') . ':<ul><i>';
                foreach ($ok as $row) {
                    $msg .= '<li> ' . $row;
                }
                $msg .= '</i></ul>';
                $this->_msg = parent::displayConfirmation($msg);
            }
        }
        self::getModules();
        if (file_exists(_IMPORT_FOLDER_ . 'doc') && count($xml->docs->doc) != 0) {
            self::loadDocForm();
        }
        $this->_html .= '<fieldset>';
        if ($this->to_install && count($this->to_install) > 0) {
            $var = '';
            foreach ($this->to_install as $row) {
                if (file_exists(_IMPORT_FOLDER_ . 'modules/' . $row)) {
                    $module_already_exists = file_exists(_PS_MODULE_DIR_ . $row);
                    $var .= '<input type="checkbox" name="modulesToExport[]" id="' . $row . '" value="' . $row . '" checked="checked" />
						<label style="display:bock;float:none" for="' . $row . '">' . $row . ($module_already_exists ? ' <span style="font-size:0.8em">-> ' . $this->l('Warning: a module with the same name already exists') . '</span>' : '') . '</label><br />';
                }
            }
            if ($var != '') {
                $this->_html .= '
					<fieldset>
						<legend>' . $this->l('Select the theme\'s modules you wish to install') . '</legend>
						<p class="margin-form">' . $var . '</p>
					</fieldset>
					<p>&nbsp;</p>';
            }
        }
        $var = '';
        foreach (array_diff($this->native_modules, $this->to_disable) as $row) {
            $obj = Module::getInstanceByName($row);
            if (Validate::isLoadedObject($obj)) {
                if (!file_exists(_IMPORT_FOLDER_ . 'modules/' . $row) && $obj->tab == 'front_office_features') {
                    $var .= '<input type="checkbox" name="modulesToDisable[]" id="' . $row . '" value="' . $row . '" />
						<label style="display:bock;float:none" for="' . $row . '">' . $row . '</label><br />';
                }
            }
        }
        $this->_html .= '
			<fieldset>
				<legend>' . $this->l('Select modules which must be disabled for this theme') . '</legend>
				<p class="margin-form">' . $var . '</p>
			</fieldset>
			<p>&nbsp;</p>';
        $this->_html .= '
			<fieldset>
				<legend>' . $this->l('Native modules configuration') . '</legend>
				<ul class="margin-form" style="list-style:none">
					<li>
						<input type="radio" name="nativeModules" value="1" id="nativemoduleconfig1"/>
						<label style="display:bock;float:none" for="nativemoduleconfig1">' . $this->l('Current configuration') . '</label>
					</li>
					<li>
						<input type="radio" name="nativeModules" value="2" id="nativemoduleconfig2" checked="checked" />
						<label style="display:bock;float:none" for="nativemoduleconfig2">' . $this->l('Theme\'s configuration') . '</label>
					</li>
					<li>
						<input type="radio" name="nativeModules" value="3" id="nativemoduleconfig3" />
						<label style="display:bock;float:none" for="nativemoduleconfig3">' . $this->l('Both') . '</label>
					</li>
				</ul>
			</fieldset>
			<p>&nbsp;</p>';
        if (Shop::isFeatureActive()) {
            $helper_form = new HelperForm();
            $this->_html .= '
			<fieldset>
				<legend>' . $this->l('Select your shop that will use this theme:') . '</legend>
				<div class="margin-form">' . $helper_form->renderAssoShop() . '</div>
			</fieldset>
			<p>&nbsp;</p>';
        }
        $this->_html .= '
			<p class="clear">&nbsp;</p>
			<input type="submit" class="button" name="prevThemes" value="' . $this->l('Previous') . '" />
			<input type="submit" class="button" name="submitModules" value="' . $this->l('Next') . '" />
		</fieldset>
		</form>
		<script type="text/javascript">
			$(document).ready(function() {
					$.ajax({
						type : "POST",
						url : "' . str_replace('index', 'ajax-tab', AdminController::$currentIndex) . '",
						data :	{
							"theme_list" : ' . Tools::jsonEncode(array((string) $this->xml->theme_key)) . ',
							"controller" : "AdminModules",
							"action" : "wsThemeCall",
							"token" : "' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id) . '"
						},
						dataType: "json",
						success: function(json)
						{
							//console.log(json);
						},
						error: function(xhr, ajaxOptions, thrownError)
						{
							//jAlert("TECHNICAL ERROR"+res);
						}
					});
				});
		</script>';
    }