Esempio n. 1
0
 /**
  * Generate a cached thumbnail for object lists (eg. carrier, order states...etc)
  *
  * @param string $image Real image filename
  * @param string $cache_image Cached filename
  * @param int $size Desired size
  * @param string $image_type Image type
  * @param bool $disable_cache When turned on a timestamp will be added to the image URI to disable the HTTP cache
  * @return string
  */
 public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg', $disable_cache = false)
 {
     if (!file_exists($image)) {
         return '';
     }
     if (!file_exists(_PS_TMP_IMG_DIR_ . $cache_image)) {
         $infos = getimagesize($image);
         // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
         if (!ImageManager::checkImageMemoryLimit($image)) {
             return false;
         }
         $x = $infos[0];
         $y = $infos[1];
         $max_x = $size * 3;
         // Size is already ok
         if ($y < $size && $x <= $max_x) {
             copy($image, _PS_TMP_IMG_DIR_ . $cache_image);
         } else {
             $ratio_x = $x / ($y / $size);
             if ($ratio_x > $max_x) {
                 $ratio_x = $max_x;
                 $size = $y / ($x / $max_x);
             }
             ImageManager::resize($image, _PS_TMP_IMG_DIR_ . $cache_image, $ratio_x, $size, $image_type);
         }
     }
     // Relative link will always work, whatever the base uri set in the admin
     if (Context::getContext()->controller->controller_type == 'admin') {
         return '<img src="../img/tmp/' . $cache_image . (!$disable_cache ? '?time=' . time() : '') . '" alt="" class="imgm" />';
     } else {
         return '<img src="' . _PS_TMP_IMG_ . $cache_image . (!$disable_cache ? '?time=' . time() : '') . '" alt="" class="imgm" />';
     }
 }
Esempio n. 2
0
 /**
  *
  */
 public function renderContent($setting)
 {
     $t = array('name' => '', 'image' => '', 'imagesize' => '', 'alignment' => '', 'animation' => '', 'ispopup' => '1', 'imageurl' => '');
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
     $url = Tools::htmlentitiesutf8($protocol . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__);
     $setting = array_merge($t, $setting);
     $size = explode('x', $setting['size']);
     $setting['thumbnailurl'] = _PAGEBUILDER_IMAGE_URL_ . $setting['imagefile'];
     $setting['imageurl'] = _PAGEBUILDER_IMAGE_URL_ . $setting['imagefile'];
     if (count($size) == 2) {
         $cache = _PS_CACHE_DIR_ . 'pspagebuilder/';
         if (!file_exists($cache . $setting['imagefile'])) {
             if (!is_dir($cache)) {
                 mkdir($cache, 0755);
             }
             if (ImageManager::resize(_PAGEBUILDER_IMAGE_DIR_ . $setting['imagefile'], $cache . $setting['imagefile'], $size[0], $size[1])) {
                 $setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
             }
         } else {
             $setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
         }
     }
     $output = array('type' => 'image', 'data' => $setting);
     return $output;
 }
 protected function afterImageUpload()
 {
     /* Generate image with differents size */
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     if ($obj->id && (isset($_FILES['image']) || isset($_FILES['thumb']))) {
         $base_img_path = _PS_SCENE_IMG_DIR_ . $obj->id . '.jpg';
         $images_types = ImageType::getImagesTypes('scenes');
         foreach ($images_types as $k => $image_type) {
             if ($image_type['name'] == 'scene_default' && isset($_FILES['image'])) {
                 ImageManager::resize($base_img_path, _PS_SCENE_IMG_DIR_ . $obj->id . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
             } else {
                 if ($image_type['name'] == 'm_scene_default') {
                     if (isset($_FILES['thumb']) && !$_FILES['thumb']['error']) {
                         $base_thumb_path = _PS_SCENE_THUMB_IMG_DIR_ . $obj->id . '.jpg';
                     } else {
                         $base_thumb_path = $base_img_path;
                     }
                     ImageManager::resize($base_thumb_path, _PS_SCENE_THUMB_IMG_DIR_ . $obj->id . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
                 }
             }
         }
     }
     return true;
 }
Esempio n. 4
0
 /**
  *
  */
 public function renderContent($setting)
 {
     $t = array('name' => '', 'image' => '', 'imagesize' => '80x80', 'alignment' => '', 'animation' => '', 'ispopup' => '1', 'imageurl' => '', 'icon' => '', 'widget_heading' => '', 'icon_position' => 'left');
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
     $url = Tools::htmlentitiesutf8($protocol . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__);
     $setting = array_merge($t, $setting);
     $size = explode('x', $setting['imagesize']);
     //$setting['thumbnailurl'] = $url.'modules/pspagebuilder/images/'.$setting['imagefile'];
     //$setting['imageurl'] = $url.'modules/pspagebuilder/images/'.$setting['imagefile'];
     $setting['thumbnailurl'] = '';
     $setting['imageurl'] = '';
     if (count($size) == 2 && empty($setting['icon'])) {
         $cache = _PS_CACHE_DIR_ . 'pspagebuilder/';
         if (!file_exists($cache . $setting['imagefile'])) {
             if (!is_dir($cache)) {
                 mkdir($cache, 0777);
             }
             if (ImageManager::resize(_PAGEBUILDER_IMAGE_DIR_ . $setting['imagefile'], $cache . $setting['imagefile'], $size[0], $size[1])) {
                 $setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
             }
         } else {
             $setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
         }
     }
     $setting['content'] = $this->getValueByLang($setting, 'content');
     $output = array('type' => 'ourservice', 'data' => $setting);
     return $output;
 }
 protected function postProcess()
 {
     $errors = '';
     if (Tools::isSubmit('deleteImage')) {
         if (!file_exists(dirname(__FILE__) . '/img/' . $this->_getUserImg())) {
             $errors .= $this->displayError($this->l('This action cannot be taken.'));
         } else {
             unlink(dirname(__FILE__) . '/img/' . $this->_getUserImg());
             Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id));
         }
     }
     if (Tools::isSubmit('submitUpdateScrolltop')) {
         if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
             if ($error = ImageManager::validateUpload($_FILES['image'])) {
                 $errors .= $this->displayError($error);
             } elseif (!ImageManager::resize($_FILES['image']['tmp_name'], dirname(__FILE__) . '/img/' . $this->_getUserImg())) {
                 $errors .= $this->displayError($this->l('An error occurred during the image upload.'));
             }
         }
         foreach ($this->_scrollParams as $param => $value) {
             if ($val = (int) Tools::getValue($param)) {
                 $this->_setScrollParam($param, $val);
             } else {
                 $errors .= $this->displayError($this->l('"' . $param . '" is not valid.'));
             }
         }
         if (!$errors) {
             Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id));
         }
     }
     $this->_html .= $errors;
 }
Esempio n. 6
0
 /**
  * 生成缩略图
  * @param $image
  * @param $cache_image
  * @param $size
  * @param string $image_type
  * @return bool|string
  */
 public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg')
 {
     if (!file_exists($image)) {
         return '';
     }
     if (!file_exists(IMAGE_CACHE_DIR . $cache_image)) {
         $infos = getimagesize($image);
         if (!ImageManager::checkImageMemoryLimit($image)) {
             return false;
         }
         $x = $infos[0];
         $y = $infos[1];
         $max_x = $size * 3;
         if ($y < $size && $x <= $max_x) {
             copy($image, IMAGE_CACHE_DIR . $cache_image);
         } else {
             $ratio_x = $x / ($y / $size);
             if ($ratio_x > $max_x) {
                 $ratio_x = $max_x;
                 $size = $y / ($x / $max_x);
             }
             ImageManager::resize($image, IMAGE_CACHE_DIR . $cache_image, $ratio_x, $size, $image_type);
         }
     }
     return IMAGE_CACHE_DIR . $cache_image;
 }
Esempio n. 7
0
 /**
  * Generate a cached thumbnail for object lists (eg. carrier, order states...etc)
  *
  * @param string $image Real image filename
  * @param string $cache_image Cached filename
  * @param int $size Desired size
  * @param string $image_type Image type
  * @param bool $disable_cache When turned on a timestamp will be added to the image URI to disable the HTTP cache
  * @return string
  */
 public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg', $disable_cache = false)
 {
     if (!file_exists($image)) {
         return '';
     }
     if (!file_exists(_PS_TMP_IMG_DIR_ . $cache_image)) {
         $infos = getimagesize($image);
         // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
         if (!ImageManager::checkImageMemoryLimit($image)) {
             return false;
         }
         $x = $infos[0];
         $y = $infos[1];
         $max_x = $size * 3;
         // Size is already ok
         if ($y < $size && $x <= $max_x) {
             copy($image, _PS_TMP_IMG_DIR_ . $cache_image);
         } else {
             $ratio_x = $x / ($y / $size);
             if ($ratio_x > $max_x) {
                 $ratio_x = $max_x;
                 $size = $y / ($x / $max_x);
             }
             ImageManager::resize($image, _PS_TMP_IMG_DIR_ . $cache_image, $ratio_x, $size, $image_type);
         }
     }
     return '<img src="' . _PS_TMP_IMG_ . $cache_image . (!$disable_cache ? '?time=' . time() : '') . '" alt="" class="imgm" />';
 }
 public function ajaxProcessuploadThumbnailImages()
 {
     $category = new Category((int) Tools::getValue('id_category'));
     if (isset($_FILES['thumbnail'])) {
         //Get total of image already present in directory
         $files = scandir(_PS_CAT_IMG_DIR_);
         $assigned_keys = array();
         $allowed_keys = array(0, 1, 2);
         foreach ($files as $file) {
             $matches = array();
             if (preg_match('/^' . $category->id . '-([0-9])?_thumb.jpg/i', $file, $matches) === 1) {
                 $assigned_keys[] = (int) $matches[1];
             }
         }
         $available_keys = array_diff($allowed_keys, $assigned_keys);
         $helper = new HelperImageUploader('thumbnail');
         $files = $helper->process();
         $total_errors = array();
         if (count($available_keys) < count($files)) {
             $total_errors['name'] = sprintf(Tools::displayError('An error occurred while uploading the image :'));
             $total_errors['error'] = sprintf(Tools::displayError('You cannot upload more files'));
             die(Tools::jsonEncode(array('thumbnail' => array($total_errors))));
         }
         foreach ($files as $key => &$file) {
             $id = array_shift($available_keys);
             $errors = array();
             // Evaluate the memory required to resize the image: if it's too much, you can't resize it.
             if (isset($file['save_path']) && !ImageManager::checkImageMemoryLimit($file['save_path'])) {
                 $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 (!isset($file['save_path']) || empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_ . (int) Tools::getValue('id_category') . '-' . $id . '_thumb.jpg')) {
                 $errors[] = Tools::displayError('An error occurred while uploading the image.');
             }
             if (count($errors)) {
                 $total_errors = array_merge($total_errors, $errors);
             }
             if (isset($file['save_path']) && is_file($file['save_path'])) {
                 unlink($file['save_path']);
             }
             //Necesary to prevent hacking
             if (isset($file['save_path'])) {
                 unset($file['save_path']);
             }
             if (isset($file['tmp_name'])) {
                 unset($file['tmp_name']);
             }
             //Add image preview and delete url
             $file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . (int) $category->id . '-' . $id . '_thumb.jpg', $this->context->controller->table . '_' . (int) $category->id . '-' . $id . '_thumb.jpg', 100, 'jpg', true, true);
             $file['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories') . '&deleteThumb=' . $id . '&id_category=' . (int) $category->id . '&updatecategory';
         }
         if (count($total_errors)) {
             $this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
         } else {
             Tools::clearSmartyCache();
         }
         die(Tools::jsonEncode(array('thumbnail' => $files)));
     }
 }
Esempio n. 9
0
 public function uploadMainImage($image, $hotel_id, $hotel_img_path, $active = false)
 {
     if (isset($image)) {
         if ($image['size'] > 0) {
             $rand_name = $this->randomImageName();
             Db::getInstance()->insert('htl_image', array('id_hotel' => (int) $hotel_id, 'hotel_image_id' => pSQL($rand_name)));
             $image_name = $rand_name . '.jpg';
             ImageManager::resize($image['tmp_name'], $hotel_img_path . $image_name);
         }
     }
 }
Esempio n. 10
0
     //		);
     return parent::renderForm();
 }
 protected function afterImageUpload()
 {
     $res = true;
     /* Generate image with differents size */
     if (($id_friend_data = (int) Tools::getValue('id_friend_data')) && isset($_FILES) && isset($_FILES) && count($_FILES) && $_FILES['image']['name'] != null && file_exists(_PS_MYFRIENDS_IMG_DIR_ . $id_friend_data . '.jpg')) {
         $images_types = ImageType::getImagesTypes('products');
         foreach ($images_types as $k => $image_type) {
             $res &= ImageManager::resize(_PS_MYFRIENDS_IMG_DIR_ . $id_friend_data . '.jpg', _PS_MYFRIENDS_IMG_DIR_ . $id_friend_data . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
         }
     }
     if (!$res) {
         $this->errors[] = Tools::displayError('Unable to resize one or more of your pictures.');
 public function postProcess()
 {
     if (Tools::isSubmit('submitOptionsconfiguration')) {
         if ($_FILES['htl_header_image']['name']) {
             $this->validateHotelHeaderImage($_FILES['htl_header_image']);
             if (!count($this->errors)) {
                 $img_path = _PS_IMG_DIR_ . 'hotel_header_image.png';
                 if (ImageManager::resize($_FILES['htl_header_image']['tmp_name'], $img_path)) {
                     Configuration::updateValue('WK_HOTEL_HEADER_IMAGE', 'hotel_header_image.png');
                 } else {
                     $this->errors[] = Tools::displayError('Some error occured while uoploading image.Please try again.');
                 }
             }
         }
     }
     parent::postProcess();
 }
Esempio n. 12
0
 protected function renderImage($url, $image, $size)
 {
     $setting = array();
     $setting['thumbnailurl'] = _PAGEBUILDER_IMAGE_URL_ . $image;
     $setting['imageurl'] = _PAGEBUILDER_IMAGE_URL_ . $image;
     if (count($size) == 2) {
         $cache = _PS_CACHE_DIR_ . 'pspagebuilder/';
         if (!file_exists($cache . $image)) {
             if (!is_dir($cache)) {
                 mkdir($cache, 0755);
             }
             if (ImageManager::resize(_PAGEBUILDER_IMAGE_DIR_ . $image, $cache . $image, $size[0], $size[1])) {
                 $setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $image;
             }
         } else {
             $setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $image;
         }
     }
     return $setting;
 }
Esempio n. 13
0
 protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null)
 {
     if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name'])) {
         // Delete old image
         if (Validate::isLoadedObject($object = $this->loadObject())) {
             $object->deleteImage();
         } else {
             return false;
         }
         // Check image validity
         $max_size = isset($this->max_image_size) ? $this->max_image_size : 0;
         if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize($max_size))) {
             $this->errors[] = $error;
         }
         $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
         if (!$tmp_name) {
             return false;
         }
         if (!move_uploaded_file($_FILES[$name]['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, _PS_MODULE_DIR_ . 'possequence' . DS . 'images' . DS . $name . '_' . $id . '.' . $this->imageType, (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;
         }
         return false;
     }
     return true;
 }
 public static function ImageGenerate()
 {
     $get_blog_image = SmartBlogPost::getBlogImage();
     $get_cate_image = BlogCategory::getCatImage();
     $get_author_image = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar.jpg';
     $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) {
             $path = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $cat_img['id_smart_blog_category'] . '.jpg';
             ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/category/' . $cat_img['id_smart_blog_category'] . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
         }
     }
     foreach ($posts_types as $image_type) {
         foreach ($get_blog_image as $blog_img) {
             $path = _PS_MODULE_DIR_ . 'smartblog/images/' . $blog_img['id_smart_blog_post'] . '.jpg';
             ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $blog_img['id_smart_blog_post'] . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
         }
     }
     foreach ($author_types as $author_type) {
         ImageManager::resize($get_author_image, _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . stripslashes($author_type['type_name']) . '.jpg', (int) $author_type['width'], (int) $author_type['height']);
     }
 }
 protected function _regenerateNewImagesOfOffers($dir, $type)
 {
     $dir = '/home/towers/sites/aphrodinet/img/offers/';
     if (!is_dir($dir)) {
         return false;
     }
     $generate_hight_dpi_images = (bool) Configuration::get('PS_HIGHT_DPI');
     include_once __DIR__ . '/../../../modules/aphrodinet/classes/AphOfferImage.php';
     error_log(var_export(AphOfferImage::getAllImages(), true));
     foreach (AphOfferImage::getAllImages() as $image) {
         $imageObj = new AphOfferImage($image['id_image']);
         $existing_img = $dir . $imageObj->getExistingImgPath() . '.jpg';
         if (file_exists($existing_img) && filesize($existing_img)) {
             foreach ($type as $imageType) {
                 unlink($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg');
                 //if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg')) {
                 if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
                     $this->errors[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product);
                 }
                 if ($generate_hight_dpi_images) {
                     if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
                         $this->errors[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product);
                     }
                 }
                 //}
             }
         } else {
             $this->errors[] = sprintf(Tools::displayError('Original image is missing or empty (%1$s) for product ID %2$d'), $existing_img, (int) $imageObj->id_product);
         }
         if (time() - $this->start_time > $this->max_execution_time - 4) {
             // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
             return 'timeout';
         }
     }
     return (bool) count($this->errors);
 }
Esempio n. 16
0
 private function copyImg($item, $className)
 {
     require_once '../../images.inc.php';
     $identifier = $this->supportedImports[strtolower($className)]['identifier'];
     $matchId = $this->getMatchId(strtolower($className));
     $matchIdLang = $this->getMatchIdLang();
     switch ($className) {
         default:
         case 'Product':
             $path = _PS_PROD_IMG_DIR_;
             $type = 'products';
             break;
         case 'Category':
             $path = _PS_CAT_IMG_DIR_;
             $type = 'categories';
             break;
         case 'Manufacturer':
             $path = _PS_MANU_IMG_DIR_;
             $type = 'manufacturers';
             break;
         case 'Supplier':
             $path = _PS_SUPP_IMG_DIR_;
             $type = 'suppliers';
             break;
     }
     $cover = 1;
     if (array_key_exists($item[$identifier], $matchId)) {
         if (array_key_exists('images', $item) && !is_null($item['images'])) {
             foreach ($item['images'] as $key => $image) {
                 $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'import');
                 if (@copy(str_replace(' ', '%20', $image), $tmpfile)) {
                     $imagesTypes = ImageType::getImagesTypes($type);
                     ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '.jpg');
                     if ($className == 'Product') {
                         $image = new Image();
                         $image->id_product = (int) $matchId[$item[$identifier]];
                         $image->cover = $cover;
                         $image->position = Image::getHighestPosition((int) $matchId[$item[$identifier]]) + 1;
                         $legend = array();
                         foreach ($item['name'] as $key => $val) {
                             if (array_key_exists($key, $matchIdLang)) {
                                 $legend[$matchIdLang[$key]] = Tools::link_rewrite($val);
                             } else {
                                 $legend[Configuration::get('PS_LANG_DEFAULT')] = Tools::link_rewrite($val);
                             }
                         }
                         $image->legend = $legend;
                         $image->add();
                         ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '-' . (int) $image->id . '.jpg');
                         foreach ($imagesTypes as $k => $imageType) {
                             ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '-' . (int) $image->id . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height']);
                         }
                     } else {
                         foreach ($imagesTypes as $imageType) {
                             ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height']);
                         }
                     }
                 } else {
                     @unlink($tmpfile);
                 }
                 @unlink($tmpfile);
                 $cover = 0;
             }
         }
     }
 }
Esempio n. 17
0
 protected function pictureUpload()
 {
     if (!($field_ids = $this->product->getCustomizationFieldIds())) {
         return false;
     }
     $authorized_file_fields = array();
     foreach ($field_ids as $field_id) {
         if ($field_id['type'] == Product::CUSTOMIZE_FILE) {
             $authorized_file_fields[(int) $field_id['id_customization_field']] = 'file' . (int) $field_id['id_customization_field'];
         }
     }
     $indexes = array_flip($authorized_file_fields);
     foreach ($_FILES as $field_name => $file) {
         if (in_array($field_name, $authorized_file_fields) && isset($file['tmp_name']) && !empty($file['tmp_name'])) {
             $file_name = md5(uniqid(rand(), true));
             if ($error = ImageManager::validateUpload($file, (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))) {
                 $this->errors[] = $error;
             }
             $product_picture_width = (int) Configuration::get('PS_PRODUCT_PICTURE_WIDTH');
             $product_picture_height = (int) Configuration::get('PS_PRODUCT_PICTURE_HEIGHT');
             $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
             if ($error || (!$tmp_name || !move_uploaded_file($file['tmp_name'], $tmp_name))) {
                 return false;
             }
             /* Original file */
             if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name)) {
                 $this->errors[] = Tools::displayError('An error occurred during the image upload.');
             } elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name . '_small', $product_picture_width, $product_picture_height)) {
                 $this->errors[] = Tools::displayError('An error occurred during the image upload.');
             } elseif (!chmod(_PS_UPLOAD_DIR_ . $file_name, 0777) || !chmod(_PS_UPLOAD_DIR_ . $file_name . '_small', 0777)) {
                 $this->errors[] = Tools::displayError('An error occurred during the image upload.');
             } else {
                 $this->context->cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name);
             }
             unlink($tmp_name);
         }
     }
     return true;
 }
 protected function postImage($id)
 {
     $ret = parent::postImage($id);
     if (($id_category = (int) Tools::getValue('id_category')) && isset($_FILES) && count($_FILES) && $_FILES['image']['name'] != null && file_exists(_PS_CAT_IMG_DIR_ . $id_category . '.jpg')) {
         $images_types = ImageType::getImagesTypes('categories');
         foreach ($images_types as $k => $image_type) {
             ImageManager::resize(_PS_CAT_IMG_DIR_ . $id_category . '.jpg', _PS_CAT_IMG_DIR_ . $id_category . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
         }
     }
     return $ret;
 }
Esempio n. 19
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']);
                 }
             }
         }
     }
 }
Esempio n. 20
0
 public function copyImagesImage($identifier)
 {
     $path = $this->img_path . 'p/';
     $image = new Image($this->retrieveId('image', $identifier));
     $dst_path = $image->getPathForCreation();
     if (!@copy($path . $identifier . '.jpg', $dst_path . '.' . $image->image_format)) {
         $this->setError($this->language->l('Cannot create image "%1$s" for entity "%2$s"', $identifier, 'product'));
         return;
     }
     @chmod($dst_path . '.' . $image->image_format, 0644);
     $types = ImageType::getImagesTypes('products');
     foreach ($types as $type) {
         $origin_file = $path . $identifier . '-' . $type['name'] . '.jpg';
         $target_file = $dst_path . '-' . $type['name'] . '.' . $image->image_format;
         // Test if dest folder is writable
         if (!is_writable(dirname($target_file))) {
             $this->setError($this->language->l('Cannot create image "%1$s" (bad permissions on folder "%2$s")', $identifier . '-' . $type['name'], dirname($target_file)));
         } elseif (file_exists($origin_file)) {
             if (!@copy($origin_file, $target_file)) {
                 $this->setError($this->language->l('Cannot create image "%1$s" for entity "%2$s"', $identifier . '-' . $type['name'], 'product'));
             }
             @chmod($target_file, 0644);
         } elseif (!ImageManager::resize($path . $identifier . '.jpg', $target_file, $type['width'], $type['height'])) {
             $this->setError($this->language->l('Cannot create image "%1$s" for entity "%2$s"', $identifier . '-' . $type['name'], 'product'));
         }
     }
 }
 protected function uploadImage($image, $image_w = '', $image_h = '')
 {
     $res = false;
     if (is_array($image) && ImageManager::validateUpload($image, $this->max_image_size) === false && ($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) && move_uploaded_file($image['tmp_name'], $tmp_name)) {
         $salt = sha1(microtime());
         $pathinfo = pathinfo($image['name']);
         $img_name = $salt . '_' . Tools::str2url($pathinfo['filename']) . '.' . $pathinfo['extension'];
         if (ImageManager::resize($tmp_name, dirname(__FILE__) . '/img/' . $img_name, $image_w, $image_h)) {
             $res = true;
         }
     }
     if (!$res) {
         $this->context->smarty->assign('error', $this->l('An error occurred during the image upload.'));
         return false;
     }
     return $img_name;
 }
 /**
  * Write the posted image on disk
  *
  * @param string $sreceptionPath
  * @param int $destWidth
  * @param int $destHeight
  * @param array $imageTypes
  * @param string $parentPath
  * @return boolean
  */
 protected function writePostedImageOnDisk($receptionPath, $destWidth = null, $destHeight = null, $imageTypes = null, $parentPath = null)
 {
     if ($this->wsObject->method == 'PUT') {
         if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
             $file = $_FILES['image'];
             if ($file['size'] > $this->imgMaxUploadSize) {
                 throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400));
             }
             // Get mime content type
             $mime_type = false;
             if (Tools::isCallable('finfo_open')) {
                 $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                 $finfo = finfo_open($const);
                 $mime_type = finfo_file($finfo, $file['tmp_name']);
                 finfo_close($finfo);
             } elseif (Tools::isCallable('mime_content_type')) {
                 $mime_type = mime_content_type($file['tmp_name']);
             } elseif (Tools::isCallable('exec')) {
                 $mime_type = trim(exec('file -b --mime-type ' . escapeshellarg($file['tmp_name'])));
             }
             if (empty($mime_type) || $mime_type == 'regular file') {
                 $mime_type = $file['type'];
             }
             if (($pos = strpos($mime_type, ';')) !== false) {
                 $mime_type = substr($mime_type, 0, $pos);
             }
             // Check mime content type
             if (!$mime_type || !in_array($mime_type, $this->acceptedImgMimeTypes)) {
                 throw new WebserviceException('This type of image format not recognized, allowed formats are: ' . implode('", "', $this->acceptedImgMimeTypes), array(73, 400));
             } elseif ($file['error']) {
                 throw new WebserviceException('Error while uploading image. Please change your server\'s settings', array(74, 400));
             }
             // Try to copy image file to a temporary file
             if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) {
                 throw new WebserviceException('Error while copying image to the temporary directory', array(75, 400));
             } else {
                 $result = $this->writeImageOnDisk($tmpName, $receptionPath, $destWidth, $destHeight, $imageTypes, $parentPath);
             }
             @unlink($tmpName);
             return $result;
         } else {
             throw new WebserviceException('Please set an "image" parameter with image data for value', array(76, 400));
         }
     } elseif ($this->wsObject->method == 'POST') {
         if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
             $file = $_FILES['image'];
             if ($file['size'] > $this->imgMaxUploadSize) {
                 throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400));
             }
             require_once _PS_ROOT_DIR_ . '/images.inc.php';
             if ($error = ImageManager::validateUpload($file)) {
                 throw new WebserviceException('Image upload error : ' . $error, array(76, 400));
             }
             if (isset($file['tmp_name']) && $file['tmp_name'] != null) {
                 if ($this->imageType == 'products') {
                     $product = new Product((int) $this->wsObject->urlSegment[2]);
                     if (!Validate::isLoadedObject($product)) {
                         throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400));
                     }
                     $image = new Image();
                     $image->id_product = (int) $product->id;
                     $image->position = Image::getHighestPosition($product->id) + 1;
                     if (!Image::getCover((int) $product->id)) {
                         $image->cover = 1;
                     } else {
                         $image->cover = 0;
                     }
                     if (!$image->add()) {
                         throw new WebserviceException('Error while creating image', array(76, 400));
                     }
                     if (!Validate::isLoadedObject($product)) {
                         throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400));
                     }
                 }
                 // copy image
                 if (!isset($file['tmp_name'])) {
                     return false;
                 }
                 if ($error = ImageManager::validateUpload($file, $this->imgMaxUploadSize)) {
                     throw new WebserviceException('Bad image : ' . $error, array(76, 400));
                 }
                 if ($this->imageType == 'products') {
                     $image = new Image($image->id);
                     if (!(Configuration::get('PS_OLD_FILESYSTEM') && file_exists(_PS_PROD_IMG_DIR_ . $product->id . '-' . $image->id . '.jpg'))) {
                         $image->createImgFolder();
                     }
                     if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) {
                         throw new WebserviceException('An error occurred during the image upload', array(76, 400));
                     } elseif (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format)) {
                         throw new WebserviceException('An error occurred while copying image', array(76, 400));
                     } else {
                         $imagesTypes = ImageType::getImagesTypes('products');
                         foreach ($imagesTypes as $imageType) {
                             if (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                                 $this->_errors[] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']);
                             }
                         }
                     }
                     @unlink($tmpName);
                     $this->imgToDisplay = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format;
                     $this->objOutput->setFieldsToDisplay('full');
                     $this->output = $this->objOutput->renderEntity($image, 1);
                     $image_content = array('sqlId' => 'content', 'value' => base64_encode(file_get_contents($this->imgToDisplay)), 'encode' => 'base64');
                     $this->output .= $this->objOutput->objectRender->renderField($image_content);
                 } elseif (in_array($this->imageType, array('categories', 'manufacturers', 'suppliers', 'stores'))) {
                     if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) {
                         throw new WebserviceException('An error occurred during the image upload', array(76, 400));
                     } elseif (!ImageManager::resize($tmpName, $receptionPath)) {
                         throw new WebserviceException('An error occurred while copying image', array(76, 400));
                     }
                     $imagesTypes = ImageType::getImagesTypes($this->imageType);
                     foreach ($imagesTypes as $imageType) {
                         if (!ImageManager::resize($tmpName, $parentPath . $this->wsObject->urlSegment[2] . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height'])) {
                             $this->_errors[] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']);
                         }
                     }
                     @unlink(_PS_TMP_IMG_DIR_ . $tmpName);
                     $this->imgToDisplay = $receptionPath;
                 }
                 return true;
             }
         }
     } else {
         throw new WebserviceException('Method ' . $this->wsObject->method . ' is not allowed for an image resource', array(77, 405));
     }
 }
Esempio n. 23
0
 /**
  * render content info
  */
 public function getContent()
 {
     //        $resultCheck = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_btmegamenu` as id FROM `' . _DB_PREFIX_ . 'btmegamenu_shop` WHERE `id_btmegamenu` = 1 AND `id_shop`=' . (int) ($this->context->shop->id));
     //        if ($resultCheck["id"] != 1){
     //            Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'btmegamenu_shop`(`id_btmegamenu`,`id_shop`) VALUES( 1, '.(int)$this->context->shop->id.' )');
     //        }
     $output = '';
     $this->_html .= $this->headerHTML();
     $this->_html .= '<h2>' . $this->displayName . '.</h2>';
     /* update tree megamenu positions */
     if (Tools::getValue('doupdatepos') && Tools::isSubmit('updatePosition')) {
         $list = Tools::getValue('list');
         $root = 1;
         $child = array();
         foreach ($list as $id => $parent_id) {
             if ($parent_id <= 0) {
                 # validate module
                 $parent_id = $root;
             }
             $child[$parent_id][] = $id;
         }
         $res = true;
         foreach ($child as $id_parent => $menus) {
             $i = 0;
             foreach ($menus as $id_btmegamenu) {
                 $res &= Db::getInstance()->execute('
                     UPDATE `' . _DB_PREFIX_ . 'btmegamenu` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' 
                     WHERE `id_btmegamenu` = ' . (int) $id_btmegamenu);
                 $i++;
             }
         }
         $this->clearCache();
         die($this->l('Update Positions Done'));
     }
     if (Tools::getValue('show_cavas') && Tools::isSubmit('updatecavas')) {
         $show = Tools::getValue('show') ? Tools::getValue('show') : 0;
         if (Configuration::updateValue('LEO_MEGAMENU_CAVAS', $show)) {
             $this->clearCache();
             die($this->l('Update Done'));
         } else {
             die($this->l('Can not Update'));
         }
     }
     /* delete megamenu item */
     if (Tools::getValue('dodel')) {
         $obj = new Btmegamenu((int) Tools::getValue('id_btmegamenu'));
         $res = $obj->delete();
         $this->clearCache();
         Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
     }
     if (Tools::isSubmit('save' . $this->name) && Tools::isSubmit('active')) {
         // if( Tools::getValue('type') == 'url' && !Tools::getValue('url')){
         //              $errors[] = $this->l('Account details are required.');
         //          }
         //			if (!isset($errors) AND !sizeof($errors)){
         if ($id_btmegamenu = Tools::getValue('id_btmegamenu')) {
             # validate module
             $megamenu = new Btmegamenu((int) $id_btmegamenu);
         } else {
             # validate module
             $megamenu = new Btmegamenu();
         }
         $keys = LeoBtmegamenuHelper::getConfigKey(false);
         $post = LeoBtmegamenuHelper::getPost($keys, false);
         $keys = LeoBtmegamenuHelper::getConfigKey(true);
         $post += LeoBtmegamenuHelper::getPost($keys, true);
         $megamenu->copyFromPost($post);
         $megamenu->id_shop = $this->context->shop->id;
         if ($megamenu->type && $megamenu->type != 'html' && Tools::getValue($megamenu->type . '_type')) {
             # validate module
             $megamenu->item = Tools::getValue($megamenu->type . '_type');
         }
         $url_default = '';
         foreach ($megamenu->url as $menu_url) {
             if ($menu_url) {
                 $url_default = $menu_url;
                 break;
             }
         }
         if ($url_default) {
             foreach ($megamenu->url as &$menu_url) {
                 if (!$menu_url) {
                     $menu_url = $url_default;
                 }
             }
         }
         if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) {
             $megamenu->save();
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 $this->checkFolderIcon();
                 if (ImageManager::validateUpload($_FILES['image'])) {
                     return false;
                 } elseif (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) {
                     return false;
                 } elseif (!ImageManager::resize($tmp_name, $this->img_path . $_FILES['image']['name'])) {
                     return false;
                 }
                 unlink($tmp_name);
                 $megamenu->image = $_FILES['image']['name'];
                 $megamenu->save();
             } else {
                 if (Tools::getIsset('delete_icon')) {
                     if ($megamenu->image) {
                         unlink($this->img_path . $megamenu->image);
                         $megamenu->image = '';
                         $megamenu->save();
                     }
                 }
             }
             Tools::redirectAdmin(AdminController::$currentIndex . '&configure=leobootstrapmenu&save' . $this->name . '&token=' . Tools::getValue('token') . '&id_btmegamenu=' . $megamenu->id);
         } else {
             # validate module
             $errors = array();
             $errors[] = $this->l('An error occurred while attempting to save.');
         }
         //			}
         if (isset($errors) && count($errors)) {
             $output .= $this->displayError(implode('<br />', $errors));
         } else {
             $this->clearCache();
             $output .= $this->displayConfirmation($this->l('Settings updated.'));
         }
     }
     return $output . $this->displayForm();
 }
 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']);
                 }
             }
         }
     }
 }
Esempio n. 25
0
 /**
  * Generic function which allows logo upload
  *
  * @param $field_name
  * @param $logo_prefix
  *
  * @return bool
  */
 protected function updateLogo($field_name, $logo_prefix)
 {
     $id_shop = Context::getContext()->shop->id;
     if (isset($_FILES[$field_name]['tmp_name']) && $_FILES[$field_name]['tmp_name']) {
         if ($error = ImageManager::validateUpload($_FILES[$field_name], Tools::getMaxUploadSize())) {
             $this->errors[] = $error;
             return false;
         }
         $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
         if (!$tmp_name || !move_uploaded_file($_FILES[$field_name]['tmp_name'], $tmp_name)) {
             return false;
         }
         $ext = $field_name == 'PS_STORES_ICON' ? '.gif' : '.jpg';
         $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . Configuration::get('PS_IMG_UPDATE_TIME') . '-' . (int) $id_shop . $ext;
         if (Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL || $id_shop == 0 || Shop::isFeatureActive() == false) {
             $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . Configuration::get('PS_IMG_UPDATE_TIME') . $ext;
         }
         if ($field_name == 'PS_STORES_ICON') {
             if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name, null, null, 'gif', true)) {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.');
             }
         } else {
             if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name)) {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.');
             }
         }
         if (!count($this->errors) && @filemtime(_PS_IMG_DIR_ . Configuration::get($field_name))) {
             @unlink(_PS_IMG_DIR_ . Configuration::get($field_name));
         }
         Configuration::updateValue($field_name, $logo_name);
         @unlink($tmp_name);
     }
 }
Esempio n. 26
0
 public function ajaxProcessUpdateCustomizationFields()
 {
     $errors = array();
     if ($this->tabAccess['edit'] === '1') {
         $errors = array();
         if (Tools::getValue('only_display') != 1) {
             if (!$this->context->cart->id || !($id_product = (int) Tools::getValue('id_product'))) {
                 return;
             }
             $product = new Product((int) $id_product);
             if (!($customization_fields = $product->getCustomizationFieldIds())) {
                 return;
             }
             foreach ($customization_fields as $customization_field) {
                 $field_id = 'customization_' . $id_product . '_' . $customization_field['id_customization_field'];
                 if ($customization_field['type'] == Product::CUSTOMIZE_TEXTFIELD) {
                     if (!Tools::getValue($field_id)) {
                         if ($customization_field['required']) {
                             $errors[] = Tools::displayError('Please fill in all the required fields.');
                         }
                         continue;
                     }
                     if (!Validate::isMessage(Tools::getValue($field_id))) {
                         $errors[] = Tools::displayError('Invalid message');
                     }
                     $this->context->cart->addTextFieldToProduct((int) $product->id, (int) $customization_field['id_customization_field'], Product::CUSTOMIZE_TEXTFIELD, Tools::getValue($field_id));
                 } elseif ($customization_field['type'] == Product::CUSTOMIZE_FILE) {
                     if (!isset($_FILES[$field_id]) || !isset($_FILES[$field_id]['tmp_name']) || empty($_FILES[$field_id]['tmp_name'])) {
                         if ($customization_field['required']) {
                             $errors[] = Tools::displayError('Please fill in all the required fields.');
                         }
                         continue;
                     }
                     if ($error = ImageManager::validateUpload($_FILES[$field_id], (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))) {
                         $errors[] = $error;
                     }
                     if (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$field_id]['tmp_name'], $tmp_name)) {
                         $errors[] = Tools::displayError('An error occurred during the image upload process.');
                     }
                     $file_name = md5(uniqid(rand(), true));
                     if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name)) {
                         continue;
                     } elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name . '_small', (int) Configuration::get('PS_PRODUCT_PICTURE_WIDTH'), (int) Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'))) {
                         $errors[] = Tools::displayError('An error occurred during the image upload process.');
                     } elseif (!chmod(_PS_UPLOAD_DIR_ . $file_name, 0777) || !chmod(_PS_UPLOAD_DIR_ . $file_name . '_small', 0777)) {
                         $errors[] = Tools::displayError('An error occurred during the image upload process.');
                     } else {
                         $this->context->cart->addPictureToProduct((int) $product->id, (int) $customization_field['id_customization_field'], Product::CUSTOMIZE_FILE, $file_name);
                     }
                     unlink($tmp_name);
                 }
             }
         }
         $this->setMedia();
         $this->initFooter();
         $this->context->smarty->assign(array('customization_errors' => implode('<br />', $errors), 'css_files' => $this->css_files));
         return $this->smartyOutputContent('controllers/orders/form_customization_feedback.tpl');
     }
 }
 public function getContent()
 {
     $html = '';
     $id_reinsurance = (int) Tools::getValue('id_reinsurance');
     if (Tools::isSubmit('saveblockreinsurance')) {
         if ($id_reinsurance = Tools::getValue('id_reinsurance')) {
             $reinsurance = new reinsuranceClass((int) $id_reinsurance);
         } else {
             $reinsurance = new reinsuranceClass();
         }
         $reinsurance->copyFromPost();
         $reinsurance->id_shop = $this->context->shop->id;
         if ($reinsurance->validateFields(false) && $reinsurance->validateFieldsLang(false)) {
             $reinsurance->save();
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 if ($error = ImageManager::validateUpload($_FILES['image'])) {
                     return false;
                 } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) {
                     return false;
                 } elseif (!ImageManager::resize($tmpName, dirname(__FILE__) . '/img/reinsurance-' . (int) $reinsurance->id . '-' . (int) $reinsurance->id_shop . '.jpg')) {
                     return false;
                 }
                 unlink($tmpName);
                 $reinsurance->file_name = 'reinsurance-' . (int) $reinsurance->id . '-' . (int) $reinsurance->id_shop . '.jpg';
                 $reinsurance->save();
             }
             $this->_clearCache('blockreinsurance.tpl');
         } else {
             $html .= '<div class="conf error">' . $this->l('An error occurred while attempting to save.') . '</div>';
         }
     }
     if (Tools::isSubmit('updateblockreinsurance') || Tools::isSubmit('addblockreinsurance')) {
         $helper = $this->initForm();
         foreach (Language::getLanguages(false) as $lang) {
             if ($id_reinsurance) {
                 $reinsurance = new reinsuranceClass((int) $id_reinsurance);
                 $helper->fields_value['text'][(int) $lang['id_lang']] = $reinsurance->text[(int) $lang['id_lang']];
             } else {
                 $helper->fields_value['text'][(int) $lang['id_lang']] = Tools::getValue('text_' . (int) $lang['id_lang'], '');
             }
         }
         if ($id_reinsurance = Tools::getValue('id_reinsurance')) {
             $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reinsurance');
             $helper->fields_value['id_reinsurance'] = (int) $id_reinsurance;
         }
         return $html . $helper->generateForm($this->fields_form);
     } else {
         if (Tools::isSubmit('deleteblockreinsurance')) {
             $reinsurance = new reinsuranceClass((int) $id_reinsurance);
             if (file_exists(dirname(__FILE__) . '/img/' . $reinsurance->file_name)) {
                 unlink(dirname(__FILE__) . '/img/' . $reinsurance->file_name);
             }
             $reinsurance->delete();
             $this->_clearCache('blockreinsurance.tpl');
             Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
         } else {
             $helper = $this->initList();
             return $html . $helper->generateList($this->getListContent((int) Configuration::get('PS_LANG_DEFAULT')), $this->fields_list);
         }
     }
     if (isset($_POST['submitModule'])) {
         Configuration::updateValue('BLOCKREINSURANCE_NBBLOCKS', isset($_POST['nbblocks']) && $_POST['nbblocks'] != '' ? (int) $_POST['nbblocks'] : '');
         if ($this->removeFromDB() && $this->addToDB()) {
             $this->_clearCache('blockreinsurance.tpl');
             $output = '<div class="conf confirm">' . $this->l('The block configuration has been updated.') . '</div>';
         } else {
             $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>' . $this->l('An error occurred while attempting to save.') . '</div>';
         }
     }
 }
 /**
  * Copy a no-product image
  *
  * @param string $language Language iso_code for no_picture image filename
  *
  * @return void|false
  */
 public function copyNoPictureImage($language)
 {
     if (isset($_FILES['no_picture']) && $_FILES['no_picture']['error'] === 0) {
         if ($error = ImageManager::validateUpload($_FILES['no_picture'], Tools::getMaxUploadSize())) {
             $this->errors[] = $error;
         } else {
             if (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['no_picture']['tmp_name'], $tmp_name)) {
                 return false;
             }
             if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'p/' . $language . '.jpg')) {
                 $this->errors[] = Tools::displayError('An error occurred while copying "No Picture" image to your product folder.');
             }
             if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'c/' . $language . '.jpg')) {
                 $this->errors[] = Tools::displayError('An error occurred while copying "No picture" image to your category folder.');
             }
             if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'm/' . $language . '.jpg')) {
                 $this->errors[] = Tools::displayError('An error occurred while copying "No picture" image to your manufacturer folder.');
             } else {
                 $images_types = ImageType::getImagesTypes('products');
                 foreach ($images_types as $k => $image_type) {
                     if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'p/' . $language . '-default-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'])) {
                         $this->errors[] = Tools::displayError('An error occurred while resizing "No picture" image to your product directory.');
                     }
                     if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'c/' . $language . '-default-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'])) {
                         $this->errors[] = Tools::displayError('An error occurred while resizing "No picture" image to your category directory.');
                     }
                     if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'm/' . $language . '-default-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'])) {
                         $this->errors[] = Tools::displayError('An error occurred while resizing "No picture" image to your manufacturer directory.');
                     }
                 }
             }
             unlink($tmp_name);
         }
     }
 }
Esempio n. 29
0
 private function _postProcess()
 {
     $errors = array();
     /* Processes Slider */
     if (Tools::isSubmit('submitSlider')) {
         $res = Configuration::updateValue('CATESLIDER_WIDTH', (int) Tools::getValue('slide_width'));
         $res &= Configuration::updateValue('CATESLIDER_HEIGHT', (int) Tools::getValue('slide_height'));
         $res &= Configuration::updateValue('CATESLIDER_SPEED', (int) Tools::getValue('slide_speed'));
         $res &= Configuration::updateValue('CATESLIDER_PAUSE', (int) Tools::getValue('slide_pause'));
         $res &= Configuration::updateValue('CATESLIDER_LOOP', (int) Tools::getValue('slide_loop'));
         $this->clearCache();
         if (!$res) {
             $errors[] = $this->displayError($this->l('The configuration could not be updated.'));
         }
         $this->_html .= $this->displayConfirmation($this->l('Configuration updated'));
     } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) {
         $slide = new CategorySlide((int) Tools::getValue('id_slide'));
         if ($slide->active == 0) {
             $slide->active = 1;
         } else {
             $slide->active = 0;
         }
         $res = $slide->update();
         $this->clearCache();
         $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.'));
     } elseif (Tools::isSubmit('submitSlide')) {
         /* Sets ID if needed */
         if (Tools::getValue('id_slide')) {
             $slide = new CategorySlide((int) Tools::getValue('id_slide'));
             if (!Validate::isLoadedObject($slide)) {
                 $this->_html .= $this->displayError($this->l('Invalid id_slide'));
                 return;
             }
         } else {
             $slide = new CategorySlide();
         }
         /* Sets position */
         $slide->position = (int) Tools::getValue('position');
         /* Sets active */
         $slide->active = (int) Tools::getValue('active_slide');
         $slide->id_category = (int) Tools::getValue('id_category');
         /* Sets each langue fields */
         $languages = Language::getLanguages(false);
         foreach ($languages as $language) {
             $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']);
             $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']);
             $slide->legend[$language['id_lang']] = Tools::getValue('legend_' . $language['id_lang']);
             $slide->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
             /* Uploads image and sets slide */
             $type = strtolower(substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1));
             $imagesize = array();
             $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']);
             if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) {
                 $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                 $salt = sha1(microtime());
                 if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) {
                     $errors[] = $error;
                 } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) {
                     return false;
                 } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/images/' . Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type, null, null, $type)) {
                     $errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
                 }
                 if (isset($temp_name)) {
                     @unlink($temp_name);
                 }
                 $slide->image[$language['id_lang']] = Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type;
             } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') {
                 $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']);
             }
         }
         /* Processes if no errors  */
         if (!$errors) {
             /* Adds */
             if (!Tools::getValue('id_slide')) {
                 if (!$slide->add()) {
                     $errors[] = $this->displayError($this->l('The slide could not be added.'));
                 }
             } elseif (!$slide->update()) {
                 $errors[] = $this->displayError($this->l('The slide could not be updated.'));
             }
             $this->clearCache();
         }
     } elseif (Tools::isSubmit('delete_id_slide')) {
         $slide = new CategorySlide((int) Tools::getValue('delete_id_slide'));
         $res = $slide->delete();
         $this->clearCache();
         if (!$res) {
             $this->_html .= $this->displayError('Could not delete');
         } else {
             $this->_html .= $this->displayConfirmation($this->l('Slide deleted'));
         }
     }
     /* Display errors if needed */
     if (count($errors)) {
         $this->_html .= $this->displayError(implode('<br />', $errors));
     } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) {
         $this->_html .= $this->displayConfirmation($this->l('Slide updated'));
     } elseif (Tools::isSubmit('submitSlide')) {
         $this->_html .= $this->displayConfirmation($this->l('Slide added'));
     }
 }
 public function getContent()
 {
     if (Tools::isSubmit('save_testimonial_data')) {
         $name = Tools::getValue('name');
         $testimonial_description = Tools::getValue('testimonial_description');
         $testimonial_content = Tools::getValue('testimonial_content');
         $testimonial_id = Tools::getValue('testimonial_id');
         foreach ($name as $key => $value) {
             if (!$testimonial_description[$key]) {
                 $this->_postErrors[] = $this->l('Testimonial description is a required field.');
             }
             if (!$testimonial_content[$key]) {
                 $this->_postErrors[] = $this->l('Testimonial content is a required field.');
             }
         }
         if ($_FILES) {
             $this->validateTestimonialsImages($_FILES['testimonial_image']);
         }
         $testimonial_img_path = _PS_MODULE_DIR_ . 'wktestimonialblock/views/img/';
         if (!count($this->_postErrors)) {
             foreach ($name as $key => $value) {
                 if (isset($testimonial_id[$key]) && $testimonial_id[$key]) {
                     $obj_testimonial_data = new WkHotelTestimonialData($testimonial_id[$key]);
                 } else {
                     $obj_testimonial_data = new WkHotelTestimonialData();
                 }
                 $obj_testimonial_data->name = $value;
                 $obj_testimonial_data->testimonial_description = $testimonial_description[$key];
                 $obj_testimonial_data->testimonial_content = $testimonial_content[$key];
                 $obj_testimonial_data->save();
                 if (isset($_FILES['testimonial_image']['name'][$key]) && $_FILES['testimonial_image']['name'][$key]) {
                     $obj_testimonial_data_img = new WkHotelTestimonialData($obj_testimonial_data->id);
                     $image_name = $obj_testimonial_data->id . '.jpg';
                     ImageManager::resize($_FILES['testimonial_image']['tmp_name'][$key], $testimonial_img_path . $image_name);
                     $obj_testimonial_data_img->testimonial_image = $image_name;
                     $obj_testimonial_data_img->save();
                 }
             }
             $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
         } else {
             foreach ($this->_postErrors as $err) {
                 $this->_html .= $this->displayError($err);
             }
         }
     } else {
         $this->_html .= '<br />';
     }
     $obj_testimonial_data = new WkHotelTestimonialData();
     $testimonials_data = $obj_testimonial_data->getAllTestimonialsData();
     $this->context->smarty->assign('testimonials_data', $testimonials_data);
     $this->context->smarty->assign('module_dir', _MODULE_DIR_);
     //tinymce
     $this->context->controller->addJS(_PS_JS_DIR_ . 'tiny_mce/tiny_mce.js');
     if (version_compare(_PS_VERSION_, '1.6.0.11', '>')) {
         $this->context->controller->addJS(_PS_JS_DIR_ . 'admin/tinymce.inc.js');
     } else {
         $this->context->controller->addJS(_PS_JS_DIR_ . 'tinymce.inc.js');
     }
     //tinymce setup
     $this->context->smarty->assign('path_css', _THEME_CSS_DIR_);
     $this->context->smarty->assign('ad', __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_));
     $this->context->smarty->assign('autoload_rte', true);
     $this->context->smarty->assign('lang', true);
     $this->context->smarty->assign('iso', $this->context->language->iso_code);
     $this->context->smarty->assign('link', new Link());
     $this->context->controller->addJS($this->_path . 'views/js/hotel_testimonial_block.js');
     $this->_html .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/hoteltestimonialblock.tpl');
     return $this->_html;
 }