public function onSaveListing($value = '') { $gallery = $value; $date = JFactory::getDate(); $image_ordering = 0; $configListingOriginalImageDirectory = JUDirectoryFrontHelper::getDirectory("listing_original_image_directory", "media/com_judirectory/images/gallery/original/"); $configListingSmallImageDirectory = JUDirectoryFrontHelper::getDirectory("listing_small_image_directory", "media/com_judirectory/images/gallery/small/"); $configListingBigImageDirectory = JUDirectoryFrontHelper::getDirectory("listing_big_image_directory", "media/com_judirectory/images/gallery/big/"); $listing_original_image_directory = JPATH_ROOT . "/" . $configListingOriginalImageDirectory . $this->listing_id . "/"; $listing_small_image_directory = JPATH_ROOT . "/" . $configListingSmallImageDirectory . $this->listing_id . "/"; $listing_big_image_directory = JPATH_ROOT . "/" . $configListingBigImageDirectory . $this->listing_id . "/"; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables', 'JUDirectoryTable'); $imageTable = JTable::getInstance('Image', 'JUDirectoryTable'); if (!$this->is_new) { if (!empty($gallery['old'])) { foreach ($gallery['old'] as $image) { if ($imageTable->load($image['id'])) { if ($image['remove'] == 1) { if ($imageTable->delete()) { JFile::delete($listing_original_image_directory . $image['file_name']); JFile::delete($listing_small_image_directory . $image['file_name']); JFile::delete($listing_big_image_directory . $image['file_name']); } } else { $image_ordering++; $_image = array(); $_image['title'] = $image['title']; $_image['description'] = $image['description']; $_image['published'] = $image['published']; $_image['ordering'] = $image_ordering; $imageTable->bind($_image); $imageTable->check(); $imageTable->store(); } } } } } if (!empty($gallery['new'])) { if (!JFolder::exists($listing_original_image_directory)) { $file_index = $listing_original_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($listing_small_image_directory)) { $file_index = $listing_small_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($listing_big_image_directory)) { $file_index = $listing_big_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } $countNewImage = 0; foreach ($gallery['new'] as $image) { $img_file_name = JUDirectoryHelper::generateImageNameByListing($this->listing_id, $image['name']); if (!JFile::move($image['tmp_name'], $listing_original_image_directory . $img_file_name) || !JUDirectoryHelper::renderImages($listing_original_image_directory . $img_file_name, $listing_small_image_directory . $img_file_name, 'listing_small', true, null, $this->listing_id) || !JUDirectoryHelper::renderImages($listing_original_image_directory . $img_file_name, $listing_big_image_directory . $img_file_name, 'listing_big', true, null, $this->listing_id)) { continue; } $imageTable->reset(); $dataImage = array('id' => 0, 'file_name' => $img_file_name, 'listing_id' => $this->listing_id, 'published' => 1, 'ordering' => ++$image_ordering, 'created' => $date->toSql()); $imageTable->bind($dataImage); $imageTable->check(); $imageTable->store(); $countNewImage++; } } return null; }