* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminImagesController extends AdminController
{
private $start_time = 0;
private $max_execution_time = 7200;
public function __construct()
{
$this->table = 'image_type';
$this->className = 'ImageType';
$this->lang = false;
$this->edit = true;
$this->delete = true;
$this->fieldsDisplay = array(
'id_image_type' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 140, 'size' => 16),
'width' => array('title' => $this->l('Width'), 'align' => 'right', 'suffix' => ' px', 'width' => 50, 'size' => 5),
'height' => array('title' => $this->l('Height'), 'align' => 'right', 'suffix' => ' px', 'width' => 50, 'size' => 5)
);
$this->form_list = array(
'options_image_pref' => array(
'images' => array(
'title' => $this->l('Images'),
'icon' => 'tab-orders',
'class' => 'width4',
'top' => '',
'bottom' => '',
'description' => $this->l('JPEG images have a small file size and standard quality. PNG images have a bigger file size, a higher quality and support transparency. Note that in all cases the image files will have the .jpg extension.').'
'.$this->l('WARNING: This feature may not be compatible with your theme or with some modules. In particular, PNG mode is not compatible with the Watermark module. If you encounter any issue, turn it off by selecting "Use JPEG".'),
'fields' => array(
'PS_IMAGE_QUALITY' => array('title' => $this->l('Image quality'), 'show' => true, 'required' => true, 'type' => 'radio', 'choices' => array('jpg' => $this->l('Use JPEG'), 'png' => $this->l('Use PNG only if the base image is in PNG format'), 'png_all' => $this->l('Use PNG for all images'))),
'PS_JPEG_QUALITY' => array('title' => $this->l('JPEG quality'), 'desc' => $this->l('Ranges from 0 (worst quality, smallest file) to 100 (best quality, biggest file)'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'),
'PS_PNG_QUALITY' => array('title' => $this->l('PNG quality'), 'desc' => $this->l('Ranges from 9 (worst quality, smallest file) to 0 (best quality, biggest file)'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'),
),
),
)
);
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Images'),
'image' => '../img/admin/picture.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Type name:'),
'name' => 'name',
'required' => true,
'p' => $this->l('Letters only (e.g., small, medium, large, extra-large)')
),
array(
'type' => 'text',
'label' => $this->l('Width:'),
'name' => 'width',
'required' => true,
'size' => 4,
'maxlength' => 5,
'p' => $this->l('Maximum image width in pixels')
),
array(
'type' => 'text',
'label' => $this->l('Height:'),
'name' => 'height',
'required' => true,
'size' => 4,
'maxlength' => 5,
'p' => $this->l('Maximum image height in pixels')
),
array(
'type' => 'radio',
'label' => $this->l('Products:'),
'name' => 'products',
'required' => false,
'class' => 't',
'is_bool' => true,
'p' => $this->l('This type will be applied to product images'),
'values' => array(
array(
'id' => 'products_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'products_off',
'value' => 0,
'label' => $this->l('Disabled')
),
)
),
array(
'type' => 'radio',
'label' => $this->l('Categories:'),
'name' => 'categories',
'required' => false,
'class' => 't',
'is_bool' => true,
'p' => $this->l('This type will be applied to categories images'),
'values' => array(
array(
'id' => 'categories_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'categories_off',
'value' => 0,
'label' => $this->l('Disabled')
),
)
),
array(
'type' => 'radio',
'label' => $this->l('Manufacturers:'),
'name' => 'manufacturers',
'required' => false,
'class' => 't',
'is_bool' => true,
'p' => $this->l('This type will be applied to manufacturers images'),
'values' => array(
array(
'id' => 'manufacturers_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'manufacturers_off',
'value' => 0,
'label' => $this->l('Disabled')
),
)
),
array(
'type' => 'radio',
'label' => $this->l('Suppliers:'),
'name' => 'suppliers',
'required' => false,
'class' => 't',
'is_bool' => true,
'p' => $this->l('This type will be applied to suppliers images'),
'values' => array(
array(
'id' => 'suppliers_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'suppliers_off',
'value' => 0,
'label' => $this->l('Disabled')
),
)
),
array(
'type' => 'radio',
'label' => $this->l('Scenes:'),
'name' => 'scenes',
'required' => false,
'class' => 't',
'is_bool' => true,
'p' => $this->l('This type will be applied to scenes images'),
'values' => array(
array(
'id' => 'scenes_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'scenes_off',
'value' => 0,
'label' => $this->l('Disabled')
),
)
),
array(
'type' => 'radio',
'label' => $this->l('stores:'),
'name' => 'stores',
'required' => false,
'class' => 't',
'is_bool' => true,
'p' => $this->l('This type will be applied to stores images'),
'values' => array(
array(
'id' => 'stores_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'stores_off',
'value' => 0,
'label' => $this->l('Disabled')
),
)
),
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
parent::__construct();
}
public function postProcess()
{
if (Tools::getValue('submitRegenerate'.$this->table))
{
if ($this->tabAccess['edit'] === '1')
{
if ($this->_regenerateThumbnails(Tools::getValue('type'), Tools::getValue('erase')))
Tools::redirectAdmin(self::$currentIndex.'&conf=9'.'&token='.$this->token);
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}elseif (Tools::getValue('submitMoveImages'.$this->table))
{
if ($this->tabAccess['edit'] === '1')
{
if($this->_moveImagesToNewFileSystem())
Tools::redirectAdmin(self::$currentIndex.'&conf=25'.'&token='.$this->token);
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}elseif (Tools::getValue('submitImagePreferences'))
{
if ($this->tabAccess['edit'] === '1')
{
if ((int)Tools::getValue('PS_JPEG_QUALITY') < 0
|| (int)Tools::getValue('PS_JPEG_QUALITY') > 100)
$this->_errors[] = Tools::displayError('Incorrect value for JPEG image quality.');
elseif ((int)Tools::getValue('PS_PNG_QUALITY') < 0
|| (int)Tools::getValue('PS_PNG_QUALITY') > 9)
$this->_errors[] = Tools::displayError('Incorrect value for PNG image quality.');
elseif (!Configuration::updateValue('PS_IMAGE_QUALITY', Tools::getValue('PS_IMAGE_QUALITY'))
|| !Configuration::updateValue('PS_JPEG_QUALITY', Tools::getValue('PS_JPEG_QUALITY'))
|| !Configuration::updateValue('PS_PNG_QUALITY', Tools::getValue('PS_PNG_QUALITY')))
$this->_errors[] = Tools::displayError('Unknown error.');
else
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getValue('token').'&conf=4');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
else
parent::postProcess();
}
protected function _childValidation()
{
if (!Tools::getValue('id_image_type') AND Validate::isImageTypeName($typeName = Tools::getValue('name')) AND ImageType::typeAlreadyExists($typeName))
$this->_errors[] = Tools::displayError('This name already exists.');
}
/**
* Display form for thumbnails regeneration
*/
public function displayRegenerate()
{
$types = array(
'categories' => $this->l('Categories'),
'manufacturers' => $this->l('Manufacturers'),
'suppliers' => $this->l('Suppliers'),
'scenes' => $this->l('Scenes'),
'products' => $this->l('Products'),
'stores' => $this->l('Stores')
);
$this->content .= '