public static function ImageDelete()
 {
     $get_blog_image = SmartBlogPost::getBlogImage();
     $get_author_image = __PS_BASE_URI__ . 'modules/smartblog/images/avatar/avatar.jpg';
     $get_cate_image = BlogCategory::getCatImage();
     $category_types = BlogImageType::GetImageAllType('category');
     $posts_types = BlogImageType::GetImageAllType('post');
     $author_types = BlogImageType::GetImageAllType('author');
     foreach ($category_types as $image_type) {
         foreach ($get_cate_image as $cat_img) {
             $dir = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $cat_img['id_smart_blog_category'] . '-' . stripslashes($image_type['type_name']) . '.jpg';
             if (file_exists($dir)) {
                 unlink($dir);
             }
         }
     }
     foreach ($posts_types as $image_type) {
         foreach ($get_blog_image as $blog_img) {
             $dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $blog_img['id_smart_blog_post'] . '-' . stripslashes($image_type['type_name']) . '.jpg';
             if (file_exists($dir)) {
                 unlink($dir);
             }
         }
     }
     foreach ($author_types as $image_type) {
         $dir = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . stripslashes($image_type['type_name']) . '.jpg';
         if (file_exists($dir)) {
             unlink($dir);
         }
     }
 }
Example #2
0
 public function deleteImage($id_blog, $id_seller)
 {
     $posts_types = BlogImageType::GetImageAllType('post');
     foreach ($posts_types as $image_type) {
         $dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $id_seller . '/' . $id_blog . '-' . stripslashes($image_type['type_name']) . '.jpg';
         $main = _PS_MODULE_DIR_ . 'smartblog/images/' . $id_seller . '/' . $id_blog . '.jpg';
         if (file_exists($dir)) {
             unlink($dir);
             unlink($main);
         }
     }
 }
Example #3
0
 public function processImageUpload($FILES)
 {
     if (isset($FILES['avatar']) && isset($FILES['avatar']['tmp_name']) && !empty($FILES['avatar']['tmp_name'])) {
         if (ImageManager::validateUpload($FILES['avatar'], 4000000)) {
             return $this->displayError($this->l('Invalid image'));
         } else {
             $ext = Tools::substr($FILES['avatar']['name'], strrpos($FILES['avatar']['name'], '.') + 1);
             $file_name = 'avatar.' . $ext;
             $path = _PS_MODULE_DIR_ . 'smartblog/images/avatar/' . $file_name;
             if (!move_uploaded_file($FILES['avatar']['tmp_name'], $path)) {
                 return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
             } else {
                 $author_types = BlogImageType::GetImageAllType('author');
                 foreach ($author_types as $image_type) {
                     $dir = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . Tools::stripslashes($image_type['type_name']) . '.jpg';
                     if (file_exists($dir)) {
                         unlink($dir);
                     }
                 }
                 $images_types = BlogImageType::GetImageAllType('author');
                 foreach ($images_types as $image_type) {
                     ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . Tools::stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
                 }
             }
         }
     }
 }
 public function processImageCategory($FILES, $id)
 {
     if (isset($FILES['category_image']) && isset($FILES['category_image']['tmp_name']) && !empty($FILES['category_image']['tmp_name'])) {
         if ($error = ImageManager::validateUpload($FILES['category_image'], 4000000)) {
             return $this->displayError($this->l('Invalid image'));
         } else {
             $ext = substr($FILES['category_image']['name'], strrpos($FILES['category_image']['name'], '.') + 1);
             $file_name = $id . '.' . $ext;
             $path = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $file_name;
             if (!move_uploaded_file($FILES['category_image']['tmp_name'], $path)) {
                 return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
             } else {
                 if (Configuration::hasContext('category_image', null, Shop::getContext()) && Configuration::get('BLOCKBANNER_IMG') != $file_name) {
                     @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKBANNER_IMG'));
                 }
                 $images_types = BlogImageType::GetImageAllType('category');
                 foreach ($images_types as $image_type) {
                     $dir = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg';
                     if (file_exists($dir)) {
                         unlink($dir);
                     }
                 }
                 foreach ($images_types as $image_type) {
                     ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/category/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
                 }
             }
         }
     }
 }
 public function ajaxProcessaddGallaryImage()
 {
     self::$currentIndex = 'index.php?tab=AdminSmartBlog&token=' . Tools::getAdminTokenLite('AdminSmartBlog');
     $smart_blog_post = new SmartBlogPost((int) Tools::getValue('id_smart_blog_post'));
     $legends = Tools::getValue('legend');
     if (!is_array($legends)) {
         $legends = (array) $legends;
     }
     if (!Validate::isLoadedObject($smart_blog_post)) {
         $files = array();
         $files[0]['error'] = Tools::displayError('Cannot add image because product creation failed.');
     }
     $image_uploader = new HelperImageUploader('file');
     $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size);
     $files = $image_uploader->process();
     foreach ($files as &$file) {
         $image = new SmartBlogGallaryImage();
         $image->id_smart_blog_post = (int) $smart_blog_post->id;
         $image->position = SmartBlogGallaryImage::getHighestPosition($smart_blog_post->id) + 1;
         foreach ($legends as $key => $legend) {
             if (!empty($legend)) {
                 $image->legend[(int) $key] = $legend;
             }
         }
         if (($validate = $image->validateFieldsLang(false, true)) !== true) {
             $file['error'] = Tools::displayError($validate);
         }
         if (isset($file['error']) && (!is_numeric($file['error']) || $file['error'] != 0)) {
             continue;
         }
         if (!$image->add()) {
             $file['error'] = Tools::displayError('Error while creating additional image');
         } else {
             if (!($new_path = $image->getPathForCreation())) {
                 $file['error'] = Tools::displayError('An error occurred during new folder creation');
                 continue;
             }
             $error = 0;
             if (!ImageManager::resize($file['save_path'], $new_path . '.' . $image->image_format, null, null, 'jpg', false, $error)) {
                 switch ($error) {
                     case ImageManager::ERROR_FILE_NOT_EXIST:
                         $file['error'] = Tools::displayError('An error occurred while copying image, the file does not exist anymore.');
                         break;
                     case ImageManager::ERROR_FILE_WIDTH:
                         $file['error'] = Tools::displayError('An error occurred while copying image, the file width is 0px.');
                         break;
                     case ImageManager::ERROR_MEMORY_LIMIT:
                         $file['error'] = Tools::displayError('An error occurred while copying image, check your memory limit.');
                         break;
                     default:
                         $file['error'] = Tools::displayError('An error occurred while copying image.');
                         break;
                 }
                 continue;
             } else {
                 $imagesTypes = BlogImageType::GetImageAllType('post');
                 foreach ($imagesTypes as $imageType) {
                     if (!ImageManager::resize($file['save_path'], $new_path . '-' . Tools::stripslashes($imageType['type_name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                         $file['error'] = Tools::displayError('An error occurred while copying image:') . ' ' . Tools::stripslashes($imageType['name']);
                         continue;
                     }
                 }
             }
             unlink($file['save_path']);
             //Necesary to prevent hacking
             unset($file['save_path']);
             Hook::exec('actionWatermark', array('id_smart_blog_post_mage' => $image->id, 'id_smart_blog_post' => $smart_blog_post->id));
             if (!$image->update()) {
                 $file['error'] = Tools::displayError('Error while updating status');
                 continue;
             }
             $file['status'] = 'ok';
             $file['id'] = $image->id;
             $file['position'] = $image->position;
             $file['cover'] = $image->cover;
             $file['legend'] = $image->legend;
             $file['path'] = $image->getExistingImgPath();
             $file['shops'] = array("{$this->context->shop->id}" => true);
             @unlink(_PS_TMP_IMG_DIR_ . 'smart_blog_post_' . (int) $smart_blog_post->id . '.jpg');
             @unlink(_PS_TMP_IMG_DIR_ . 'smart_blog_post__mini_' . (int) $smart_blog_post->id . '_' . $this->context->shop->id . '.jpg');
         }
     }
     die(Tools::jsonEncode(array($image_uploader->getName() => $files)));
 }
 public function deleteImage($id_smart_blog_post = 1)
 {
     if (!$id_smart_blog_post) {
         return false;
     }
     // Delete base image
     if (file_exists(_MODULE_SMARTBLOG_DIR_ . '/' . $id_smart_blog_post . '.jpg')) {
         unlink($this->image_dir . '/' . $id_smart_blog_post . '.jpg');
     } else {
         return false;
     }
     // now we need to delete the image type of post
     $files_to_delete = array();
     // Delete auto-generated images
     $image_types = BlogImageType::GetImageAllType('post');
     foreach ($image_types as $image_type) {
         $files_to_delete[] = $this->image_dir . '/' . $id_smart_blog_post . '-' . $image_type['type_name'] . '.jpg';
     }
     // Delete tmp images
     $files_to_delete[] = _PS_TMP_IMG_DIR_ . 'smart_blog_post_' . $id_smart_blog_post . '.jpg';
     $files_to_delete[] = _PS_TMP_IMG_DIR_ . 'smart_blog_post_mini_' . $id_smart_blog_post . '.jpg';
     foreach ($files_to_delete as $file) {
         if (file_exists($file) && !@unlink($file)) {
             return false;
         }
     }
     return true;
 }
 public function processImage($FILES, $id)
 {
     if (isset($FILES['image']) && isset($FILES['image']['tmp_name']) && !empty($FILES['image']['tmp_name'])) {
         if ($error = ImageManager::validateUpload($FILES['image'], 4000000)) {
             return $this->displayError($this->l('Invalid image'));
         } else {
             $path = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '.' . $this->imageType;
             $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
             if (!$tmp_name) {
                 return false;
             }
             if (!move_uploaded_file($FILES['image']['tmp_name'], $tmp_name)) {
                 return false;
             }
             // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
             if (!ImageManager::checkImageMemoryLimit($tmp_name)) {
                 $this->errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
             }
             // Copy new image
             if (empty($this->errors) && !ImageManager::resize($tmp_name, $path, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) {
                 $this->errors[] = Tools::displayError('An error occurred while uploading the image.');
             }
             if (count($this->errors)) {
                 return false;
             }
             if ($this->afterImageUpload()) {
                 unlink($tmp_name);
                 //  return true;
             }
             $posts_types = BlogImageType::GetImageAllType('post');
             foreach ($posts_types as $image_type) {
                 $dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg';
                 if (file_exists($dir)) {
                     unlink($dir);
                 }
             }
             foreach ($posts_types as $image_type) {
                 ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
             }
         }
     }
 }
 /**
  * Delete the product image from disk and remove the containing folder if empty
  * Handles both legacy and new image filesystems
  */
 public function deleteImage($force_delete = false)
 {
     if (!$this->id) {
         return false;
     }
     // Delete base image
     if (file_exists($this->image_dir . $this->getExistingImgPath() . '.' . $this->image_format)) {
         unlink($this->image_dir . $this->getExistingImgPath() . '.' . $this->image_format);
     } else {
         return false;
     }
     $files_to_delete = array();
     // Delete auto-generated images
     $image_types = BlogImageType::getImagesTypes();
     foreach ($image_types as $image_type) {
         $files_to_delete[] = $this->image_dir . $this->getExistingImgPath() . '-' . $image_type['name'] . '.' . $this->image_format;
     }
     // Delete watermark image
     $files_to_delete[] = $this->image_dir . $this->getExistingImgPath() . '-watermark.' . $this->image_format;
     // delete index.php
     $files_to_delete[] = $this->image_dir . $this->getImgFolder() . 'index.php';
     // Delete tmp images
     $files_to_delete[] = _PS_TMP_IMG_DIR_ . 'product_' . $this->id_smart_blog_post . '.' . $this->image_format;
     $files_to_delete[] = _PS_TMP_IMG_DIR_ . 'product_mini_' . $this->id_smart_blog_post . '.' . $this->image_format;
     foreach ($files_to_delete as $file) {
         if (file_exists($file) && !@unlink($file)) {
             return false;
         }
     }
     // Can we delete the image folder?
     if (is_dir($this->image_dir . $this->getImgFolder())) {
         $delete_folder = true;
         foreach (scandir($this->image_dir . $this->getImgFolder()) as $file) {
             if ($file != '.' && $file != '..') {
                 $delete_folder = false;
                 break;
             }
         }
     }
     if (isset($delete_folder) && $delete_folder) {
         @rmdir($this->image_dir . $this->getImgFolder());
     }
     return true;
 }
Example #9
0
 public function processImageUpload($FILES, $id_seller, $id_smart_blog_post, $active_img_id)
 {
     if (isset($FILES['img']) && isset($FILES['img']['tmp_name']) && !empty($FILES['img']['tmp_name'])) {
         if ($error = ImageManager::validateUpload($FILES['img'], 4000000)) {
             return $this->displayError($this->l('Invalid image'));
         } else {
             $ext = substr($FILES['img']['name'], strrpos($FILES['img']['name'], '.') + 1);
             $file_name = $id_smart_blog_post . '.' . $ext;
             $path = _PS_MODULE_DIR_ . 'smartblog/images/' . $id_seller . '/' . $file_name;
             if (!move_uploaded_file($FILES['img']['tmp_name'], $path)) {
                 return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
             } else {
                 $author_types = BlogImageType::GetImageAllType('post');
                 foreach ($author_types as $image_type) {
                     $dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $id_seller . '/' . $id_smart_blog_post . '-' . stripslashes($image_type['type_name']) . '.jpg';
                     if (file_exists($dir)) {
                         unlink($dir);
                     }
                 }
                 $images_types = BlogImageType::GetImageAllType('post');
                 foreach ($images_types as $image_type) {
                     ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $id_seller . '/' . $id_smart_blog_post . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
                 }
                 //  insert data into the database
                 $this->insertImgData($id_seller, $id_smart_blog_post);
             }
         }
     }
 }