Image name
This commit is contained in:
parent
fcf69fedec
commit
ea75b02efa
@ -8,9 +8,9 @@ class AdminAdvSliderController extends ModuleAdminController
|
||||
$this->table = 'advslider';
|
||||
$this->className = 'AdvSlide';
|
||||
$this->identifier = 'id_slide';
|
||||
$this->lang = TRUE;
|
||||
$this->deleted = FALSE;
|
||||
$this->bootstrap = TRUE;
|
||||
$this->lang = true;
|
||||
$this->deleted = false;
|
||||
$this->bootstrap = true;
|
||||
$this->fieldImageSettings = array(
|
||||
'name' => 'image',
|
||||
'dir' => 'slider'
|
||||
@ -227,22 +227,22 @@ class AdminAdvSliderController extends ModuleAdminController
|
||||
|
||||
// Images
|
||||
$image = _PS_IMG_DIR_ . 'slider/' . $obj->id.'.jpg';
|
||||
$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350, $this->imageType, TRUE, TRUE);
|
||||
$image_size = file_exists($image) ? filesize($image) / 1000 : FALSE;
|
||||
$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350, $this->imageType, true, true);
|
||||
$image_size = file_exists($image) ? filesize($image) / 1000 : false;
|
||||
|
||||
$image_mobile = _PS_IMG_DIR_ . 'slider/' . $obj->id.'-image_mobile.jpg';
|
||||
$image_url_mobile = ImageManager::thumbnail($image_mobile, $this->table.'_'.(int)$obj->id.'-image_mobile.'.$this->imageType, 350, $this->imageType, TRUE, TRUE);
|
||||
$image_size_mobile = file_exists($image_mobile) ? filesize($image_mobile) / 1000 : FALSE;
|
||||
$image_mobile = _PS_IMG_DIR_ . 'slider/' . $obj->id.'-mobile.jpg';
|
||||
$image_url_mobile = ImageManager::thumbnail($image_mobile, $this->table.'_'.(int)$obj->id.'-image_mobile.'.$this->imageType, 350, $this->imageType, true, true);
|
||||
$image_size_mobile = file_exists($image_mobile) ? filesize($image_mobile) / 1000 : false;
|
||||
}
|
||||
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Image'),
|
||||
'desc' => $this->l('Image de 940 x 300 px'),
|
||||
'desc' => $this->l('Image - type: jpg,png - size: 940 x 300 px'),
|
||||
'name' => 'image',
|
||||
'display_image' => TRUE,
|
||||
'lang' => TRUE,
|
||||
'required' => TRUE,
|
||||
'display_image' => true,
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'image' => $image_url,
|
||||
'size' => $image_size,
|
||||
'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->object->id.'&token='.$this->token.'&deleteImage=1'
|
||||
@ -251,11 +251,11 @@ class AdminAdvSliderController extends ModuleAdminController
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'file',
|
||||
'label' => $this->l('Image Mobile'),
|
||||
'desc' => $this->l('Image de 300 x 200 px'),
|
||||
'desc' => $this->l('Image - type: jpg,png - size: 300 x 200 px'),
|
||||
'name' => 'image_mobile',
|
||||
'display_image' => TRUE,
|
||||
'lang' => TRUE,
|
||||
'required' => TRUE,
|
||||
'display_image' => true,
|
||||
'lang' => true,
|
||||
'required' => true,
|
||||
'image' => $image_url_mobile,
|
||||
'size' => $image_size_mobile,
|
||||
'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->object->id.'&token='.$this->token.'&deleteImage=1&imgName=image_mobile'
|
||||
@ -286,7 +286,7 @@ class AdminAdvSliderController extends ModuleAdminController
|
||||
parent::postProcess();
|
||||
|
||||
$obj = $this->loadObject(TRUE);
|
||||
|
||||
|
||||
// Groupes
|
||||
$groupsData = array();
|
||||
foreach ($_POST as $pKey => $pValue) {
|
||||
@ -298,29 +298,35 @@ class AdminAdvSliderController extends ModuleAdminController
|
||||
if (count($groupsData) > 0) {
|
||||
$obj->updateGroups($groupsData);
|
||||
}
|
||||
|
||||
|
||||
// Images
|
||||
$images = array('image_mobile');
|
||||
foreach($images as $imageName) {
|
||||
$images = array(
|
||||
'image_mobile' => 'mobile',
|
||||
);
|
||||
foreach($images as $imageName => $suffix) {
|
||||
if(isset($_FILES[$imageName]) && !empty($_FILES[$imageName]['tmp_name'])) {
|
||||
$fileTemp = $_FILES[$imageName]['tmp_name'];
|
||||
$fileParts = pathinfo($_FILES[$imageName]['name']);
|
||||
$extension = $fileParts['extension'];
|
||||
|
||||
if(file_exists(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$imageName.'.jpg')) {
|
||||
unlink(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$imageName.'.jpg');
|
||||
if(file_exists(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$suffix.'.'.$extension)) {
|
||||
unlink(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$suffix.'.'.$extension);
|
||||
}
|
||||
|
||||
if($fileParts['extension'] == 'jpg') {
|
||||
$res = move_uploaded_file($fileTemp, _PS_IMG_DIR_.'slider/'.$obj->id.'-'.$imageName.'.jpg');
|
||||
if(in_array($extension, array('jpg', 'png'))) {
|
||||
$res = move_uploaded_file($fileTemp, _PS_IMG_DIR_.'slider/'.$obj->id.'-'.$suffix.'.'.$extension);
|
||||
if(!$res) {
|
||||
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), $obj->id.'.jpg');
|
||||
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), $obj->id.'.'.$extension);
|
||||
}
|
||||
else {
|
||||
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), $obj->id.'.jpg');
|
||||
if($extension == 'png') {
|
||||
ImageManager::resize(_PS_IMG_DIR_.'slider/'.$obj->id.'-'.$suffix.'.'.$extension, _PS_IMG_DIR_.'slider/'.$obj->id.'-'.$suffix.'.jpg');
|
||||
}
|
||||
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), $obj->id.'.'.$extension);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), $obj->id.'.jpg');
|
||||
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), $obj->id.'.'.$extension);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -328,10 +334,10 @@ class AdminAdvSliderController extends ModuleAdminController
|
||||
|
||||
public function processForceDeleteImage()
|
||||
{
|
||||
$link = $this->loadObject(TRUE);
|
||||
$link = $this->loadObject(true);
|
||||
|
||||
if (Validate::isLoadedObject($link)) {
|
||||
$link->deleteImage(TRUE);
|
||||
$link->deleteImage(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
<div id="slider_home_mobile" class="clearfix smobile">
|
||||
<div class="clearfix owl">
|
||||
{foreach from=$slides item=slide key=key name=slider}
|
||||
<div class="col-sm-12 slide-home item" style="height:200px;background: url('{$img_ps_dir}slider/{$slide.id_slide}_1.jpg') no-repeat center top; background-size: contain;">
|
||||
<div class="col-sm-12 slide-home item" style="height:200px;background: url('{$img_ps_dir}slider/{$slide.id_slide}-mobile.jpg') no-repeat center top; background-size: contain;">
|
||||
{if isset($slide.url) && $slide.url}
|
||||
<a {if !$cookie->logged}onclick="window.location.href='{$link->getPageLink('authentication', true)|escape:'html':'UTF-8'}';"{else}href="{$slide.url}"{/if} style="width:100%;height: 100%;display: block;" {if isset($slide.title) && $slide.title}title="{$slide.title}"{/if}></a>
|
||||
{/if}
|
||||
|
Loading…
Reference in New Issue
Block a user