Пример #1
0
 /**
  * Process each record and store it in the database
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		3.0
  */
 public function getProcessRecord()
 {
     $db = JFactory::getDbo();
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $template = $jinput->get('template', null, null);
     // Process the image
     $this->_processMedia();
     // Set some basic values
     if (!isset($this->modified_on)) {
         $this->_medias->modified_on = $this->date->toSql();
         $this->_medias->modified_by = $this->user->id;
     }
     // Find the media ID
     $this->_medias->file_url = $this->file_url;
     $this->_medias->check();
     $this->virtuemart_media_id = $this->_medias->virtuemart_media_id;
     // Do we need to delete a media file?
     if ($this->media_delete == 'Y') {
         $this->_deleteMedia();
     } else {
         // Check if the media exists
         if (empty($this->virtuemart_media_id)) {
             $this->_medias->created_on = $this->date->toMySQL();
             $this->_medias->created_by = $this->user->id;
         }
         // Bind all the data
         $this->_medias->bind($this);
         // Store the data
         if ($this->_medias->store()) {
             if ($this->queryResult() == 'UPDATE') {
                 $csvilog->AddStats('updated', JText::_('COM_CSVI_UPDATE_MEDIAFILE'));
             } else {
                 $csvilog->AddStats('added', JText::_('COM_CSVI_ADD_MEDIAFILE'));
             }
             // Watermark image if needed
             $imagehelper = new ImageHelper();
             if ($template->get('full_watermark', 'image')) {
                 $imagehelper->addWatermark(JPATH_SITE . '/' . $this->_medias->file_url);
             }
             // Add a link to the product if the SKU is specified
             if (isset($this->product_sku)) {
                 $this->_product_medias->virtuemart_media_id = $this->_medias->virtuemart_media_id;
                 $this->_product_medias->virtuemart_product_id = $this->helper->getProductId();
                 if (!$this->_product_medias->check()) {
                     if ($this->_product_medias->store()) {
                         if ($this->queryResult() == 'UPDATE') {
                             $csvilog->AddStats('updated', JText::_('COM_CSVI_UPDATE_MEDIAXREF'));
                         } else {
                             $csvilog->AddStats('added', JText::_('COM_CSVI_ADD_MEDIAXREF'));
                         }
                     }
                 }
             }
         } else {
             $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_MEDIAFILE_NOT_ADDED', $this->_medias->getError()));
         }
         // Store the debug message
         $csvilog->addDebug(JText::_('COM_CSVI_MEDIAFILE_QUERY'), true);
     }
     // Clean the tables
     $this->cleanTables();
 }
 /**
  * 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
     }
 }
Пример #3
0
 /**
  * Process each record and store it in the database
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see
  * @access 		public
  * @param
  * @return
  * @since 		5.8
  */
 public function getProcessRecord()
 {
     $db = JFactory::getDbo();
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $template = $jinput->get('template', null, null);
     // Find the media ID, we only use the image name
     $this->_images->fname = basename($this->fname);
     $this->_images->check();
     $this->id = $this->_images->id;
     // Do we need to delete a media file?
     if ($this->image_delete == 'Y') {
         if ($this->id) {
             $this->_deleteImage();
         } else {
             $csvilog->AddStats('information', JText::_('COM_CSVI_NO_IMAGE_ID'));
         }
     } else {
         // Find the property ID
         $based_on = $template->get('update_based_on', 'property', 'id');
         if ($based_on != 'id') {
             // Find the property ID
             $db = JFactory::getDbo();
             $propid = $this->propid;
             $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__ezrealty'))->where($db->qn($based_on) . ' = ' . $db->q($propid));
             $db->setQuery($query);
             $this->propid = $db->loadResult();
             if (!$this->propid) {
                 $csvilog->AddStats('error', JText::sprintf('COM_CSVI_CANNOT_FIND_PROPERTY', $propid));
                 return false;
             }
         }
         // Process the image
         $this->_processMedia();
         // Bind all the data
         $this->_images->bind($this);
         // Store the data
         if ($this->_images->store()) {
             if ($this->queryResult() == 'UPDATE') {
                 $csvilog->AddStats('updated', JText::_('COM_CSVI_UPDATE_IMAGEFILE'));
             } else {
                 $csvilog->AddStats('added', JText::_('COM_CSVI_ADD_IMAGEFILE'));
             }
             // Watermark image if needed
             $imagehelper = new ImageHelper();
             if ($template->get('full_watermark', 'image')) {
                 $imagehelper->addWatermark(JPATH_SITE . '/' . $this->_images->fname);
             }
         } else {
             $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_MEDIAFILE_NOT_ADDED', $this->_images->getError()));
         }
         // Store the debug message
         $csvilog->addDebug(JText::_('COM_CSVI_IMAGEFILE_QUERY'), true);
     }
     // Clean the tables
     $this->cleanTables();
 }