/** * Takes an image file, moves the file and adds database entry * @param the verified REAL name of the local file including path * @param name of file according to user/browser or just the name excluding path * @param desired category * @param title of image, if empty will be created from $imgName * @param description of image, if empty will remain empty * @return returns true if successfull otherwise returns an ImageUploadError */ function importImage($imgTmpName, $imgName, $imgCat, $imgTitle = '', $imgDesc = '') { global $rsgConfig; $my =& JFactory::getUser(); $database =& JFactory::getDBO(); //First move uploaded file to original directory $destination = fileUtils::move_uploadedFile_to_orignalDir($imgTmpName, $imgName); if (is_a($destination, 'imageUploadError')) { return $destination; } $parts = pathinfo($destination); // If IPTC parameter in config is true and the user left either the image title // or description empty in the upload step we want to get that IPTC data. if ($rsgConfig->get('useIPTCinformation')) { if ($imgTitle == '' or $imgDesc == '') { getimagesize($destination, $imageInfo); if (isset($imageInfo['APP13'])) { $iptc = iptcparse($imageInfo['APP13']); //Get Iptc.Caption for the description (null if it does not exist) $IPTCcaption = $iptc["2#120"][0]; //Get Iptc.ObjectName for the title $IPTCtitle = $iptc["2#005"][0]; //If the field (description or title) in the import step is emtpy, and we have IPTC info, then use the IPTC info: if ($imgDesc == '' and !is_null($IPTCcaption)) { $imgDesc = $IPTCcaption; } if ($imgTitle == '' and !is_null($IPTCtitle)) { $imgTitle = $IPTCtitle; } } } } // fill $imgTitle if empty if ($imgTitle == '') { $imgTitle = substr($parts['basename'], 0, -(strlen($parts['extension']) + ($parts['extension'] == '' ? 0 : 1))); } // replace names with the new name we will actually use $parts = pathinfo($destination); $newName = $parts['basename']; $imgName = $parts['basename']; //Get details of the original image. $width = getimagesize($destination); if (!$width) { imgUtils::deleteImage($newName); return new imageUploadError($destination, JText::_('NOT AN IMAGE OR CANNOT READ') . " " . $destination); } else { //the actual image width and height and its max $height = $width[1]; $width = $width[0]; if ($height > $width) { $maxSideImage = $height; } else { $maxSideImage = $width; } } //Destination becomes original image, just for readability $original_image = $destination; // if original is wider or higher than display size, create a display image if ($maxSideImage > $rsgConfig->get('image_width')) { $result = imgUtils::makeDisplayImage($original_image, $newName, $rsgConfig->get('image_width')); if (!$result) { imgUtils::deleteImage($newName); return new imageUploadError($imgName, JText::_('ERROR CREATING DISPLAY IMAGE') . ": " . $newName); } } else { $result = imgUtils::makeDisplayImage($original_image, $newName, $maxSideImage); if (!$result) { imgUtils::deleteImage($newName); return new imageUploadError($imgName, JText::_('ERROR CREATING DISPLAY IMAGE') . ": " . $newName); } } // if original is wider or higher than thumb, create a thumb image if ($maxSideImage > $rsgConfig->get('thumb_width')) { $result = imgUtils::makeThumbImage($original_image, $newName); if (!$result) { imgUtils::deleteImage($newName); return new imageUploadError($imgName, JText::_('ERROR CREATING THUMB IMAGE') . ": " . $newName); } } // determine ordering $database->setQuery("SELECT COUNT(1) FROM #__rsgallery2_files WHERE gallery_id = '{$imgCat}'"); $ordering = $database->loadResult() + 1; //Store image details in database $imgAlias = $database->getEscaped(JFilterOutput::stringURLSafe($imgTitle)); $imgDesc = $database->getEscaped($imgDesc); $imgTitle = $database->getEscaped($imgTitle); $database->setQuery("INSERT INTO #__rsgallery2_files" . " (title, name, descr, gallery_id, date, ordering, userid, alias) VALUES" . " ('{$imgTitle}', '{$newName}', '{$imgDesc}', '{$imgCat}', now(), '{$ordering}', '{$my->id}', '{$imgAlias}')"); if (!$database->query()) { imgUtils::deleteImage($newName); return new imageUploadError($imgName, $database->stderr(true)); } //check if original image needs to be kept, otherwise delete it. if (!$rsgConfig->get('keepOriginalImage')) { JFile::delete(imgUtils::getImgOriginal($newName, true)); } return true; }
/** * Used in the consolidate database function * Creates images based on an image id or an image name */ function regenerateImage() { global $mainframe; global $rsgConfig; $database =& JFactory::getDBO(); //Check if id or name is set if (isset($_REQUEST['id'])) { $id = rsgInstance::getInt('id', null); $name = galleryUtils::getFileNameFromId($id); } elseif (isset($_REQUEST['name'])) { $name = rsgInstance::getVar('name', null); } else { $mainframe->redirect("index2.php?option=com_rsgallery2&task=batchupload", JText::_('No fileinformation found. This should never happen!')); } //Just for readability of code $original = JPATH_ORIGINAL . '/' . $name; $display = JPATH_DISPLAY . '/' . imgUtils::getImgNameDisplay($name); $thumb = JPATH_THUMB . '/' . imgUtils::getImgNameThumb($name); if (file_exists($original)) { //Check if display image exists, if not make it. if (!file_exists($display)) { imgUtils::makeDisplayImage($original, NULL, $rsgConfig->get('image_width')); } if (!file_exists($thumb)) { imgUtils::makeThumbImage($original); } } else { if (file_exists($display)) { copy($display, $original); } if (!file_exists($thumb)) { imgUtils::makeThumbImage($display); } } }
/** * Copies original images from Pony Gallery to the RSGallery2 file structure * and then creates display and thumb images. * @param string full path to the original Pony Images * @return True id succesfull, false if not */ function copyImages($basedir, $prefix = "easy_") { global $rsgConfig; $database = JFactory::getDBO(); $sql = "SELECT * FROM #__easygallery"; $database->setQuery($sql); $result = $database->loadObjectList(); $i = 0; foreach ($result as $image) { $source = $basedir . "/" . $image->path; $filename = array_reverse(explode("/", $image->path)); $destination = JPATH_ORIGINAL . "/" . $prefix . $filename[0]; //First move image to original folder $newpath = fileUtils::move_uploadedFile_to_orignalDir($source, $destination); if ($newpath) { imgUtils::makeDisplayImage($newpath, '', $rsgConfig->get('image_width')); imgUtils::makeThumbImage($newpath); } else { $i++; } } if ($i > 0) { return false; } else { return true; } }