/controllers/admin/AdminThemesController.php
PHP | 2985 lines | 2509 code | 342 blank | 134 comment | 426 complexity | 30ae876883642a9535e5534243cd15b6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * 2007-2014 PrestaShop
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@prestashop.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
- * versions in the future. If you wish to customize PrestaShop for your
- * needs please refer to http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2014 PrestaShop SA
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- class AdminThemesControllerCore extends AdminController
- {
- const MAX_NAME_LENGTH = 128;
- public function __construct()
- {
- $this->bootstrap = true;
- parent::__construct();
- }
- /** This value is used in isThemeCompatible method. only version node with an
- * higher version number will be used in [theme]/config.xml
- * @since 1.4.0.11, check theme compatibility 1.4
- * @static
- */
- public static $check_features_version = '1.4';
- /** $check_features is a multidimensional array used to check [theme]/config.xml values,
- * and also checks prestashop current configuration if not match.
- * @static
- */
- public static $check_features = array(
- 'ccc' => array(
- 'attributes' => array(
- 'available' => array(
- 'value' => 'true',
- /*
- * accepted attribute value if value doesn't match, prestashop configuration value must have those values
- */
- 'check_if_not_valid' => array(
- 'PS_CSS_THEME_CACHE' => 0,
- 'PS_JS_THEME_CACHE' => 0,
- 'PS_HTML_THEME_COMPRESSION' => 0,
- 'PS_JS_HTML_THEME_COMPRESSION' => 0,
- ),
- ),
- ),
- 'error' => 'This theme may not correctly use PrestaShop\'s "combine, compress and cache" options.',
- 'tab' => 'AdminPerformance',
- ),
- 'guest_checkout' => array(
- 'attributes' => array(
- 'available' => array(
- 'value' => 'true',
- 'check_if_not_valid' => array('PS_GUEST_CHECKOUT_ENABLED' => 0)
- ),
- ),
- 'error' => 'This theme may not correctly use PrestaShop\'s "guest checkout" feature.',
- 'tab' => 'AdminPreferences',
- ),
- 'one_page_checkout' => array(
- 'attributes' => array(
- 'available' => array(
- 'value' => 'true',
- 'check_if_not_valid' => array('PS_ORDER_PROCESS_TYPE' => 0),
- ),
- ),
- 'error' => 'This theme may not correctly use PrestaShop\'s "one-page checkout" feature.',
- 'tab' => 'AdminPreferences',
- ),
- 'store_locator' => array(
- 'attributes' => array(
- 'available' => array(
- 'value' => 'true',
- 'check_if_not_valid' => array(
- 'PS_STORES_SIMPLIFIED' => 0,
- 'PS_STORES_DISPLAY_FOOTER' => 0
- ),
- )
- ),
- 'error' => 'This theme may not correctly use PrestaShop\'s "store locator" feature.',
- 'tab' => 'AdminStores',
- )
- );
- public $className = 'Theme';
- public $table = 'theme';
- protected $toolbar_scroll = false;
- private $img_error;
- public function init()
- {
- // No cache for auto-refresh uploaded logo
- header('Cache-Control: no-cache, must-revalidate');
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- parent::init();
- $this->can_display_themes = (!Shop::isFeatureActive() || Shop::getContext() == Shop::CONTEXT_SHOP) ? true : false;
- libxml_use_internal_errors(true);
- $this->addJS(_PS_JS_DIR_.'admin_themes.js');
- //get addons themes
- if ($this->logged_on_addons)
- {
- if (!$this->isFresh(Theme::CACHE_FILE_CUSTOMER_THEMES_LIST, 86400))
- file_put_contents(_PS_ROOT_DIR_.Theme::CACHE_FILE_CUSTOMER_THEMES_LIST, Tools::addonsRequest('customer_themes'));
- $customer_themes_list = file_get_contents(_PS_ROOT_DIR_.Theme::CACHE_FILE_CUSTOMER_THEMES_LIST);
- if (!empty($customer_themes_list) && $customer_themes_list_xml = simplexml_load_string($customer_themes_list))
- {
- foreach ($customer_themes_list_xml->theme as $addons_theme)
- {
- //get addons theme if folder does not exist
- $ids_themes = unserialize(Configuration::get('PS_ADDONS_THEMES_IDS'));
- if (!is_array($ids_themes) || (is_array($ids_themes) && !in_array((string)$addons_theme->id, $ids_themes)))
- {
- $zip_content = Tools::addonsRequest('module', array(
- 'id_module' => pSQL($addons_theme->id),
- 'username_addons' => pSQL(trim($this->context->cookie->username_addons)),
- 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))
- );
- $uniqid = uniqid();
- $sandbox = _PS_CACHE_DIR_.'sandbox'.DIRECTORY_SEPARATOR.$uniqid.DIRECTORY_SEPARATOR;
- mkdir($sandbox);
- file_put_contents($sandbox.(string)$addons_theme->name.'.zip', $zip_content);
- if ($theme_directory = $this->extractTheme($sandbox.(string)$addons_theme->name.'.zip', $sandbox))
- $ids_themes[$theme_directory] = (string)$addons_theme->id;
- Tools::deleteDirectory($sandbox);
- }
- Configuration::updateValue('PS_ADDONS_THEMES_IDS', serialize($ids_themes));
- }
- }
- }
- $all_themes = Theme::getThemes();
- $themes = array();
- $other_themes = array();
- $cur_theme = array();
- foreach ($all_themes as $theme)
- {
- if (file_exists(_PS_ALL_THEMES_DIR_.$theme->directory.'/preview.jpg'))
- {
- $themes[] = array('id' => $theme->id, 'name' => $theme->name, 'preview' => '../themes/'.$theme->directory.'/preview.jpg');
- if ($theme->id == $this->context->shop->id_theme)
- {
- if (file_exists(_PS_ROOT_DIR_.'/config/xml/themes/'.$theme->directory.'.xml'))
- $config_file = _PS_ROOT_DIR_.'/config/xml/themes/'.$theme->directory.'.xml';
- elseif ($theme->name == 'default-bootstrap')
- $config_file = _PS_ROOT_DIR_.'/config/xml/themes/default.xml';
- else
- $config_file = false;
- if ($config_file)
- {
- $cur_theme['theme_id'] = $theme->id;
- $xml_theme = @simplexml_load_file($config_file);
- if ($xml_theme !== false)
- {
- foreach ($xml_theme->attributes() as $key => $value)
- $cur_theme['theme_'.$key] = (string)$value;
- foreach ($xml_theme->author->attributes() as $key => $value)
- $cur_theme['author_'.$key] = (string)$value;
- if ($cur_theme['theme_name'] == 'default-bootstrap')
- $cur_theme['tc'] = Module::isEnabled('themeconfigurator');
- }
- }
- else
- {
- // If no xml we use data from database
- $cur_theme['theme_id'] = $theme->id;
- $cur_theme['theme_name'] = $theme->name;
- $cur_theme['theme_directory'] = $theme->directory;
- }
- }
- else
- $other_themes[] = array('id' => $theme->id, 'name' => $theme->name, 'preview' => '../themes/'.$theme->directory.'/preview.jpg');
- }
- $themes_directory[] = $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_directory)
- )
- {
- $config_file = false;
- $default_config = _PS_ROOT_DIR_.'/config/xml/themes/default.xml';
- $theme_config = _PS_ROOT_DIR_.'/config/xml/themes/'.$theme_dir.'.xml';
- if (file_exists($theme_config))
- $config_file = $theme_config;
- elseif (file_exists($default_config))
- $config_file = $default_config;
- if ($config_file)
- {
- $theme_installed = $this->importThemeXmlConfig(simplexml_load_file($config_file), $theme_dir);
- foreach ($theme_installed as $item)
- if (Validate::isLoadedObject($item) && file_exists(_PS_ALL_THEMES_DIR_.$item->directory.'/preview.jpg'))
- $themes[] = array('id' => $item->id, 'name' => $item->name, 'preview' => '../themes/'.$item->directory.'/preview.jpg');
- }
- }
- }
- // Employee languages used for link and utm_source
- $lang = new Language($this->context->language->id);
- $iso_lang_uc = strtoupper($lang->iso_code);
- $this->fields_options = array(
- 'appearance' => array(
- 'title' => $this->l('Your current theme'),
- 'icon' => 'icon-html5',
- 'tabs' => array(
- 'logo' => $this->l('Logo'),
- 'logo2' => $this->l('Invoice & Email Logos'),
- 'icons' => $this->l('Icons'),
- 'mobile' => $this->l('Mobile'),
- ),
- 'fields' => array(
- 'PS_LOGO' => array(
- 'title' => $this->l('Header logo'),
- 'hint' => $this->l('Will appear on main page. Recommended height: 52px. Maximum height on default theme: 65px.'),
- 'type' => 'file',
- 'name' => 'PS_LOGO',
- 'tab' => 'logo',
- 'thumb' => _PS_IMG_.Configuration::get('PS_LOGO')
- ),
- 'PS_LOGO_MOBILE' => array(
- 'title' => $this->l('Header logo for mobile'),
- 'desc' => ((Configuration::get('PS_LOGO_MOBILE') === false) ? '<span class="light-warning">'.$this->l('Warning: No mobile logo has been defined. The header logo will be used instead.').'</span><br />' : ''),
- 'hint' => $this->l('Will appear on the main page of your mobile template. If left undefined, the header logo will be used.'),
- 'type' => 'file',
- 'name' => 'PS_LOGO_MOBILE',
- 'tab' => 'mobile',
- 'thumb' => (Configuration::get('PS_LOGO_MOBILE') !== false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_MOBILE'))) ? _PS_IMG_.Configuration::get('PS_LOGO_MOBILE') : _PS_IMG_.Configuration::get('PS_LOGO')
- ),
- 'PS_LOGO_MAIL' => array(
- 'title' => $this->l('Mail logo'),
- 'desc' => ((Configuration::get('PS_LOGO_MAIL') === false) ? '<span class="light-warning">'.$this->l('Warning: No email logo has been identified. The header logo will be used instead.').'</span><br />' : ''),
- 'hint' => $this->l('Will appear on email headers. If undefined, the header logo will be used.'),
- 'type' => 'file',
- 'name' => 'PS_LOGO_MAIL',
- 'tab' => 'logo2',
- 'thumb' => (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_MAIL'))) ? _PS_IMG_.Configuration::get('PS_LOGO_MAIL') : _PS_IMG_.Configuration::get('PS_LOGO')
- ),
- 'PS_LOGO_INVOICE' => array(
- 'title' => $this->l('Invoice logo'),
- 'desc' => ((Configuration::get('PS_LOGO_INVOICE') === false) ? '<span class="light-warning">'.$this->l('Warning: No invoice logo has been defined. The header logo will be used instead.').'</span><br />' : ''),
- 'hint' => $this->l('Will appear on invoice headers.').' '.$this->l('Warning: you can use a PNG file for transparency, but it can take up to 1 second per page for processing. Please consider using JPG instead.'),
- 'type' => 'file',
- 'name' => 'PS_LOGO_INVOICE',
- 'tab' => 'logo2',
- 'thumb' => (Configuration::get('PS_LOGO_INVOICE') !== false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_INVOICE'))) ? _PS_IMG_.Configuration::get('PS_LOGO_INVOICE') : _PS_IMG_.Configuration::get('PS_LOGO')
- ),
- 'PS_FAVICON' => array(
- 'title' => $this->l('Favicon'),
- 'hint' => $this->l('Will appear in the address bar of your web browser.'),
- 'type' => 'file',
- 'name' => 'PS_FAVICON',
- 'tab' => 'icons',
- 'thumb' => _PS_IMG_.Configuration::get('PS_FAVICON')
- ),
- 'PS_STORES_ICON' => array(
- 'title' => $this->l('Store icon'),
- 'hint' => $this->l('Will appear on the store locator (inside Google Maps).').'<br />'.$this->l('Suggested size: 30x30, transparent GIF.'),
- 'type' => 'file',
- 'name' => 'PS_STORES_ICON',
- 'tab' => 'icons',
- 'thumb' => _PS_IMG_.Configuration::get('PS_STORES_ICON')
- ),
- 'PS_ALLOW_MOBILE_DEVICE' => array(
- 'title' => $this->l('Enable the mobile theme'),
- 'hint' => $this->l('Allows visitors browsing on mobile devices to view a lighter version of your website.'),
- 'type' => 'radio',
- 'required' => true,
- 'validation' => 'isGenericName',
- 'tab' => 'mobile',
- 'choices' => array(
- 0 => $this->l('I\'d like to disable it.'),
- 1 => $this->l('I\'d like to enable it only on smartphones.'),
- 2 => $this->l('I\'d like to enable it only on tablets.'),
- 3 => $this->l('I\'d like to enable it on both smartphones and tablets.')
- )
- ),
- ),
- 'after_tabs' => array(
- 'cur_theme' => $cur_theme,
- ),
- 'submit' => array('title' => $this->l('Save')),
- 'buttons' => array(
- 'storeLink' => array(
- 'title' => $this->l('Visit the theme store'),
- 'icon' => 'process-icon-themes',
- 'href' => 'http://addons.prestashop.com/en/3-templates-prestashop?utm_source=back-office&utm_medium=theme-button&utm_campaign=back-office-'.$iso_lang_uc,
- 'js' => 'return !window.open(this.href)'
- )
- )
- ),
- );
- if (!empty($other_themes))
- {
- $this->fields_options['theme'] = array(
- 'title' => sprintf($this->l('Select a theme for the "%s" shop'), $this->context->shop->name),
- 'description' => (!$this->can_display_themes) ? $this->l('You must select a shop from the above list if you wish to choose a theme.') : '',
- 'fields' => array(
- 'theme_for_shop' => array(
- 'type' => 'theme',
- 'themes' => $other_themes,
- 'id_theme' => $this->context->shop->id_theme,
- 'can_display_themes' => $this->can_display_themes,
- 'no_multishop_checkbox' => true
- ),
- ),
- );
- }
- }
- public function renderForm()
- {
- $get_available_themes = Theme::getAvailable(false);
- $available_theme_dir = array();
- $selected_theme_dir = null;
- $metas = Meta::getMetas();
- $formated_metas = array();
- foreach ($metas as $meta)
- {
- $meta_object = New Meta($meta['id_meta']);
- $title = $meta['page'];
- if (isset($meta_object->title[(int)$this->context->language->id]) && $meta_object->title[(int)$this->context->language->id] != '')
- $title = $meta_object->title[(int)$this->context->language->id];
- $formated_metas[$meta['id_meta']] = array(
- 'title' => $title,
- 'left' => 0,
- 'right' => 0,
- );
- }
- $image_url = false;
- if ($this->object)
- {
- if ((int)$this->object->id > 0)
- {
- $theme = New Theme((int)$this->object->id);
- $theme_metas = $theme->getMetas();
- // if no theme_meta are found, we must create them
- if (empty($theme_metas))
- {
- $metas = Db::getInstance()->executeS('SELECT id_meta FROM '._DB_PREFIX_.'meta');
- $metas_default = array();
- foreach ($metas as $meta)
- {
- $tmp_meta['id_meta'] = (int)$meta['id_meta'];
- $tmp_meta['left'] = 1;
- $tmp_meta['right'] = 1;
- $metas_default[] = $tmp_meta;
- }
- $theme->updateMetas($metas_default);
- $theme_metas = $theme->getMetas();
- }
- $image_url = '<img alt="preview" src="'.__PS_BASE_URI__.'themes/'.$theme->directory.'/preview.jpg">';
- foreach ($theme_metas as $theme_meta)
- {
- $formated_metas[$theme_meta['id_meta']]['id_theme_meta'] = (int)$theme_meta['id_theme_meta'];
- $formated_metas[$theme_meta['id_meta']]['id_meta'] = (int)$theme_meta['id_meta'];
- $formated_metas[$theme_meta['id_meta']]['left'] = (int)$theme_meta['left_column'];
- $formated_metas[$theme_meta['id_meta']]['right'] = (int)$theme_meta['right_column'];
- }
- }
- $selected_theme_dir = $this->object->directory;
- }
- foreach ($get_available_themes as $k => $dirname)
- {
- $available_theme_dir[$k]['value'] = $dirname;
- $available_theme_dir[$k]['label'] = $dirname;
- $available_theme_dir[$k]['id'] = $dirname;
- };
- $this->fields_form = array(
- 'tinymce' => false,
- 'legend' => array(
- 'title' => $this->l('Theme'),
- 'icon' => 'icon-picture'
- ),
- 'input' => array(
- array(
- 'type' => 'text',
- 'label' => $this->l('Name of the theme'),
- 'name' => 'name',
- 'required' => true,
- 'hint' => $this->l('Invalid characters:').' <>;=#{}',
- ),
- array(
- 'type' => 'file',
- 'label' => $this->l('Preview image for the theme'),
- 'name' => 'image_preview',
- 'display_image' => true,
- 'hint' => sprintf($this->l('Maximum image size: %1s'), Tools::formatBytes(Tools::getMaxUploadSize())),
- 'image' => $image_url,
- ),
- array(
- 'type' => 'switch',
- 'label' => $this->l('Default left column'),
- 'name' => 'default_left_column',
- 'hint' => $this->l('Choose a default behavior when displaying the column in a new page added by you or by a module.'),
- 'values' => array(
- array(
- 'id' => 'default_left_column_on',
- 'value' => 1,
- 'label' => $this->l('Yes')
- ),
- array(
- 'id' => 'default_left_column_off',
- 'value' => 0,
- 'label' => $this->l('No')
- )
- ),
- ),
- array(
- 'type' => 'switch',
- 'label' => $this->l('Default right column'),
- 'name' => 'default_right_column',
- 'hint' => $this->l('Choose a default behavior when displaying the column in a new page added by you or by a module.'),
- 'values' => array(
- array(
- 'id' => 'default_right_column_on',
- 'value' => 1,
- 'label' => $this->l('Yes')
- ),
- array(
- 'id' => 'default_right_column_off',
- 'value' => 0,
- 'label' => $this->l('No')
- )
- ),
- ),
- array(
- 'type' => 'text',
- 'label' => $this->l('Number of products per page'),
- 'name' => 'product_per_page',
- 'hint' => $this->l('This value will be used when activating the theme.'),
- )
- ),
- 'submit' => array(
- 'title' => $this->l('Save'),
- )
- );
- // adding a new theme, you can create a directory, and copy from an existing theme
- if ($this->display == 'add' || !Validate::isLoadedObject($this->object))
- {
- $this->fields_form['input'][] = array(
- 'type' => 'text',
- 'label' => $this->l('Name of the theme\'s directory'),
- 'name' => 'directory',
- 'required' => true,
- 'hint' => $this->l('If the directory does not exist, PrestaShop will create it automatically.'),
- );
- $theme_query = Theme::getThemes();
- $this->fields_form['input'][] = array(
- 'type' => 'select',
- 'name' => 'based_on',
- 'label' => $this->l('Copy missing files from existing theme'),
- 'hint' => $this->l('If you create a new theme from scratch, it is recommended that you use the files from the default theme as a foundation.'),
- 'options' => array(
- 'id' => 'id',
- 'name' => 'name',
- 'default' => array(
- 'value' => 0,
- 'label' => '-'
- ),
- 'query' => $theme_query,
- )
- );
- $this->fields_form['input'][] = array(
- 'type' => 'switch',
- 'label' => $this->l('Responsive'),
- 'name' => 'responsive',
- 'hint' => $this->l('Please indicate if the theme is adapted to all screen sizes (mobile, tablet, desktop).'),
- 'values' => array(
- array(
- 'id' => 'responsive_on',
- 'value' => 1,
- 'label' => $this->l('Yes')
- ),
- array(
- 'id' => 'responsive_off',
- 'value' => 0,
- 'label' => $this->l('No')
- )
- ),
- );
- }
- else
- $this->fields_form['input'][] = array(
- 'type' => 'radio',
- 'label' => $this->l('Directory'),
- 'name' => 'directory',
- 'required' => true,
- 'br' => true,
- 'values' => $available_theme_dir,
- 'selected' => $selected_theme_dir,
- 'hint' => $this->l('Please select a valid theme directory.'),
- );
- $list = '';
- if (Tools::getIsset('update'.$this->table))
- {
- $fields_list = array(
- 'title' => array(
- 'title' => $this->l('Meta'),
- 'align' => 'center',
- 'width' => 'auto'
- ),
- 'left' => array(
- 'title' => $this->l('Left column'),
- 'active' => 'left',
- 'type' => 'bool',
- 'ajax' => true
- ),
- 'right' => array(
- 'title' => $this->l('Right column'),
- 'active' => 'right',
- 'type' => 'bool',
- 'ajax' => true
- ),
- );
- $helper_list = New HelperList();
- $helper_list->tpl_vars = array('icon' => 'icon-columns');
- $helper_list->title = $this->l('Appearance of columns');
- $helper_list->no_link = true;
- $helper_list->shopLinkType = '';
- $helper_list->identifier = 'id_theme_meta';
- $helper_list->table = 'meta';
- $helper_list->tpl_vars['show_filters'] = false;
- $helper_list->currentIndex = $this->context->link->getAdminLink('AdminThemes', false);
- $helper_list->token = Tools::getAdminTokenLite('AdminThemes');
- $list = $helper_list->generateList($formated_metas, $fields_list);
- }
- return parent::renderForm().$list;
- }
- public function renderList()
- {
- return parent::renderList();
- }
- /**
- * copy $base_theme_dir into $target_theme_dir.
- *
- * @param string $base_theme_dir relative path to base dir
- * @param string $target_theme_dir relative path to target dir
- *
- * @return boolean true if success
- */
- protected static function copyTheme($base_theme_dir, $target_theme_dir)
- {
- $res = true;
- $base_theme_dir = rtrim($base_theme_dir, '/').'/';
- $base_dir = _PS_ALL_THEMES_DIR_.$base_theme_dir;
- $target_theme_dir = rtrim($target_theme_dir, '/').'/';
- $target_dir = _PS_ALL_THEMES_DIR_.$target_theme_dir;
- $files = scandir($base_dir);
- foreach ($files as $file)
- {
- if (!in_array($file[0], array('.', '..', '.svn')))
- {
- if (is_dir($base_dir.$file))
- {
- if (!is_dir($target_dir.$file))
- mkdir($target_dir.$file, Theme::$access_rights);
- $res &= AdminThemesController::copyTheme($base_theme_dir.$file, $target_theme_dir.$file);
- }
- elseif (!file_exists($target_theme_dir.$file))
- $res &= copy($base_dir.$file, $target_dir.$file);
- }
- }
- return $res;
- }
- public function processAdd()
- {
- if (Tools::getValue('directory') == '' || Tools::getValue('name') == '')
- {
- $this->errors[] = $this->l('Form invalid');
- $this->display = 'form';
- return false;
- }
- if (($new_dir = Tools::getValue('directory')) != '')
- {
- if (!Validate::isDirName($new_dir))
- {
- $this->display = 'add';
- return !($this->errors[] = sprintf(Tools::displayError('"%s" is not a valid directory name'), $new_dir));
- }
- if (Theme::getByDirectory($new_dir))
- {
- $this->display = 'add';
- return !($this->errors[] = Tools::displayError('A directory with this name already exists.'));
- }
- if (mkdir(_PS_ALL_THEMES_DIR_.$new_dir, Theme::$access_rights))
- $this->confirmations[] = $this->l('The directory was successfully created.');
- if (0 !== $id_based = (int)Tools::getValue('based_on'))
- {
- $base_theme = new Theme($id_based);
- $this->copyTheme($base_theme->directory, $new_dir);
- $base_theme = new Theme((int)Tools::getValue('based_on'));
- }
- if (isset($_FILES['image_preview']) && $_FILES['image_preview']['error'] == 0)
- {
- if (@getimagesize($_FILES['image_preview']['tmp_name']) && !ImageManager::validateUpload($_FILES['image_preview'], Tools::getMaxUploadSize()))
- {
- move_uploaded_file($_FILES['image_preview']['tmp_name'], _PS_ALL_THEMES_DIR_.$new_dir.'/preview.jpg');
- }
- else
- {
- $this->errors[] = $this->l('Image is not valid.');
- $this->display = 'form';
- return false;
- }
- }
- }
- $theme = parent::processAdd();
- if ((int)$theme->product_per_page == 0)
- {
- $theme->product_per_page = 1;
- $theme->save();
- }
- if (is_object($theme) && (int)$theme->id > 0)
- {
- $metas = Meta::getMetas();
- foreach ($metas as &$meta)
- {
- $meta['left'] = $theme->default_left_column;
- $meta['right'] = $theme->default_right_column;
- }
- $theme->updateMetas($metas, true);
- }
- return $theme;
- }
- public function processUpdate()
- {
- if (Tools::getIsset('id_theme') && Tools::getIsset('name') && Tools::getIsset('directory'))
- {
- $theme = New Theme((int)Tools::getValue('id_theme'));
- $theme->name = Tools::getValue('name');
- $theme->directory = Tools::getValue('directory');
- $theme->default_left_column = Tools::getValue('default_left_column');
- $theme->default_right_column = Tools::getValue('default_right_column');
- $nb_product_per_page = (int)Tools::getValue('product_per_page');
- if ($nb_product_per_page == 0)
- $nb_product_per_page = 1;
- $theme->product_per_page = $nb_product_per_page;
- if ($this->context->shop->id_theme == (int)Tools::getValue('id_theme'))
- Configuration::updateValue('PS_PRODUCTS_PER_PAGE', $nb_product_per_page);
- if (isset($_FILES['image_preview']) && $_FILES['image_preview']['error'] == 0)
- {
- if (@getimagesize($_FILES['image_preview']['tmp_name']) && !ImageManager::validateUpload($_FILES['image_preview'], 300000))
- {
- move_uploaded_file($_FILES['image_preview']['tmp_name'], _PS_ALL_THEMES_DIR_.$theme->directory.'/preview.jpg');
- }
- else
- {
- $this->errors[] = $this->l('Image is not valid.');
- $this->display = 'form';
- return false;
- }
- }
- $theme->update();
- }
- Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes').'&conf=29');
- }
- protected function processUpdateOptions()
- {
- parent::processUpdateOptions();
- if (!count($this->errors))
- Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes').'&conf=6');
- }
- public function processDelete()
- {
- $obj = $this->loadObject();
- if ($obj)
- {
- if ($obj->isUsed())
- {
- $this->errors[] = $this->l('The theme is being used by at least one shop. Please choose another theme before continuing.');
- return false;
- }
- $themes = array();
- foreach (Theme::getThemes() as $theme)
- {
- if ($theme->id != $obj->id)
- $themes[] = $theme->directory;
- }
- if (is_dir(_PS_ALL_THEMES_DIR_.$obj->directory) && !in_array($obj->directory, $themes))
- Tools::deleteDirectory(_PS_ALL_THEMES_DIR_.$obj->directory.'/');
- $ids_themes = unserialize(Configuration::get('PS_ADDONS_THEMES_IDS'));
- if (array_key_exists($obj->directory, $ids_themes))
- unset($ids_themes[$obj->directory]);
- $obj->removeMetas();
- }
- return parent::processDelete();
- }
- public function initPageHeaderToolbar()
- {
- parent::initPageHeaderToolbar();
- if (empty($this->display))
- {
- if (!defined('_PS_HOST_MODE_'))
- $this->page_header_toolbar_btn['import_theme'] = array(
- 'href' => self::$currentIndex.'&action=importtheme&token='.$this->token,
- 'desc' => $this->l('Add new theme', null, null, false),
- 'icon' => 'process-icon-new'
- );
- if (defined('_PS_HOST_MODE_'))
- unset($this->toolbar_btn['new']);
- $this->page_header_toolbar_btn['export_theme'] = array(
- 'href' => self::$currentIndex.'&action=exporttheme&token='.$this->token,
- 'desc' => $this->l('Export theme', null, null, false),
- 'icon' => 'process-icon-export'
- );
- }
- if ($this->display == 'importtheme')
- $this->toolbar_title[] = $this->l('Import theme');
- elseif ($this->display == 'exporttheme')
- $this->toolbar_title[] = $this->l('Export theme');
- else
- $this->toolbar_title[] = $this->l('Theme');
- $title = implode(' '.Configuration::get('PS_NAVIGATION_PIPE').' ', $this->toolbar_title);
- $this->page_header_toolbar_title = $title;
- }
- private function checkParentClass($name)
- {
- if (!$obj = Module::getInstanceByName($name))
- return false;
- if (is_callable(array(
- $obj,
- 'validateOrder'
- ))
- )
- return false;
- if (is_callable(array(
- $obj,
- 'getDateBetween'
- ))
- )
- return false;
- if (is_callable(array(
- $obj,
- 'getGridEngines'
- ))
- )
- return false;
- if (is_callable(array(
- $obj,
- 'getGraphEngines'
- ))
- )
- return false;
- if (is_callable(array(
- $obj,
- 'hookAdminStatsModules'
- ))
- )
- return false;
- else
- return true;
- }
- private function checkNames()
- {
- $author = Tools::getValue('name');
- $theme_name = Tools::getValue('theme_name');
- if (!$author || !Validate::isGenericName($author) || strlen($author) > self::MAX_NAME_LENGTH)
- $this->errors[] = $this->l('Please enter a valid author name');
- elseif (!$theme_name || !Validate::isGenericName($theme_name) || strlen($theme_name) > self::MAX_NAME_LENGTH)
- $this->errors[] = $this->l('Please enter a valid theme name');
- if (count($this->errors) > 0)
- return false;
- return true;
- }
- private function checkDocumentation()
- {
- $extensions = array(
- '.pdf',
- '.txt'
- );
- if (isset($_FILES['documentation']) && $_FILES['documentation']['name'] != '')
- {
- $extension = strrchr($_FILES['documentation']['name'], '.');
- $name = Tools::getValue('documentationName');
- if (!in_array($extension, $extensions))
- $this->errors[] = $this->l('File extension must be .txt or .pdf');
- elseif ($_FILES['documentation']['error'] > 0 || $_FILES['documentation']['size'] > 1048576)
- $this->errors[] = $this->l('An error occurred during documentation upload');
- elseif (!$name || !Validate::isGenericName($name) || strlen($name) > self::MAX_NAME_LENGTH)
- $this->errors[] = $this->l('Please enter a valid documentation name');
- }
- if (count($this->errors) > 0)
- return false;
- return true;
- }
- private function checkVersionsAndCompatibility()
- {
- $exp = '#^[0-9]+[.]+[0-9.]*[0-9]$#';
- if (!preg_match('#^[0-9][.][0-9]$#', Tools::getValue('theme_version')) ||
- !preg_match($exp, Tools::getValue('compa_from')) || !preg_match($exp, Tools::getValue('compa_to')) ||
- version_compare(Tools::getValue('compa_from'), Tools::getValue('compa_to')) == 1
- )
- $this->errors[] = $this->l('Syntax error on version field. Only digits and periods (.) are allowed, and the compatibility version should be increasing or at least be equal to the previous version.');
- if (count($this->errors) > 0)
- return false;
- return true;
- }
- private function checkPostedDatas()
- {
- $mail = Tools::getValue('email');
- $website = Tools::getValue('website');
- if ($mail && !preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $mail))
- $this->errors[] = $this->l('There is an error in your e-mail syntax!');
- elseif ($website && (!Validate::isURL($website) || !Validate::isAbsoluteUrl($website)))
- $this->errors[] = $this->l('There is an error in your URL syntax!');
- elseif (!$this->checkVersionsAndCompatibility() || !$this->checkNames() || !$this->checkDocumentation())
- return false;
- else
- return true;
- return false;
- }
- private function archiveThisFile($obj, $file, $server_path, $archive_path)
- {
- if (is_dir($server_path.$file))
- {
- $dir = scandir($server_path.$file);
- foreach ($dir as $row)
- {
- if ($row != '.' && $row != '..')
- $this->archiveThisFile($obj, $row, $server_path.$file.'/', $archive_path.$file.'/');
- }
- }
- elseif (!$obj->addFile($server_path.$file, $archive_path.$file))
- $this->error = true;
- }
- private function generateArchive()
- {
- $zip = new ZipArchive();
- $zip_file_name = md5(time()).'.zip';
- if ($zip->open(_PS_CACHE_DIR_.$zip_file_name, ZipArchive::OVERWRITE) === true)
- {
- if (!$zip->addFromString('Config.xml', $this->xml_file))
- $this->errors[] = $this->l('Can\'t create config file.');
- if (isset($_FILES['documentation']))
- if (!empty($_FILES['documentation']['tmp_name']) &&
- !empty($_FILES['documentation']['name']) &&
- !$zip->addFile($_FILES['documentation']['tmp_name'], 'doc/'.$_FILES['documentation']['name']))
- $this->errors[] = $this->l('Can\'t copy documentation.');
- $given_path = realpath(_PS_ALL_THEMES_DIR_.Tools::getValue('theme_directory'));
-
- if ($given_path !== false)
- {
- $ps_all_theme_dir_lenght = strlen(realpath(_PS_ALL_THEMES_DIR_));
- $to_compare_path = substr($given_path, 0, $ps_all_theme_dir_lenght);
- if ($to_compare_path != realpath(_PS_ALL_THEMES_DIR_))
- $this->errors[] = $this->l('Wrong theme directory path');
- else
- {
- $this->archiveThisFile($zip, Tools::getValue('theme_directory'), _PS_ALL_THEMES_DIR_, 'themes/');
- foreach ($this->to_export as $row)
- {
- if (!in_array($row, $this->native_modules))
- $this->archiveThisFile($zip, $row, _PS_ROOT_DIR_.'/modules/', 'modules/');
- }
- }
- }
- else
- $this->errors[] = $this->l('Wrong theme directory path');
- $zip->close();
- if (!$this->errors)
- {
- if (ob_get_length() > 0)
- ob_end_clean();
- ob_start();
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Cache-Control: public');
- header('Content-Description: File Transfer');
- header('Content-type: application/octet-stream');
- header('Content-Disposition: attachment; filename="'.$zip_file_name.'"');
- header('Content-Transfer-Encoding: binary');
- ob_end_flush();
- readfile(_PS_CACHE_DIR_.$zip_file_name);
- @unlink(_PS_CACHE_DIR_.$zip_file_name);
- exit;
- }
- }
- $this->errors[] = $this->l('An error occurred during the archive generation');
- }
- private function generateXML($theme_to_export, $metas)
- {
- $theme = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><!-- Copyright Prestashop --><theme></theme>');
- $theme->addAttribute('version', Tools::getValue('theme_version'));
- $theme->addAttribute('name', Tools::htmlentitiesUTF8(Tools::getValue('theme_name')));
- $theme->addAttribute('directory', Tools::htmlentitiesUTF8(Tools::getValue('theme_directory')));
- $author = $theme->addChild('author');
- $author->addAttribute('name', Tools::htmlentitiesUTF8(Tools::getValue('name')));
- $author->addAttribute('email', Tools::htmlentitiesUTF8(Tools::getValue('email')));
- $author->addAttribute('url', Tools::htmlentitiesUTF8(Tools::getValue('website')));
- $descriptions = $theme->addChild('descriptions');
- $languages = Language::getLanguages();
- foreach ($languages as $language)
- {
- $val = Tools::htmlentitiesUTF8(Tools::getValue('body_title_'.$language['id_lang']));
- $description = $descriptions->addChild('description', Tools::htmlentitiesUTF8($val));
- $description->addAttribute('iso', $language['iso_code']);
- }
- $variations = $theme->addChild('variations');
- $variation = $variations->addChild('variation');
- $variation->addAttribute('name', Tools::htmlentitiesUTF8(Tools::getValue('theme_name')));
- $variation->addAttribute('directory', Tools::getValue('theme_directory'));
- $variation->addAttribute('responsive', $theme_to_export->responsive);
- $variation->addAttribute('default_left_column', $theme_to_export->default_left_column);
- $variation->addAttribute('default_right_column', $theme_to_export->default_right_column);
- $variation->addAttribute('product_per_page', $theme_to_export->product_per_page);
- $variation->addAttribute('from', Tools::getValue('compa_from'));
- $variation->addAttribute('to', Tools::getValue('compa_to'));
- $docs = $theme->addChild('docs');
- if (isset($this->user_doc))
- foreach ($this->user_doc as $row)
- {
- $array = explode('造', $row);
- $doc = $docs->addChild('doc');
- $doc->addAttribute('name', $array[0]);
- $doc->addAttribute('path', $array[1]);
- }
- $metas_xml = $theme->addChild('metas');
- foreach ($metas as $row)
- {
- $meta_obj = New Meta((int)$row['id_meta']);
- $meta_xml = $metas_xml->addChild('meta');
- $meta_xml->addAttribute('meta_page', $meta_obj->page);
- $meta_xml->addAttribute('left', $row['left_column']);
- $meta_xml->addAttribute('right', $row['right_column']);
- }
- $modules = $theme->addChild('modules');
- if (isset($this->to_export))
- foreach ($this->to_export as $row)
- {
- if (!in_array($row, $this->native_modules))
- {
- $module = $modules->addChild('module');
- $module->addAttribute('action', 'install');
- $module->addAttribute('name', $row);
- }
- }
- foreach ($this->to_enable as $row)
- {
- $module = $modules->addChild('module');
- $module->addAttribute('action', 'enable');
- $module->addAttribute('name', $row);
- }
- foreach ($this->to_disable as $row)
- {
- $module = $modules->addChild('module');
- $module->addAttribute('action', 'disable');
- $module->addAttribute('name', $row);
- }
- $hooks = $modules->addChild('hooks');
- foreach ($this->to_hook as $row)
- {
- $array = explode(';', $row);
- $hook = $hooks->addChild('hook');
- $hook->addAttribute('module', $array[0]);
- $hook->addAttribute('hook', $array[1]);
- $hook->addAttribute('position', $array[2]);
- if (!empty($array[3]))
- $hook->addAttribute('exceptions', $array[3]);
- }
- $images = $theme->addChild('images');
- foreach ($this->image_list as $row)
- {
- $array = explode(';', $row);
- $image = $images->addChild('image');
- $image->addAttribute('name', Tools::htmlentitiesUTF8($array[0]));
- $image->addAttribute('width', $array[1]);
- $image->addAttribute('height', $array[2]);
- $image->addAttribute('products', $array[3]);
- $image->addAttribute('categories', $array[4]);
- $image->addAttribute('manufacturers', $array[5]);
- $image->addAttribute('suppliers', $array[6]);
- $image->addAttribute('scenes', $array[7]);
- }
- $this->xml_file = $theme->asXML();
- }
- public function processExportTheme()
- {
- if (Tools::isSubmit('name'))
- {
- if ($this->checkPostedDatas())
- {
- $filename = Tools::htmlentitiesUTF8($_FILES['documentation']['name']);
- $name = Tools::htmlentitiesUTF8(Tools::getValue('documentationName'));
- $this->user_doc = array($name.'造doc/'.$filename);
- $table = Db::getInstance()->executeS('
- SELECT name, width, height, products, categories, manufacturers, suppliers, scenes
- FROM `'._DB_PREFIX_.'image_type`');
- $this->image_list = array();
- foreach ($table as $row)
- {
- $this->image_list[] = $row['name'].';'.$row['width'].';'.$row['height'].';'.
- ($row['products'] == 1 ? 'true' : 'false').';'.
- ($row['categories'] == 1 ? 'true' : 'false').';'.
- ($row['manufacturers'] == 1 ? 'true' : 'false').';'.
- ($row['suppliers'] == 1 ? 'true' : 'false').';'.
- ($row['scenes'] == 1 ? 'true' : 'false');
- }
- $id_shop = Db::getInstance()->getValue('SELECT `id_shop` FROM `'._DB_PREFIX_.'shop` WHERE `id_theme` = '.(int)Tools::getValue('id_theme_export'));
- // Select the list of module for this shop
- $this->module_list = Db::getInstance()->executeS('
- SELECT m.`id_module`, m.`name`, m.`active`, ms.`id_shop`
- FROM `'._DB_PREFIX_.'module` m
- LEFT JOIN `'._DB_PREFIX_.'module_shop` ms On (m.`id_module` = ms.`id_module`)
- WHERE ms.`id_shop` = '.(int)$id_shop.'
- ');
- // Select the list of hook for this shop
- $this->hook_list = Db::getInstance()->executeS('
- SELECT h.`id_hook`, h.`name` as name_hook, hm.`position`, hm.`id_module`, m.`name` as name_module, GROUP_CONCAT(hme.`file_name`, ",") as exceptions
- FROM `'._DB_PREFIX_.'hook` h
- LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_hook` = h.`id_hook`
- LEFT JOIN `'._DB_PREFIX_.'module` m ON hm.`id_module` = m.`id_module`
- LEFT OUTER JOIN `'._DB_PREFIX_.'hook_module_exceptions` hme ON (hme.`id_module` = hm.`id_module` AND hme.`id_hook` = h.`id_hook`)
- WHERE hm.`id_shop` = '.(int)$id_shop.'
- GROUP BY `id_module`, `id_hook`
- ORDER BY `name_module`
- ');
- $this->native_modules = $this->getNativeModule();
- foreach ($this->hook_list as &$row)
- {
- $row['exceptions'] = trim(preg_replace('/(,,+)/', ',', $row['exceptions']), ',');
- }
- $this->to_install = array();
- $this->to_enable = array();
- $this->to_hook = array();
- foreach ($this->module_list as $array)
- {
- if (!self::checkParentClass($array['name']))
- continue;
- if (in_array($array['name'], $this->native_modules))
- {
- if ($array['active'] == 1)
- $this->to_enable[] = $array['name'];
- else
- $this->to_disable[] = $array['name'];
- }
- elseif ($array['active'] == 1)
- $this->to_install[] = $array['name'];
- }
- foreach ($this->native_modules as $str)
- {
- $flag = 0;
- if (!self::checkParentClass($str))
- continue;
- foreach ($this->module_list as $tmp)
- {
- if (in_array($str, $tmp))
- {
- $flag = 1;
- break;
- }
- }
- if ($flag == 0)
- $this->to_disable[] = $str;
- }
- foreach ($_POST as $key => $value)
- {
- if (strncmp($key, 'modulesToExport_module', strlen('modulesToExport_module')) == 0)
- {
- $this->to_export[] = $value;
- }
- }
- if ($this->to_install)
- foreach ($this->to_install as $string)
- {
- foreach ($this->hook_list as $tmp)
- {
- if ($tmp['name_module'] == $string)
- $this->to_hook[] = $string.';'.$tmp['name_hook'].';'.$tmp['position'].';'.$tmp['exceptions'];
- }
- }
- if ($this->to_enable)
- foreach ($this->to_enable as $string)
- {
- foreach ($this->hook_list as $tmp)
- {
- if ($tmp['name_module'] == $string)
- $this->to_hook[] = $string.';'.$tmp['name_hook'].';'.$tmp['position'].';'.$tmp['exceptions'];
- }
- }
- $theme_to_export = New Theme((int)Tools::getValue('id_theme_export'));
- $metas = $theme_to_export->getMetas();
- $this->generateXML($theme_to_export, $metas);
- $this->generateArchive();
- }
- else
- $this->display = 'exporttheme';
- }
- else
- $this->display = 'exporttheme';
- }
- private function renderExportTheme1()
- {
- $to_install = array();
- $module_list = Db::getInstance()->executeS('
- SELECT m.`id_module`, m.`name`, m.`active`, ms.`id_shop`
- FROM `'._DB_PREFIX_.'module` m
- LEFT JOIN `'._DB_PREFIX_.'module_shop` ms On (m.`id_module` = ms.`id_module`)
- WHERE ms.`id_shop` = '.(int)$this->context->shop->id.'
- ');
- // Select the list of hook for this shop
- $hook_list = Db::getInstance()->executeS('
- SELECT h.`id_hook`, h.`name` as name_hook, hm.`position`, hm.`id_module`, m.`name` as name_module, GROUP_CONCAT(hme.`file_name`, ",") as exceptions
- FROM `'._DB_PREFIX_.'hook` h
- LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_hook` = h.`id_hook`
- LEFT JOIN `'._DB_PREFIX_.'module` m ON hm.`id_module` = m.`id_module`
- LEFT OUTER JOIN `'._DB_PREFIX_.'hook_module_exceptions` hme ON (hme.`id_module` = hm.`id_module` AND hme.`id_hook` = h.`id_hook`)
- WHERE hm.`id_shop` = '.(int)$this->context->shop->id.'
- GROUP BY `id_module`, `id_hook`
- ORDER BY `name_module`
- ');
- foreach ($hook_list as &$row)
- {
- $row['exceptions'] = trim(preg_replace('/(,,+)/', ',', $row['exceptions']), ',');
- }
- $native_modules = $this->getNativeModule();
- foreach ($module_list as $array)
- {
- if (!self::checkParentClass($array['name']))
- continue;
- if (in_array($array['name'], $native_modules))
- {
- if ($array['active'] == 1)
- $to_enable[] = $array['name'];
- else
- $to_disable[] = $array['name'];
- }
- elseif ($array['active'] == 1)
- $to_install[] = $array['name'];
- }
- foreach ($native_modules as $str)
- {
- $flag = 0;
- if (!$this->checkParentClass($str))
- continue;
- foreach ($module_list as $tmp)
- {
- if (in_array($str, $tmp))
- {
- $flag = 1;
- break;
- }
- }
- if ($flag == 0)
- $to_disable[] = $str;
- }
- $employee = $this->context->employee;
- $mail = Tools::getValue('email') ? Tools::getValue('email') : $employee->email;
- $author = Tools::getValue('author_name') ? Tools::getValue('author_name') : $employee->firstname.' '.$employee->lastname;
- $website = Tools::getValue('website') ? Tools::getValue('website') : Tools::getHttpHost(true);
- $this->formatHelperArray($to_install);
- $theme = New Theme(Tools::getValue('id_theme_export'));
- $fields_form = array(
- 'form' => array(
- 'tinymce' => false,
- 'legend' => array(
- 'title' => $this->l('Theme configuration'),
- 'icon' => 'icon-picture'
- ),
- 'input' => array(
- array(
- 'type' => 'hidden',
- 'name' => 'id_theme_export'
- ),
- array(
- 'type' => 'text',
- 'name' => 'name',
- 'label' => $this->l('Name'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'email',
- 'label' => $this->l('Email'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'website',
- 'label' => $this->l('Website'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'theme_name',
- 'label' => $this->l('Theme name'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'theme_directory',
- 'label' => $this->l('Theme directory'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'body_title',
- 'lang' => true,
- 'label' => $this->l('Description'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'theme_version',
- 'label' => $this->l('Theme version'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'compa_from',
- 'label' => $this->l('Compatible from'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'compa_to',
- 'label' => $this->l('Compatible to'),
- ),
- array(
- 'type' => 'file',
- 'name' => 'documentation',
- 'label' => $this->l('Documentation'),
- ),
- array(
- 'type' => 'text',
- 'name' => 'documentationName',
- 'label' => $this->l('Documentation name'),
- ),
- ),
- 'submit' => array(
- 'title' => $this->l('Save'),
- )
- )
- );
- if (count($to_install) > 0)
- {
- $fields_form['form']['input'][] = array(
- 'type' => 'checkbox',
- 'label' => $this->l('Select the theme\'s modules that you wish to export'),
- 'values' => array(
- 'query' => $this->formatHelperArray($to_install),
- 'id' => 'id',
- 'name' => 'name'
- ),
- 'name' => 'modulesToExport',
- );
- }
- $default_language = (int)$this->context->language->id;
- $languages = $this->getLanguages();
- foreach ($languages as $language)
- {
- $fields_value['body_title'][$language['id_lang']] = '';
- }
- $helper = new HelperForm();
- $helper->languages = $languages;
- $helper->default_form_language = $default_language;
- $fields_value['name'] = $author;
- $fields_value['email'] = $mail;
- $fields_value['website'] = $website;
- $fields_value['theme_name'] = $theme->name;
- $fields_value['theme_directory'] = $theme->directory;
- $fields_value['theme_version'] = '1.0';
- $fields_value['compa_from'] = _PS_VERSION_;
- $fields_value['compa_to'] = _PS_VERSION_;
- $fields_value['id_theme_export'] = Tools::getValue('id_theme_export');
- $fields_value['documentationName'] = $this->l('documentation');
- $toolbar_btn['save'] = array(
- 'href' => '',
- 'desc' => $this->l('Save')
- );
- $helper->currentIndex = $this->context->link->getAdminLink('AdminThemes', false).'&action=exporttheme';
- $helper->token = Tools::getAdminTokenLite('AdminThemes');
- $helper->show_toolbar = true;
- $helper->fields_value = $fields_value;
- $helper->toolbar_btn = $toolbar_btn;
- $helper->override_folder = $this->tpl_folder;
- return $helper->generateForm(array($fields_form));
- }
- public function renderExportTheme()
- {
- if (Tools::getIsset('id_theme_export') && (int)Tools::getValue('id_theme_export') > 0)
- return $this->renderExportTheme1();
- $theme_list = Theme::getThemes();
- $fields_form = array(
- 'form' => array(
- 'tinymce' => false,
- 'legend' => array(
- 'title' => $this->l('Theme'),
- 'icon' => 'icon-picture'
- ),
- 'input' => array(
- array(
- 'type' => 'select',
- 'name' => 'id_theme_export',
- 'label' => $this->l('Choose the theme that you want to export'),
- 'options' => array(
- 'id' => 'id',
- 'name' => 'name',
- 'query' => $theme_list,
- )
- ),
- ),
- 'submit' => array(
- 'title' => $this->l('Save'),
- )
- )
- );
- $toolbar_btn['save'] = array(
- 'href' => '#',
- 'desc' => $this->l('Export')
- );
- $fields_value['id_theme_export'] = array();
- $helper = new HelperForm();
- $helper->currentIndex = $this->context->link->getAdminLink('AdminThemes', false).'&action=exporttheme';
- $helper->token = Tools::getAdminTokenLite('AdminThemes');
- $helper->show_toolbar = true;
- $helper->fields_value = $fields_value;
- $helper->toolbar_btn = $toolbar_btn;
- $helper->override_folder = $this->tpl_folder;
- return $helper->generateForm(array($fields_form));
- }
- private function checkXmlFields($sandbox)
- {
- if (!file_exists($sandbox.'uploaded/Config.xml') || !$xml = simplexml_load_file($sandbox.'uploaded/Config.xml'))
- return false;
- if (!$xml['version'] || !$xml['name'])
- return false;
- foreach ($xml->variations->variation as $val)
- {
- if (!$val['name'] || !$val['directory'] || !$val['from'] || !$val['to'])
- return false;
- }
- foreach ($xml->modules->module as $val)
- {
- if (!$val['action'] || !$val['name'])
- return false;
- }
- foreach ($xml->modules->hooks->hook as $val)
- {
- if (!$val['module'] || !$val['hook'] || !$val['position'])
- return false;
- }
- return true;
- }
- private function recurseCopy($src, $dst)
- {
- if (!$dir = opendir($src))
- return;
- if (!file_exists($dst))
- mkdir($dst);
- while (($file = readdir($dir)) !== false)
- {
- if (strncmp($file, '.', 1) != 0)
- {
- if (is_dir($src.'/'.$file))
- self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
- elseif (is_readable($src.'/'.$file) && $file != 'Thumbs.db' && $file != '.DS_Store' && substr($file, -1) != '~')
- copy($src.'/'.$file, $dst.'/'.$file);
- }
- }
- closedir($dir);
- }
- public function processImportTheme()
- {
- $this->display = 'importtheme';
- if (defined('_PS_HOST_MODE_'))
- return true;
- if (isset($_FILES['themearchive']) && isset($_POST['filename']) && Tools::isSubmit('theme_archive_server'))
- {
- $uniqid = uniqid();
- $sandbox = _PS_CACHE_DIR_.'sandbox'.DIRECTORY_SEPARATOR.$uniqid.DIRECTORY_SEPARATOR;
- mkdir($sandbox);
- $archive_uploaded = false;
- if (Tools::getValue('filename') != '')
- {
- $uploader = new Uploader('themearchive');
- $uploader->setAcceptTypes(array('zip'));
- $uploader->setSavePath($sandbox);
- $file = $uploader->process('uploaded.zip');
- if ($file[0]['error'] === 0)
- {
- if (Tools::ZipTest($sandbox.'uploaded.zip'))
- $archive_uploaded = true;
- else
- $this->errors[] = $this->l('Zip file seems to be broken');
- }
- else
- $this->errors[] = $file[0]['error'];
- }
- elseif (Tools::getValue('themearchiveUrl') != '')
- {
- if (!Validate::isModuleUrl($url = Tools::getValue('themearchiveUrl'), $this->errors))
- $this->errors[] = $this->l('Only zip files are …
Large files files are truncated, but you can click here to view the full file