public function insertUpdateDocument($data, $isInsert = true) { $db = JFactory::getDbo(); $iconDir = JPATH_ROOT . '/' . JUDownloadFrontHelper::getDirectory('document_icon_directory', 'media/com_judownload/images/document/'); $originalDir = $iconDir . 'original/'; $newMainCatId = $data['main_cat']; $gallery = $data['gallery']; $files = $data['files']; $fieldsData = $data['fieldsData']; $relatedDocs = $data['related_docs']; $data = $data['data']; $messages = array(); if (!$isInsert) { $docObj = JUDownloadHelper::getDocumentById($data['id']); if ($docObj->cat_id != $newMainCatId) { $oldFieldGroup = JUDownloadHelper::getCategoryById($docObj->cat_id); $newFieldGroup = JUDownloadHelper::getCategoryById($newMainCatId); if ($oldFieldGroup->fieldgroup_id != $newFieldGroup->fieldgroup_id) { $query = $db->getQuery(true); $query->select("field.*"); $query->from("#__judownload_fields AS field"); $query->select("plg.folder"); $query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id"); $query->join("", "#__judownload_categories AS c ON (c.fieldgroup_id = field.group_id AND field.group_id != 1)"); $query->join("", "#__judownload_documents_xref AS dxref ON (dxref.cat_id = c.id AND dxref.main = 1)"); $query->join("", "#__judownload_documents AS d ON dxref.doc_id = d.id"); $query->where("d.id = " . $data['id']); $query->group('field.id'); $query->order('field.ordering'); $db->setQuery($query); $fields = $db->loadObjectList(); foreach ($fields as $field) { $fieldObj = JUDownloadFrontHelperField::getField($field, $data['id']); $fieldObj->onDelete(); } } } } $iconPath = ''; $iconFieldId = $this->field_name_id_array['icon']; if (!empty($data['icon'])) { $iconPath = $data['icon']; unset($data['icon']); } if (!empty($fieldsData[$iconFieldId])) { $iconPath = $fieldsData[$iconFieldId]; unset($fieldsData[$iconFieldId]); } $table = JTable::getInstance("Document", "JUDownloadTable"); if (!$table->bind($data) || !$table->check() || !$table->store()) { return array('doc_id' => 0, 'messages' => $table->getErrors()); } $docId = $table->id; $categoriesField = new JUDownloadFieldCore_categories(null, $docId); $categoriesField->is_new_doc = $isInsert; $result = $categoriesField->storeValue($fieldsData[$this->field_name_id_array['cat_id']]); if (!$result) { $table->delete($docId); return array('doc_id' => 0, 'messages' => $db->getErrorMsg()); } $query = $db->getQuery(true); $query->select("field.*"); $query->from("#__judownload_fields AS field"); $query->select("plg.folder"); $query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id"); $query->join("", "#__judownload_categories AS c ON (c.fieldgroup_id = field.group_id OR field.group_id = 1)"); $query->join("", "#__judownload_documents_xref AS dxref ON (dxref.cat_id = c.id AND dxref.main = 1)"); $query->join("", "#__judownload_documents AS d ON dxref.doc_id = d.id"); $query->where("d.id = {$docId}"); $query->where("field.field_name != 'id'"); $query->where("field.field_name != 'cat_id'"); $query->group('field.id'); $query->order('ordering ASC'); $db->setQuery($query); $fields = $db->loadObjectList(); $docObj = JUDownloadHelper::getDocumentById($docId); foreach ($fields as $field) { if (isset($fieldsData[$field->id])) { $fieldObj = JUDownloadFrontHelperField::getField($field, $docObj); $fieldObj->fields_data = $fieldsData; $fieldValue = $fieldsData[$field->id]; $fieldObj->is_new_doc = $isInsert; $fieldValue = $fieldObj->onImportDocument($fieldValue); $fieldObj->storeValue($fieldValue); } } if ($iconPath) { $iconPath = JUDownloadHelper::getPhysicalPath($iconPath); if (!$iconPath) { $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $iconPath); } else { if ($data['id'] > 0) { if ($table->icon) { if (JFile::exists($iconDir . $table->icon)) { JFile::delete($iconDir . $table->icon); JFile::delete($originalDir . $table->icon); } } } $iconName = basename($iconPath); $iconName = $docId . "_" . JUDownloadHelper::fileNameFilter($iconName); if (JFile::copy($iconPath, $originalDir . $iconName) && JUDownloadHelper::renderImages($originalDir . $iconName, $iconDir . $iconName, 'document_icon', true, null, $data['id'])) { $table->icon = $iconName; $table->store(); } } } $imageTable = JTable::getInstance("Image", "JUDownloadTable"); if (!empty($gallery)) { $dir_document_ori = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/") . $docId . "/"; $dir_document_small = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/") . $docId . "/"; $dir_document_big = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_big_image_directory", "media/com_judownload/images/gallery/big/") . $docId . "/"; if (!JFolder::exists($dir_document_ori)) { $file_index = $dir_document_ori . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($dir_document_small)) { $file_index = $dir_document_small . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($dir_document_big)) { $file_index = $dir_document_big . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } $image_ordering = 1; $date = JFactory::getDate(); foreach ($gallery as $imagePath) { $imagePath = JUDownloadHelper::getPhysicalPath($imagePath); if (!$imagePath) { $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $imagePath); continue; } $imageName = basename($imagePath); $imageName = JUDownloadHelper::generateImageNameByDocument($docId, $imageName); if (JFile::copy($imagePath, $dir_document_ori . $imageName) && JUDownloadHelper::renderImages($dir_document_ori . $imageName, $dir_document_small . $imageName, 'document_small', true, null, $data['id']) && JUDownloadHelper::renderImages($dir_document_ori . $imageName, $dir_document_big . $imageName, 'document_big', true, null, $data['id'])) { $imageObj = new stdClass(); $imageObj->id = 0; $imageObj->file_name = $imageName; $imageObj->doc_id = $docId; $imageObj->ordering = $image_ordering; $imageObj->created = $date->toSql(); $imageObj->published = 1; if (!$imageTable->bind($imageObj) || !$imageTable->check() || !$imageTable->store()) { $messages[] = implode(' | ', $imageTable->getErrors()); JFile::delete($dir_document_ori . $imageName); JFile::delete($dir_document_small . $imageName); JFile::delete($dir_document_big . $imageName); } else { $image_ordering++; } } else { $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_CAN_NOT_COPY_FILE_FROM_S_TO_S', $imagePath, $dir_document_ori . $imageName); } } } $fileTable = JTable::getInstance("File", "JUDownloadTable"); if (!empty($files)) { $file_directory = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/"); if (!JFolder::exists($file_directory . $docId . "/")) { $file_index = $file_directory . $docId . "/index.html"; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } $file_ordering = 1; foreach ($files as $filePath) { $filePath = JUDownloadHelper::getPhysicalPath($filePath); if (!$filePath) { $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $filePath); continue; } $query = $db->getQuery(true); $query->select('COUNT(*)')->from('#__judownload_files')->where('doc_id = ' . $docId)->where('`rename` = ' . $db->quote(basename($filePath))); $db->setQuery($query); $count = $db->loadResult(); if ($count) { $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_EXISTED_FILE_S', $filePath); continue; } $fileObject = array(); $fileObject['id'] = 0; $fileObject['doc_id'] = $docId; $fileObject['ordering'] = $file_ordering; $fileObject['rename'] = basename($filePath); $fileObject['file_name'] = md5($fileObject['rename'] . JUDownloadHelper::generateRandomString(10)) . "." . JFile::getExt($fileObject['rename']); $fileObject['published'] = 1; $this->addFileInfo($fileObject, $filePath, $file_directory); $dest = $file_directory . $docId . "/" . $fileObject['file_name']; if ($fileTable->bind($fileObject) && $fileTable->check() && $fileTable->store()) { if (!JFile::copy($filePath, $dest)) { $fileTable->delete($fileTable->id); $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_CAN_NOT_COPY_FILE_FROM_S_TO_S', $filePath, $dest); } $file_ordering++; } else { $messages[] = implode(' | ', $fileTable->getErrors()); } } } if (!empty($relatedDocs)) { $ordering = 1; foreach ($relatedDocs as $relatedDocId) { $document = JUDownloadHelper::getDocumentById($relatedDocId); if ($document) { $relatedDocObj = new stdClass(); $relatedDocObj->id = 0; $relatedDocObj->doc_id = $docId; $relatedDocObj->doc_id_related = $relatedDocId; $relatedDocObj->ordering = $ordering; $query = $db->getQuery(true); $query->select('id')->from('#__judownload_documents_relations')->where('doc_id = ' . $docId)->where('doc_id_related = ' . $relatedDocId); $db->setQuery($query); $existedId = $db->loadResult(); if ($existedId) { $relatedDocObj->id = $existedId; $db->updateObject('#__judownload_documents_relations', $relatedDocObj, 'id'); } else { $db->insertObject('#__judownload_documents_relations', $relatedDocObj); } $relationId = $db->insertid(); if ($relationId > 0) { $ordering++; } else { $messages[] = $db->getErrorMsg(); } } else { $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_INVALID_RELATED_DOCUMENT_N', $relatedDocId); } } } return array('doc_id' => $docId, 'messages' => $messages); }
public function saveCategoryImage($pk, $table, &$data) { $app = JFactory::getApplication(); $jInput = $app->input; if ($pk > 0) { if ($jInput->post->getInt('remove_jform_images_intro_image', 0) == 1 || $jInput->post->getInt('remove_jform_images_detail_image', 0) == 1 && $jInput->post->getInt('use_detail_image', 0) == 1) { $intro_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $data['images']['intro_image']; $ori_intro_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $data['images']['intro_image']; $data['images']['intro_image'] = ''; $data['images']['intro_image_alt'] = ''; $data['images']['intro_image_caption'] = ''; JFile::delete($ori_intro_image_dir); JFile::delete($intro_image_dir); } if ($jInput->post->getInt('remove_jform_images_detail_image', 0) == 1) { $full_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . $data['images']['detail_image']; $ori_full_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . "original/" . $data['images']['detail_image']; $data['images']['detail_image'] = ''; $data['images']['detail_image_alt'] = ''; $data['images']['detail_image_caption'] = ''; JFile::delete($full_image_dir); JFile::delete($ori_full_image_dir); } } $mime_types = array("image/jpeg", "image/pjpeg", "image/png", "image/gif", "image/bmp", "image/x-windows-bmp"); $num_files_failed_mime_type = 0; $images = $app->input->files->get('images', array()); $old_ori_intro_image_path = isset($data['images']['intro_image']) && $data['images']['intro_image'] ? JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $data['images']['intro_image'] : ''; $old_intro_image_path = $old_ori_intro_image_path ? JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $data['images']['intro_image'] : ''; $old_ori_detail_image_path = isset($data['images']['detail_image']) && $data['images']['detail_image'] ? JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . 'original/' . $data['images']['detail_image'] : ''; $old_detail_image_path = $old_ori_detail_image_path ? JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . $data['images']['detail_image'] : ''; foreach ($images as $key => $image) { if ($image['name']) { if (!in_array($image['type'], $mime_types)) { $num_files_failed_mime_type++; continue; } $info = pathinfo($image['name']); $replace = array('id' => $table->id, 'document' => '', 'category' => $table->title, 'image_name' => $info['filename']); $image['name'] = JUDownloadHelper::parseImageNameByTags($replace, 'category', $table->id, null) . '.' . $info['extension']; if ($key == 'intro' && $app->input->post->get('use_detail_image', 0) != 1) { $new_ori_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $image['name']; $new_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $image['name']; if (!JFile::upload($image['tmp_name'], JPATH_ROOT . "/" . $new_ori_image_path) || !JUDownloadHelper::renderImages(JPATH_ROOT . "/" . $new_ori_image_path, JPATH_ROOT . "/" . $new_image_path, "category_intro", true, $table->id)) { unset($images['intro']); } else { $delete_old_intro_image = $data['images']['intro_image'] && $data['images']['intro_image'] !== $image['name'] ? true : false; $data['images']['intro_image'] = $image['name']; } if ($delete_old_intro_image) { if ($old_intro_image_path && JFile::exists(JPATH_ROOT . "/" . $old_intro_image_path)) { JFile::delete(JPATH_ROOT . "/" . $old_ori_intro_image_path); JFile::delete(JPATH_ROOT . "/" . $old_intro_image_path); } } } if ($key == 'detail') { $new_ori_image_path = JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . 'original/' . $image['name']; $new_image_path = JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . $image['name']; if (!JFile::upload($image['tmp_name'], JPATH_ROOT . "/" . $new_ori_image_path) || !JUDownloadHelper::renderImages(JPATH_ROOT . "/" . $new_ori_image_path, JPATH_ROOT . "/" . $new_image_path, "category_detail", true, $table->id)) { unset($images['detail']); } else { if ($data['images']['detail_image'] && $data['images']['detail_image'] !== $image['name']) { if ($old_detail_image_path && JFile::exists(JPATH_ROOT . "/" . $old_detail_image_path)) { JFile::delete(JPATH_ROOT . "/" . $old_ori_detail_image_path); JFile::delete(JPATH_ROOT . "/" . $old_detail_image_path); } } $data['images']['detail_image'] = $image['name']; } } } } if ($num_files_failed_mime_type) { JError::raise(E_NOTICE, 500, JText::plural('COM_JUDOWNLOAD_N_IMAGES_ARE_NOT_VALID_MIMETYPE', $num_files_failed_mime_type, implode(",", $mime_types))); } if ($app->input->post->get('use_detail_image', 0) == 1 && $data['images']['detail_image']) { $old_ori_detail_image_path = JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . 'original/' . $data['images']['detail_image']; $new_ori_intro_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $data['images']['detail_image']; $new_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $data['images']['detail_image']; if (JFile::copy(JPATH_ROOT . "/" . $old_ori_detail_image_path, JPATH_ROOT . "/" . $new_ori_intro_image_path) && JUDownloadHelper::renderImages(JPATH_ROOT . "/" . $new_ori_intro_image_path, JPATH_ROOT . "/" . $new_image_path, 'category_intro', true, $table->id)) { if ($data['images']['intro_image'] && $data['images']['intro_image'] !== $data['images']['detail_image']) { if (JFile::exists(JPATH_ROOT . "/" . $old_ori_intro_image_path)) { JFile::delete(JPATH_ROOT . "/" . $old_ori_intro_image_path); } if (JFile::exists(JPATH_ROOT . "/" . $old_intro_image_path)) { JFile::delete(JPATH_ROOT . "/" . $old_intro_image_path); } } $data['images']['intro_image'] = $data['images']['detail_image']; } } if (!empty($data['images'])) { $registry = new JRegistry(); $registry->loadArray($data['images']); $table->images = (string) $registry; $table->store(); } }
public function resizeCollectionIcons($limitStart, $limit) { $db = JFactory::getDbo(); $query = "SELECT icon FROM #__judownload_collections WHERE icon != ''"; $db->setQuery($query, $limitStart, $limit); $images = $db->loadObjectList(); if (count($images)) { $collection_icon_path = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("collection_icon_directory", "media/com_judownload/images/collection/"); foreach ($images as $image) { $ori_image_path = $collection_icon_path . "original/" . $image->icon; if (JFile::exists($ori_image_path)) { $image_path = $collection_icon_path . $image->icon; if (JFile::exists($image_path)) { JFile::delete($image_path); } JUDownloadHelper::renderImages($ori_image_path, $image_path, 'collection'); } } } }
public function storeValue($value, $type = 'default', $inputData = null) { if ($type == 'migrate') { $iconKeyArray = $this->getId() . "_icon"; $icon = $inputData[$iconKeyArray]; $mime_types = array("image/jpeg", "image/pjpeg", "image/png", "image/gif", "image/bmp", "image/x-windows-bmp"); if ($icon['name']) { if (in_array($icon['type'], $mime_types)) { $iconDirectory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/"); $icon_file_name = $this->doc_id . "_" . JUDownloadHelper::fileNameFilter($icon['name']); if (JFile::copy($icon['tmp_name'], $iconDirectory . "original/" . $icon_file_name) && JUDownloadHelper::renderImages($iconDirectory . "original/" . $icon_file_name, $iconDirectory . $icon_file_name, 'doc_icon', true, null, $this->doc_id) ) { $value = $icon_file_name; parent::storeValue($value, $type, $inputData); } } } elseif ($value == "" || strpos($value, 'default/') === 0) { if ($this->doc && $this->doc->icon && strpos($this->doc->icon, 'default/') === false) { $this->removeIcon(); } parent::storeValue($value, $type, $inputData); } } else { $app = JFactory::getApplication(); $icon = $app->input->files->get($this->getId() . "_icon"); $mime_types = array("image/jpeg", "image/pjpeg", "image/png", "image/gif", "image/bmp", "image/x-windows-bmp"); if ($icon['name']) { if (in_array($icon['type'], $mime_types)) { $this->removeIcon(); $iconDirectory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/"); $icon_file_name = $this->doc_id . "_" . JUDownloadHelper::fileNameFilter($icon['name']); if (JFile::upload($icon['tmp_name'], $iconDirectory . "original/" . $icon_file_name) && JUDownloadHelper::renderImages($iconDirectory . "original/" . $icon_file_name, $iconDirectory . $icon_file_name, 'doc_icon', true, null, $this->doc_id) ) { $value = $icon_file_name; parent::storeValue($value, $type, $inputData); } } else { JError::raise( E_NOTICE, 500, JText::sprintf('COM_JUDOWNLOAD_ICON_IS_NOT_VALID_MIME_TYPE') ); } } elseif ($value == "" || strpos($value, 'default/') === 0) { if ($this->doc && $this->doc->icon && strpos($this->doc->icon, 'default/') === false) { $this->removeIcon(); } parent::storeValue($value, $type, $inputData); } } }
public function storeValue($value, $type = 'default', $inputData = null) { $gallery = $value; $date = JFactory::getDate(); $image_ordering = 0; $configDocumentOriginalImageDirectory = JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/"); $configDocumentSmallImageDirectory = JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/"); $configDocumentBigImageDirectory = JUDownloadFrontHelper::getDirectory("document_big_image_directory", "media/com_judownload/images/gallery/big/"); $document_original_image_directory = JPATH_ROOT . "/" . $configDocumentOriginalImageDirectory . $this->doc_id . "/"; $document_small_image_directory = JPATH_ROOT . "/" . $configDocumentSmallImageDirectory . $this->doc_id . "/"; $document_big_image_directory = JPATH_ROOT . "/" . $configDocumentBigImageDirectory . $this->doc_id . "/"; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables', 'JUDownloadTable'); $imageTable = JTable::getInstance('Image', 'JUDownloadTable'); 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($document_original_image_directory . $image['file_name']); JFile::delete($document_small_image_directory . $image['file_name']); JFile::delete($document_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 ($type == 'migrate') { $gallery['new'] = $inputData['new']; if (!empty($gallery['new'])) { if (!JFolder::exists($document_original_image_directory)) { $file_index = $document_original_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($document_small_image_directory)) { $file_index = $document_small_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($document_big_image_directory)) { $file_index = $document_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 = JUDownloadHelper::generateImageNameByDocument($this->doc_id, $image['name']); if (!JFile::copy($image['tmp_name'], $document_original_image_directory . $img_file_name) || !JUDownloadHelper::renderImages($document_original_image_directory . $img_file_name, $document_small_image_directory . $img_file_name, 'document_small', true, null, $this->doc_id) || !JUDownloadHelper::renderImages($document_original_image_directory . $img_file_name, $document_big_image_directory . $img_file_name, 'document_big', true, null, $this->doc_id) ) { continue; } $imageTable->reset(); $dataImage = array('id' => 0, 'file_name' => $img_file_name, 'doc_id' => $this->doc_id, 'published' => 1, 'ordering' => ++$image_ordering, 'created' => $date->toSql()); $imageTable->bind($dataImage); $imageTable->check(); $imageTable->store(); $countNewImage++; } } } else { if (!empty($gallery['new'])) { if (!JFolder::exists($document_original_image_directory)) { $file_index = $document_original_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($document_small_image_directory)) { $file_index = $document_small_image_directory . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!JFolder::exists($document_big_image_directory)) { $file_index = $document_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 = JUDownloadHelper::generateImageNameByDocument($this->doc_id, $image['name']); if (!JFile::move($image['tmp_name'], $document_original_image_directory . $img_file_name) || !JUDownloadHelper::renderImages($document_original_image_directory . $img_file_name, $document_small_image_directory . $img_file_name, 'document_small', true, null, $this->doc_id) || !JUDownloadHelper::renderImages($document_original_image_directory . $img_file_name, $document_big_image_directory . $img_file_name, 'document_big', true, null, $this->doc_id) ) { continue; } $imageTable->reset(); $dataImage = array('id' => 0, 'file_name' => $img_file_name, 'doc_id' => $this->doc_id, 'published' => 1, 'ordering' => ++$image_ordering, 'created' => $date->toSql()); $imageTable->bind($dataImage); $imageTable->check(); $imageTable->store(); $countNewImage++; } } } }