/**
  * Process media files
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		4.0
  */
 private function _processMedia()
 {
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $template = $jinput->get('template', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->file_url)) {
             // Image handling
             $imagehelper = new ImageHelper();
             // Verify the original image
             if ($imagehelper->isRemote($this->file_url)) {
                 $original = $this->file_url;
                 $remote = true;
                 if ($template->get('save_images_on_server', 'image')) {
                     switch ($this->file_type) {
                         case 'category':
                             $base = $template->get('file_location_category_images', 'path');
                             break;
                         default:
                             $base = $template->get('file_location_product_images', 'path');
                             break;
                     }
                 } else {
                     $base = '';
                 }
                 $full_path = $base;
             } else {
                 // Create the full file_url path
                 switch ($this->file_type) {
                     case 'category':
                         $base = $template->get('file_location_category_images', 'path');
                         break;
                     default:
                         $base = $template->get('file_location_product_images', 'path');
                         break;
                 }
                 // Check if the image contains the image path
                 $dirname = dirname($this->file_url);
                 if (strpos($base, $dirname) !== false) {
                     $image = basename($this->file_url);
                 }
                 $original = $base . $this->file_url;
                 $remote = false;
                 // Get subfolders
                 $path_parts = pathinfo($original);
                 $full_path = $path_parts['dirname'] . '/';
                 $csvilog->addDebug(JText::sprintf('COM_CSVI_CREATED_FILE_URL', $original));
                 $remote = false;
             }
             // Generate image names
             $file_details = $imagehelper->ProcessImage($original, $full_path);
             // Process the file details
             if ($file_details['exists'] && $file_details['isimage']) {
                 $media = array();
                 $this->file_title = $this->file_title ? $this->file_title : $this->file_url;
                 $this->file_description = $this->file_description ? $this->file_description : $this->file_url;
                 $this->file_meta = $this->file_meta ? $this->file_meta : $this->file_url;
                 $this->file_mimetype = $file_details['mime_type'];
                 $this->file_type = $this->file_type;
                 $this->file_is_product_image = $this->file_type == 'product' ? 1 : 0;
                 $this->file_is_downloadable = $this->file_is_downloadable ? $this->file_is_downloadable : 0;
                 $this->file_is_forSale = $this->file_is_forSale ? $this->file_is_forSale : 0;
                 $this->file_url = empty($file_details['output_path']) ? $file_details['output_name'] : $file_details['output_path'] . $file_details['output_name'];
                 // Create the thumbnail
                 if ($template->get('thumb_create', 'image')) {
                     // Get the subfolder structure
                     $thumb_path = str_ireplace($base, '', $full_path);
                     if (empty($this->file_url_thumb)) {
                         $this->file_url_thumb = 'resized/' . $thumb_path . basename($this->file_url);
                     }
                     if (!$remote) {
                         $original = $this->file_url;
                     }
                     $this->file_url_thumb = $imagehelper->createThumbnail($original, $base, $this->file_url_thumb);
                 } else {
                     if (empty($this->file_url_thumb)) {
                         $this->file_url_thumb = $this->file_url;
                     }
                 }
             }
         }
     }
 }
 /**
  * Process media files
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		4.0
  */
 private function _processMedia()
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     $csvilog = $jinput->get('csvilog', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->file_url) || $template->get('auto_generate_image_name', 'image', false)) {
             // Create an array of images to process
             $images = explode('|', $this->file_url);
             $thumbs = explode('|', $this->file_url_thumb);
             $titles = explode('|', $this->file_title);
             $descriptions = explode('|', $this->file_description);
             $metas = explode('|', $this->file_meta);
             $ordering = 1;
             // Image handling
             $imagehelper = new ImageHelper();
             foreach ($images as $key => $image) {
                 $image = trim($image);
                 // Create image name if needed
                 if (count($images) == 1) {
                     $img_counter = 0;
                 } else {
                     $img_counter = $key + 1;
                 }
                 if ($template->get('auto_generate_image_name', 'image')) {
                     $this->_createImageName($img_counter);
                 }
                 if (!empty($image)) {
                     // Verify the original image
                     if ($imagehelper->isRemote($image)) {
                         $original = $image;
                         $remote = true;
                         $full_path = $template->get('file_location_product_images', 'path');
                     } else {
                         $original = $template->get('file_location_product_images', 'path') . $image;
                         $remote = false;
                         // Get subfolders
                         $path_parts = pathinfo($original);
                         $full_path = $path_parts['dirname'] . '/';
                     }
                     // Generate image names
                     if ($template->get('auto_generate_image_name', 'image')) {
                         $file_details = $imagehelper->ProcessImage($original, $full_path, $this->product_full_image_output);
                     } else {
                         $file_details = $imagehelper->ProcessImage($original, $full_path);
                     }
                     // Process the file details
                     if ($file_details['exists']) {
                         // Check if the image is an external image
                         if (substr($file_details['name'], 0, 4) == 'http') {
                             $csvilog->AddStats('incorrect', 'COM_CSVI_VM_NOSUPPORT_URL');
                         } else {
                             $title = isset($titles[$key]) ? $titles[$key] : $file_details['output_name'];
                             $description = isset($descriptions[$key]) ? $descriptions[$key] : '';
                             $meta = isset($metas[$key]) ? $metas[$key] : '';
                             $media = array();
                             $media['virtuemart_vendor_id'] = $this->virtuemart_vendor_id;
                             if ($template->get('autofill', 'image')) {
                                 $media['file_title'] = $file_details['output_name'];
                                 $media['file_description'] = $file_details['output_name'];
                                 $media['file_meta'] = $file_details['output_name'];
                             } else {
                                 $media['file_title'] = $title;
                                 $media['file_description'] = $description;
                                 $media['file_meta'] = $meta;
                             }
                             $media['file_mimetype'] = $file_details['mime_type'];
                             $media['file_type'] = 'product';
                             $media['file_is_product_image'] = 1;
                             $media['file_is_downloadable'] = 0;
                             $media['file_is_forSale'] = 0;
                             $media['file_url'] = empty($file_details['output_path']) ? $file_details['output_name'] : $file_details['output_path'] . $file_details['output_name'];
                             $media['published'] = $this->published;
                             // Create the thumbnail
                             if ($file_details['isimage']) {
                                 $thumb = isset($thumbs[$key]) ? $thumbs[$key] : null;
                                 if ($template->get('thumb_create', 'image')) {
                                     $thumb_sizes = getimagesize(JPATH_SITE . '/' . $media['file_url']);
                                     if (empty($thumb)) {
                                         $thumb = 'resized/' . basename($media['file_url']);
                                     }
                                     if ($thumb_sizes[0] < 1024 || $thumb_sizes[1] < 768) {
                                         $media['file_url_thumb'] = $imagehelper->createThumbnail($media['file_url'], $template->get('file_location_product_images', 'path'), $thumb);
                                     } else {
                                         $media['file_url_thumb'] = '';
                                     }
                                 } else {
                                     $media['file_url_thumb'] = empty($thumb) ? $media['file_url'] : $file_details['output_path'] . $thumb;
                                     if (substr($media['file_url_thumb'], 0, 4) == 'http') {
                                         $csvilog->addDebug(JText::sprintf('COM_CSVI_RESET_THUMB_NOHTTP', $media['file_url_thumb']));
                                         $media['file_url_thumb'] = '';
                                     }
                                 }
                             } else {
                                 $media['file_is_product_image'] = 0;
                                 $media['file_url_thumb'] = '';
                             }
                             // Bind the media data
                             $this->_medias->bind($media);
                             // Check if the media image already exists
                             $this->_medias->check();
                             // Store the media data
                             if ($this->_medias->store()) {
                                 if ($this->queryResult() == 'UPDATE') {
                                     $csvilog->AddStats('updated', JText::_('COM_CSVI_UPDATE_MEDIA'));
                                 } else {
                                     $csvilog->AddStats('added', JText::_('COM_CSVI_ADD_MEDIA'));
                                 }
                                 // Store the debug message
                                 $csvilog->addDebug('COM_CSVI_MEDIA_QUERY', true);
                                 // Watermark the image
                                 if ($template->get('full_watermark', 'image') && $file_details['isimage']) {
                                     $imagehelper->addWatermark(JPATH_SITE . '/' . $media['file_url']);
                                 }
                                 // Store the product image relation
                                 $data = array();
                                 $data['virtuemart_product_id'] = $this->virtuemart_product_id;
                                 $data['virtuemart_media_id'] = $this->_medias->virtuemart_media_id;
                                 $data['ordering'] = $ordering;
                                 $this->_product_medias->bind($data);
                                 if (!$this->_product_medias->check()) {
                                     if ($this->_product_medias->store()) {
                                         $csvilog->addDebug('COM_CSVI_STORE_PRODUCT_IMAGE_RELATION', true);
                                         $ordering++;
                                     }
                                 } else {
                                     $csvilog->addDebug('Product image relation already exists');
                                 }
                             } else {
                                 $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_MEDIA_NOT_ADDED', $this->_medias->getError()));
                                 return false;
                             }
                             // Reset the product media table
                             $this->_medias->reset();
                             $this->_product_medias->reset();
                         }
                         // else
                     }
                     // if
                 }
                 // if
             }
             // foreach
         }
         // if
     }
 }
 /**
  * Process media files
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		4.0
  */
 private function _processMedia()
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->file_url)) {
             // Image handling
             $imagehelper = new ImageHelper();
             // Verify the original image
             if ($imagehelper->isRemote($this->file_url)) {
                 $original = $this->file_url;
                 $remote = true;
             } else {
                 $original = $template->get('file_location_category_images', 'path') . $this->file_url;
                 $remote = false;
             }
             $file_details = $imagehelper->ProcessImage($original, $template->get('file_location_category_images', 'path'));
             // Process the file details
             if ($file_details['exists'] && $file_details['isimage']) {
                 $media = array();
                 $media['virtuemart_vendor_id'] = $this->virtuemart_vendor_id;
                 $media['file_title'] = $this->file_url;
                 $media['file_description'] = $this->file_url;
                 $media['file_meta'] = $this->file_url;
                 $media['file_mimetype'] = $file_details['mime_type'];
                 $media['file_type'] = 'category';
                 $media['file_is_product_image'] = 0;
                 $media['file_is_downloadable'] = 0;
                 $media['file_is_forSale'] = 0;
                 $media['file_url'] = empty($file_details['output_path']) ? $file_details['output_name'] : $file_details['output_path'] . $file_details['output_name'];
                 $media['published'] = $this->published;
                 // Create the thumbnail
                 if ($template->get('thumb_create', 'image')) {
                     if (empty($this->file_url_thumb)) {
                         $this->file_url_thumb = 'resized/' . basename($media['file_url']);
                     }
                     if ($remote) {
                         $original = $this->file_url;
                     } else {
                         $original = $media['file_url'];
                     }
                     $media['file_url_thumb'] = $imagehelper->createThumbnail($original, $template->get('file_location_category_images', 'path'), $this->file_url_thumb);
                 } else {
                     $media['file_url_thumb'] = empty($this->file_url_thumb) ? $media['file_url'] : $this->file_url_thumb;
                 }
                 // Bind the media data
                 $this->_medias->bind($media);
                 // Check if the media image already exists
                 $this->_medias->check();
                 // Store the media data
                 if ($this->_medias->store()) {
                     // Store the product image relation
                     $data = array();
                     $data['virtuemart_category_id'] = $this->virtuemart_category_id;
                     $data['virtuemart_media_id'] = $this->_medias->virtuemart_media_id;
                     $this->_category_medias->bind($data);
                     if (!$this->_category_medias->check()) {
                         $this->_category_medias->store();
                     }
                 }
             }
         }
     }
 }
 /**
  * Process property images
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		4.3
  */
 private function _processMedia($image)
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     $csvilog = $jinput->get('csvilog', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->{$image})) {
             // Image handling
             $imagehelper = new ImageHelper();
             // Verify the original image
             if ($imagehelper->isRemote($this->{$image})) {
                 $original = $this->{$image};
                 $remote = true;
                 $full_path = $template->get('file_location_property_images', 'path');
             } else {
                 $original = $template->get('file_location_property_images', 'path') . $this->{$image};
                 $remote = false;
                 // Get subfolders
                 $path_parts = pathinfo($original);
                 $full_path = $path_parts['dirname'] . '/';
             }
             // Generate image names
             $file_details = $imagehelper->ProcessImage($original, $full_path);
             // Process the file details
             if ($file_details['exists'] && $file_details['isimage']) {
                 // Check if the image is an external image
                 if (substr($file_details['name'], 0, 4) == 'http') {
                     $csvilog->AddStats('incorrect', 'COM_CSVI_EZREALTY_NOSUPPORT_URL');
                 } else {
                     $this->{$image} = $file_details['output_name'];
                     // Create the thumbnail
                     if ($template->get('thumb_create', 'image')) {
                         $imagehelper->createThumbnail($file_details['output_path'] . $this->{$image}, $template->get('file_location_property_images', 'path') . 'th/', $this->{$image});
                     }
                 }
             }
         }
     }
 }
Example #5
0
 /**
  * Process property images
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		4.3
  */
 private function _processMedia($image)
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     $csvilog = $jinput->get('csvilog', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->{$image})) {
             // Create an array of images to process
             $images = explode('|', $this->{$image});
             $titles = explode('|', $this->file_title);
             $descriptions = explode('|', $this->file_description);
             $order = explode('|', $this->file_ordering);
             $ordering = 1;
             $max_width = $template->get('resize_max_width', 'image', 1024);
             $max_height = $template->get('resize_max_height', 'image', 768);
             // Image handling
             $imagehelper = new ImageHelper();
             foreach ($images as $key => $image) {
                 $image = trim($image);
                 // Create image name if needed
                 if (count($images) == 1) {
                     $img_counter = 0;
                 } else {
                     $img_counter = $key + 1;
                 }
                 if (!empty($image)) {
                     // Verify the original image
                     if ($imagehelper->isRemote($image)) {
                         $original = $image;
                         $remote = true;
                         $full_path = $template->get('file_location_property_images', 'path');
                     } else {
                         $original = $template->get('file_location_property_images', 'path') . $image;
                         $remote = false;
                         // Get subfolders
                         $path_parts = pathinfo($original);
                         $full_path = $path_parts['dirname'] . '/';
                     }
                     // Generate image names
                     $file_details = $imagehelper->ProcessImage($original, $full_path);
                     // Process the file details
                     if ($file_details['exists'] && $file_details['isimage']) {
                         // Check if the image is an external image
                         $title = isset($titles[$key]) ? $titles[$key] : $file_details['output_name'];
                         $description = isset($descriptions[$key]) ? $descriptions[$key] : '';
                         $data = array();
                         $data['propid'] = $this->id;
                         $data['fname'] = $file_details['output_name'];
                         $data['title'] = $title;
                         $data['description'] = $description;
                         $data['ordering'] = isset($order[$key]) && !empty($order[$key]) ? $order[$key] : $ordering;
                         if (substr($file_details['name'], 0, 4) == 'http') {
                             if (is_null($this->_images)) {
                                 $csvilog->AddStats('incorrect', 'COM_CSVI_EZREALTY_NOSUPPORT_URL');
                             } else {
                                 // External images are supported now but needs to be stored with separate data
                                 if (substr($file_details['output_path'], -1) == '/') {
                                     $data['path'] = substr($file_details['output_path'], 0, -1);
                                 } else {
                                     $data['path'] = $file_details['output_path'];
                                 }
                             }
                         } else {
                             $this->{$image} = $file_details['output_name'];
                             // Create the thumbnail
                             if ($template->get('thumb_create', 'image')) {
                                 $imagehelper->createThumbnail($file_details['output_path'] . $this->{$image}, $template->get('file_location_property_images', 'path') . 'th/', $this->{$image});
                             }
                         }
                         // Store the property image relation
                         $this->_images->bind($data);
                         if (!$this->_images->check()) {
                             if ($this->_images->store()) {
                                 $csvilog->addDebug('COM_CSVI_STORE_PROPERTY_IMAGE', true);
                                 $ordering++;
                                 $this->_images->reset();
                             }
                         } else {
                             $csvilog->addDebug('Property image relation already exists');
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Process media files
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		4.0
  */
 private function _processMedia()
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     $csvilog = $jinput->get('csvilog', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->file_url) || $template->get('auto_generate_image_name', 'image', false)) {
             // Image handling
             $imagehelper = new ImageHelper();
             // Get the image path
             $imgpath = $template->get('file_location_product_images', 'path');
             if ($template->get('auto_generate_image_name', 'image')) {
                 $this->_createImageName();
             }
             // Verify the original image
             if ($imagehelper->isRemote($this->file_url)) {
                 $original = $this->file_url;
                 $remote = true;
                 $full_path = $imgpath;
             } else {
                 $remote = false;
                 // Check if the image contains the image path
                 $dirname = dirname($this->file_url);
                 if (strpos($imgpath, $dirname) !== false) {
                     $image = basename($this->file_url);
                 }
                 $original = $imgpath . $this->file_url;
                 $remote = false;
                 // Get subfolders
                 $path_parts = pathinfo($original);
                 $full_path = $path_parts['dirname'] . '/';
             }
             // Generate image names
             if ($template->get('auto_generate_image_name', 'image')) {
                 $file_details = $imagehelper->ProcessImage($original, $full_path, $this->product_full_image_output);
             } else {
                 $file_details = $imagehelper->ProcessImage($original, $full_path);
             }
             // Process the file details
             if ($file_details['exists'] && $file_details['isimage']) {
                 // Check if the image is an external image
                 if (substr($file_details['name'], 0, 4) == 'http') {
                     $csvilog->AddStats('incorrect', 'COM_CSVI_VM_NOSUPPORT_URL');
                 } else {
                     $media = array();
                     $media['virtuemart_vendor_id'] = $this->virtuemart_vendor_id;
                     $media['file_title'] = $this->file_title ? $this->file_title : $this->file_url;
                     $media['file_description'] = $this->file_description;
                     $media['file_meta'] = $this->file_meta;
                     $media['file_mimetype'] = $file_details['mime_type'];
                     $media['file_type'] = 'product';
                     $media['file_is_product_image'] = 1;
                     $media['file_is_downloadable'] = 0;
                     $media['file_is_forSale'] = 0;
                     $media['file_url'] = empty($file_details['output_path']) ? $file_details['output_name'] : $file_details['output_path'] . $file_details['output_name'];
                     // Create the thumbnail
                     if ($template->get('thumb_create', 'image')) {
                         // Get the subfolder structure
                         $thumb_path = str_ireplace($imgpath, '', $full_path);
                         if (empty($this->file_url_thumb)) {
                             $this->file_url_thumb = 'resized/' . $thumb_path . basename($media['file_url']);
                         }
                         if ($remote) {
                             $original = $this->file_url;
                         } else {
                             $original = $media['file_url'];
                         }
                         $media['file_url_thumb'] = $imagehelper->createThumbnail($original, $imgpath, $this->file_url_thumb);
                     } else {
                         $media['file_url_thumb'] = empty($this->file_url_thumb) ? $media['file_url'] : $this->file_url_thumb;
                         if (substr($media['file_url_thumb'], 0, 4) == 'http') {
                             $csvilog->addDebug(JText::sprintf('COM_CSVI_RESET_THUMB_NOHTTP', $media['file_url_thumb']));
                             $media['file_url_thumb'] = '';
                         }
                     }
                     // Bind the media data
                     $this->_medias->bind($media);
                     // Check if the media image already exists
                     $this->_medias->check();
                     // Store the media data
                     if ($this->_medias->store()) {
                         // Store the product image relation
                         $data = array();
                         $data['virtuemart_product_id'] = $this->virtuemart_product_id;
                         $data['virtuemart_media_id'] = $this->_medias->virtuemart_media_id;
                         $this->_product_medias->bind($data);
                         if (!$this->_product_medias->check()) {
                             $this->_product_medias->store();
                         }
                     }
                 }
             }
         }
     }
 }
Example #7
0
 /**
  * Process media files
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		private
  * @param
  * @return
  * @since 		5.8
  */
 private function _processMedia()
 {
     $jinput = JFactory::getApplication()->input;
     $template = $jinput->get('template', null, null);
     $csvilog = $jinput->get('csvilog', null, null);
     // Check if any image handling needs to be done
     if ($template->get('process_image', 'image', false)) {
         if (!is_null($this->fname)) {
             $max_width = $template->get('resize_max_width', 'image', 1024);
             $max_height = $template->get('resize_max_height', 'image', 768);
             // Image handling
             $imagehelper = new ImageHelper();
             $image = trim($this->fname);
             if (!empty($image)) {
                 // Verify the original image
                 if ($imagehelper->isRemote($image)) {
                     $original = $image;
                     $remote = true;
                     $full_path = $template->get('file_location_property_images', 'path');
                 } else {
                     $original = $template->get('file_location_property_images', 'path') . $image;
                     $remote = false;
                     // Get subfolders
                     $path_parts = pathinfo($original);
                     $full_path = $path_parts['dirname'] . '/';
                 }
                 // Generate image names
                 $file_details = $imagehelper->ProcessImage($original, $full_path);
                 // Process the file details
                 if ($file_details['exists'] && $file_details['isimage']) {
                     // Check if the image is an external image
                     $title = isset($this->title) ? $this->title : $file_details['output_name'];
                     $data = array();
                     $data['propid'] = $this->propid;
                     $data['fname'] = $file_details['output_name'];
                     $data['title'] = $title;
                     $data['description'] = $this->description;
                     $data['ordering'] = $this->ordering;
                     if (substr($file_details['name'], 0, 4) == 'http') {
                         if (is_null($this->_images)) {
                             $csvilog->AddStats('incorrect', 'COM_CSVI_EZREALTY_NOSUPPORT_URL');
                         } else {
                             // External images are supported now but needs to be stored with separate data
                             if (substr($file_details['output_path'], -1) == '/') {
                                 $data['path'] = substr($file_details['output_path'], 0, -1);
                             } else {
                                 $data['path'] = $file_details['output_path'];
                             }
                         }
                     } else {
                         $this->fname = $file_details['output_name'];
                         // Create the thumbnail
                         if ($template->get('thumb_create', 'image')) {
                             $imagehelper->createThumbnail($file_details['output_path'] . $this->fname, $template->get('file_location_property_images', 'path') . 'th/', $this->fname);
                         }
                     }
                 }
             }
         }
     }
 }