* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7346 $
* @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
{
/** 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( // feature key name
'attributes' => array(
'available' => array(
'value' => 'true', // accepted attribute value
// if value doesnt match,
// prestashop configuration value must have thoses 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,
'PS_HIGH_HTML_THEME_COMPRESSION' => 0,
),
),
),
'error' => 'This theme may not correctly use "combine, compress and cache"',
'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 "guest checkout"',
'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 "one page checkout"',
'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 "display store location"',
'tab' => 'AdminStores',
)
);
public function __construct()
{
$this->className = 'Theme';
$this->table = 'theme';
parent::__construct();
// Thumbnails filenames depend on multishop activation
if (Shop::isFeatureActive())
$shop_suffix = '-'.(int)Context::getContext()->shop->getID();
else
$shop_suffix = '';
$this->options = array(
'appearance' => array(
'title' => $this->l('Appearance'),
'icon' => 'email',
'class' => 'width3',
'fields' => array(
'PS_LOGO' => array('title' => $this->l('Header logo:'), 'desc' => $this->l('Will appear on main page'), 'type' => 'file', 'thumb' => _PS_IMG_.'logo'.$shop_suffix.'.jpg?date='.time()),
'PS_LOGO_MAIL' => array('title' => $this->l('Mail logo:'), 'desc' => $this->l('Will appear on e-mail headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => (file_exists(_PS_IMG_DIR_.'logo_mail'.$shop_suffix.'.jpg')) ? _PS_IMG_.'logo_mail'.$shop_suffix.'.jpg?date='.time() : _PS_IMG_.'logo'.$shop_suffix.'.jpg?date='.time()),
'PS_LOGO_INVOICE' => array('title' => $this->l('Invoice logo:'), 'desc' => $this->l('Will appear on invoices headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => file_exists(_PS_IMG_DIR_.'logo_invoice'.$shop_suffix.'.jpg') ? _PS_IMG_.'logo_invoice'.$shop_suffix.'.jpg?date='.time() : _PS_IMG_.'logo'.$shop_suffix.'.jpg?date='.time()),
'PS_FAVICON' => array('title' => $this->l('Favicon:'), 'desc' => $this->l('Will appear in the address bar of your web browser'), 'type' => 'file', 'thumb' => _PS_IMG_.'favicon'.$shop_suffix.'.ico?date='.time()),
'PS_STORES_ICON' => array('title' => $this->l('Store icon:'), 'desc' => $this->l('Will appear on the store locator (inside Google Maps)').'
'.$this->l('Suggested size: 30x30, Transparent GIF'), 'type' => 'file', 'thumb' => _PS_IMG_.'logo_stores'.$shop_suffix.'.gif?date='.time()),
'PS_NAVIGATION_PIPE' => array('title' => $this->l('Navigation pipe:'), 'desc' => $this->l('Used for navigation path inside categories/product'), 'cast' => 'strval', 'type' => 'text', 'size' => 20),
),
'submit' => array('title' => $this->l(' Save '), 'class' => 'button')
),
);
$this->fieldsDisplay = array(
'id_theme' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 20,
),
'name' => array(
'title' => $this->l('Name'),
'width' => 'auto',
),
'directory' => array(
'title' => $this->l('Directory'),
'width' => 'auto',
),
);
}
public function renderForm(){
$getAvailableThemes = Theme::getAvailable(false);
$available_theme_dir = array();
$selected_theme_dir = null;
if ($this->object)
$selected_theme_dir= $this->object->directory;
foreach($getAvailableThemes 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'),
'image' => '../img/admin/tab-themes.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name:'),
'name' => 'name',
'size' => 48,
'required' => true,
'hint' => $this->l('Invalid characters:').' <>;=#{}',
),
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
// adding a new theme, you can create a directory, and copy from an existing theme
if ($this->display == 'add' || !$this->object->id)
{
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Directory:'),
'name' => 'directory',
'required' => true,
'desc' => $this->l('Note: only the existence of the directory is checked. Please be sure to select a valid theme directory.'),
);
$this->fields_form['input'][] = array(
'type' => 'select',
'name' => 'based_on',
'label' => $this->l('Based on'),
'options' => array(
'id' => 'id', 'name' => 'name',
'default' => array('value' => 0, 'label' => ' - '),
'query' => Theme::getThemes(),
)
);
}
else
$this->fields_form['input'][] = array(
'type' => 'radio',
'label' => $this->l('Directory:'),
'name' => 'directory',
'required' => true,
'br' => true,
'class' => 't',
'values' => $available_theme_dir,
'selected' => $selected_theme_dir,
'desc' => $this->l('Note: only the existence of the directory is checked. Please be sure to select a valid theme directory.'),
);
return parent::renderForm();
}
public function renderList(){
$this->addRowAction('edit');
$this->addRowAction('delete');
// $this->_filter .= ' AND `id_parent` = '.(int)$this->_category->id.' ';
// $this->_select = 'position ';
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
*/
private 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 &= self::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($token){
$new_dir = Tools::getValue('directory');
$res = true;
if (Validate::isDirName($new_dir) && !is_dir(_PS_ALL_THEMES_DIR_.$new_dir))
{
$res &= mkdir(_PS_ALL_THEMES_DIR_.$new_dir, Theme::$access_rights);
if ($res)
$this->confirmations[] = $this->l('Directory successfully created');
}
if (0 !== $id_based = (int)Tools::getValue('based_on'))
{
$base_theme = new Theme($id_based);
$res = $this->copyTheme($base_theme->directory, $new_dir);
$base_theme = new Theme((int)Tools::getValue('based_on'));
}
return parent::processAdd($token);
}
public function processDelete($token){
$obj = $this->loadObject();
if ($obj && $obj->isUsed())
{
$this->_errors[] = $this->l('This theme is used by at least one shop. Please choose another theme first.');
return false;
}
return parent::processDelete($token);
}
public function initContent()
{
$content = '';
if (file_exists(_PS_IMG_DIR_.'logo.jpg'))
{
list($width, $height, $type, $attr) = getimagesize(_PS_IMG_DIR_.'logo.jpg');
Configuration::updateValue('SHOP_LOGO_WIDTH', (int)round($width));
Configuration::updateValue('SHOP_LOGO_HEIGHT', (int)round($height));
}
// No cache for auto-refresh uploaded logo
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// $this->displayOptionsList();
/* if (@ini_get('allow_url_fopen') AND @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3))
$content .= '