Skip to content
Permalink
Browse files

show an error message if the images folder is not writable

change path to local_path var to upload the image
refactor var name
  • Loading branch information...
tpeigne committed Jun 21, 2013
1 parent ca17491 commit d28ccb95ea0f247d0a0127d4ad8ebadf455bf6d5
@@ -7,17 +7,17 @@
$responsiveSlider = new ResponsiveSlider();
if (Tools::getValue('action') == 'deleteSlide') {
$slider = new ResponsiveSliderClass(Tools::getValue('idSlide'));
$slider = new ResponsiveSliderClass((int) Tools::getValue('idSlide'));
if (ResponsiveSliderClass::deleteSlide(Tools::getValue('idSlide'), __DIR__)) {
if (ResponsiveSliderClass::deleteSlide($slider, $responsiveSlider->getLocalPath())) {
$response = '
<div class="conf confirm">
'.$responsiveSlider->l('The slide').' '.$slider->title[$cookie->id_lang].' '.$responsiveSlider->l('has been deleted.').'
'.$responsiveSlider->l('The slide has been deleted.').'
</div>';
} else {
$response = '
<div class="conf error">
'.$responsiveSlider->l('An error has occured while deleting slide.').'
'.$responsiveSlider->l('An error has occured while deleting slide, check you logs.').'
</div>';
}
@@ -33,14 +33,14 @@
$response = '
<div class="conf confirm">
'.$responsiveSlider->l('The slide').' '.$slider->title[$cookie->id_lang].' '.$responsiveSlider->l('is now online.').'
'.$responsiveSlider->l('The slide is now online.').'
</div>';
} else {
$slider->isonline = 0;
$response = '
<div class="conf confirm">
'.$responsiveSlider->l('The slide').' '.$slider->title[$cookie->id_lang].' '.$responsiveSlider->l('is now offline.').'
'.$responsiveSlider->l('The slide is now offline.').'
</div>';
}
@@ -127,60 +127,67 @@ public static function findAllByOnline($isOnline = 1)
/**
* Delete one slide
*
* @param $idSlide
* @param $dirCaller
* @param $slider ResponsiveSliderClass
* @param $moduleLocalPath Local path to module
* @return bool
*/
public static function deleteSlide($idSlide, $dirCaller)
public static function deleteSlide($slider, $moduleLocalPath)
{
$slider = new ResponsiveSliderClass($idSlide);
$return = true;
//delete all images of a slide
foreach ($slider->urlimage AS $image){
//check if the field is not empty
if ($image <> '') {
unlink($dirCaller.'/images/'.$image);
if (!unlink($moduleLocalPath.'images/'.$image)) {
Logger::AddLog('[Module : ResponsiveSlider | Class : ResponsiveSliderClass | Message : Error while deleting the slide image | PathToImage : '.$moduleLocalPath.'images/'.$image);
$return = false;
}
}
}
if(!Db::getInstance()->delete(_DB_PREFIX_.'responsiveslider', '`id_responsiveslider` = '.(int)$idSlide.''))
return false;
if (!Db::getInstance()->delete(_DB_PREFIX_.self::$definition['table'], '`'.self::$definition['primary'].'` = '.$slider->id.'')) {
$return = false;
}
if(!Db::getInstance()->delete(_DB_PREFIX_.'responsiveslider_lang', '`id_responsiveslider` = '.(int)$idSlide.''))
return false;
if (!Db::getInstance()->delete(_DB_PREFIX_.self::$definition['table'], '`'.self::$definition['primary'].'` = '.$slider->id.'')) {
$return = false;
}
return true;
return $return;
}
/**
* Upload one image on the server
*
* @param $file
* @param $modulePath
* @param $idLangue
* @param $langId
* @return bool|string
*/
private function uploadOneImage($file, $modulePath, $idLangue)
private function uploadOneImage($file, $modulePath, $langId)
{
//check image error
//check image errors
if ($file["error"] > 0) {
return false;
} else {
//TODO : keep real image extension name
$imageName = sha1(uniqid(mt_rand(), true)).'-'.$langId.'.jpg';
$imagePath = $modulePath.'images/';
//check image type
if ($file['type'] == 'image/png'
|| $file['type'] == 'image/jpg'
|| $file['type'] == 'image/gif'
|| $file['type'] == 'image/jpeg'
|| $file['type'] == 'image/pjpeg') {
if (file_exists($modulePath.'images/'.$file["name"])) {
if (file_exists($imagePath.$imageName)) {
return false;
} else {
$rep = dirname(__DIR__).'/images/';
$image = md5(date('YmdHis')).'-'.$idLangue.'.jpg';
move_uploaded_file($file["tmp_name"], $rep.$image);
if (!move_uploaded_file($file["tmp_name"], $imagePath.$imageName)) {
Logger::AddLog('[Module : ResponsiveSlider | Class : ResponsiveSliderClass | Message : Error while moving the slide image | PathToImage : '.$imagePath.$imageName);
}
return $image;
return $imageName;
}
} else {
return false;
Binary file not shown.
Binary file not shown.
@@ -137,7 +137,7 @@ public function getContent()
} else {
$slider = new ResponsiveSliderClass(Tools::getValue('idSlide'));
$slider->copyFromPost();
$slider->uploadImages($_FILES, $this->_path);
$slider->uploadImages($_FILES, $this->local_path);
if ($slider->save()) {
$this->_html .= '
@@ -160,7 +160,7 @@ public function getContent()
//get data from post method
$slider = new ResponsiveSliderClass();
$slider->copyFromPost();
$slider->uploadImages($_FILES, $this->_path);
$slider->uploadImages($_FILES, $this->local_path);
$slider->position = ResponsiveSliderClass::getMaxPosition();
$slider->id_shop = $this->context->shop->id;
@@ -202,7 +202,14 @@ public function getContent()
$this->_html .= '<h2 id="module-title">'.$this->displayName.'</h2>
<div style="display:none;" id="ajax-response"></div>';
$this->_displayForm();
if (is_writable($this->local_path.'images/')) {
$this->_displayForm();
} else {
$this->_html .= '
<div class="conf error">
'.$this->l('The folder images in the module responsiveslider is not writable. Please allow the system to write in the images folder').'
</div>';
}
return $this->_html;
}
@@ -2,11 +2,10 @@
global $_MODULE;
$_MODULE = array();
$_MODULE['<{responsiveslider}prestashop>ajax_fefe6b3d05d40601341560ec5217b5af'] = 'Le slide';
$_MODULE['<{responsiveslider}prestashop>ajax_93fadb3e8ad55afc270a15aec5d009fd'] = 'à été supprimé.';
$_MODULE['<{responsiveslider}prestashop>ajax_8f44973975a56a39d51425e78271bfb2'] = 'Une erreur est apparue pendant la suppression du slide.';
$_MODULE['<{responsiveslider}prestashop>ajax_760a4d8c60572a2c0896a0d27d474ef9'] = 'est maintenant en ligne.';
$_MODULE['<{responsiveslider}prestashop>ajax_b1c86c7e0c953661b083c36d45f46e45'] = 'est maintenant hors ligne.';
$_MODULE['<{responsiveslider}prestashop>ajax_57ce0680ad6f9124f1446dda23053a40'] = 'Le slide à été supprimé.';
$_MODULE['<{responsiveslider}prestashop>ajax_61883055689643bdb7fa41dcbb4a484d'] = 'Une erreur est survenue pendant la suppression du slide, regardez vos logs.';
$_MODULE['<{responsiveslider}prestashop>ajax_abdc12605bc4ef316e845cde7ffadd9f'] = 'Le slide est maintenant en ligne.';
$_MODULE['<{responsiveslider}prestashop>ajax_34dd4d57c32413f323ef9d7bed0ffa35'] = 'Le slide est maintenant hors ligne.';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_b7b77aa03dd603929bec6228133cd1fc'] = 'Responsive Slider';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_76ead36f6fccc43feeef394def78e340'] = 'Ajoute un slider responsive sur votre page d\'accueil';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_d80c33cfb4a592ccbafaa87517f4d3a7'] = 'L\'image du slider à été mise à jour.';
@@ -16,6 +15,7 @@
$_MODULE['<{responsiveslider}prestashop>responsiveslider_634ce0cb6e09deec10f976c23ef52827'] = 'à été ajouté à votre slider';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_0aa29d5ef84676e4f539562ef9eaf007'] = 'Une erreur est apparue pendant l\'ajout du slide.';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_5b4d374c883ac32c59e763a5683a110f'] = 'La configuration du slider à été mise à jour.';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_c22674e3b47ff447f7c44d37a12d371f'] = 'Le dossier images du module responsiveslider n\'est pas accessible en écriture. Autorisez le système à écrire à l\'intérieur.';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_232df6779ed585fc66a7ac8e3f54a852'] = 'Ajouter un slide';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_a2f7ac064958b81a343b8e379a5d1acc'] = 'Ajouter un slide à votre slider';
$_MODULE['<{responsiveslider}prestashop>responsiveslider_1a9693b440ee61940b01583cf287cee3'] = 'Titre :';

0 comments on commit d28ccb9

Please sign in to comment.
You can’t perform that action at this time.