Ejemplo n.º 1
0
 /**
  * Method to store an image
  *
  * @param   array $data   The data of the image to store, if null we will use the data of the current request
  * @param   array $files  Image files to upload, if null we will use the data of the current request
  * @param   array $params Additional parameters of the image, if null we will use the data of the current request
  * @return  int   The image ID on success, boolean false otherwise
  * @since   1.5.5
  */
 public function store($data = null, $files = null, $params = null)
 {
     $row = $this->getTable('joomgalleryimages');
     $validate = true;
     if (is_null($data)) {
         $data = JRequest::get('post', 2);
     } else {
         // No validation in case of e.g. 'editimage' view
         $validate = false;
     }
     if (is_null($params)) {
         $params = JRequest::getVar('params', array(), 'post', 'array');
     }
     // Check for validation errors
     if ($validate) {
         $form = $this->getForm($data);
         $data = $this->_validate($form, $data);
         if ($data === false) {
             return false;
         }
     } else {
         // Sanitize image description here because JForm didn't take care of it above
         if (isset($data['imgtext'])) {
             $data['imgtext'] = JComponentHelper::filterText($data['imgtext']);
         }
     }
     // Check whether it is a new image
     if ($id = intval($data['cid'])) {
         $isNew = false;
         // Read image from database
         $row->load($id);
         // Check whether we are allowed to edit it
         $asset = _JOOM_OPTION . '.image.' . $id;
         if (!$this->_user->authorise('core.edit', $asset) && (!$this->_user->authorise('core.edit.own', $asset) || !$row->owner || $row->owner != $this->_user->get('id'))) {
             $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NOT_ALLOWED_TO_EDIT_IMAGE'));
             return false;
         }
         // Read old category ID
         $catid_old = $row->catid;
     } else {
         $isNew = true;
     }
     // Bind the form fields to the image table
     if (!$row->bind($data)) {
         $this->setError($row->getError());
         return false;
     }
     // Additional parameters, if set
     if (count($params)) {
         // Build parameter INI string
         $txt = array();
         foreach ($params as $k => $v) {
             $txt[] = $k . '=' . $v;
         }
         $row->params = implode("\n", $txt);
     }
     // Bind the rules
     if (isset($data['rules'])) {
         $rules = new JAccessRules($data['rules']);
         $row->setRules($rules);
     }
     // Load category information for permission checks
     $query = $this->_db->getQuery(true)->select('cid, owner')->from(_JOOM_TABLE_CATEGORIES)->where('cid = ' . $row->catid);
     $this->_db->setQuery($query);
     $category = $this->_db->loadObject();
     if ($isNew) {
         // Check whether we are allowed to create the image in the selected category
         $asset = _JOOM_OPTION . '.category.' . $row->catid;
         if (!$this->_user->authorise('joom.upload', $asset) && (!$this->_user->authorise('joom.upload.inown', $asset) || !$category->owner || $category->owner != $this->_user->get('id'))) {
             $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NOT_ALLOWED_TO_CREATE_IMAGE'));
             return false;
         }
         // Approve image
         $row->approved = 1;
         // Set date of image
         $date = JFactory::getDate();
         $row->imgdate = $date->toSQL();
         // Make sure the record is valid
         if (!$row->check()) {
             $this->setError($row->getError());
             return false;
         }
         // Category path for destination category
         $catpath = JoomHelper::getCatPath($row->catid);
         // Source path for original and detail image
         $detail_catpath = JoomHelper::getCatPath($data['detail_catid']);
         // Source path for thumbnail
         $thumb_catpath = JoomHelper::getCatPath($data['thumb_catid']);
         // Make sure the record is valid
         if (!$row->check()) {
             $this->setError($row->getError());
             return false;
         }
         // Copy the image files, the row will be stored, too
         if (!$this->_newImage($row, $catpath, $detail_catpath, $thumb_catpath, $data['copy_original'])) {
             $this->setError(JText::_('COM_JOOMGALLERY_IMGMAN_MSG_ERROR_CREATING_NEW_IMAGES'));
             return false;
         }
         // Successfully stored new image
         $row->reorder('catid = ' . $row->catid);
         $this->_mainframe->triggerEvent('onContentAfterSave', array(_JOOM_OPTION . '.image', &$row, true));
         return $row->id;
     }
     // Get new image files
     if (is_null($files)) {
         $files = JRequest::getVar('files', '', 'files');
     }
     // Clear votes if 'clearvotes' is checked
     if (isset($data['clearvotes']) && $data['clearvotes']) {
         $row->imgvotes = 0;
         $row->imgvotesum = 0;
         // Delete votes for image
         $query = $this->_db->getQuery(true)->delete()->from(_JOOM_TABLE_VOTES)->where('picid = ' . $row->id);
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($row->getError());
             return false;
         }
     }
     // Clear hits if 'clearhits' is checked
     if (isset($data['clearhits']) && $data['clearhits']) {
         $row->hits = 0;
     }
     // Clear downloads if 'cleardownloads' is checked
     if (isset($data['cleardownloads']) && $data['cleardownloads']) {
         $row->downloads = 0;
     }
     // Upload and handle new image files
     $types = array('thumb', 'img', 'orig');
     foreach ($types as $type) {
         if (isset($files['tmp_name']) && isset($files['tmp_name'][$type]) && $files['tmp_name'][$type]) {
             jimport('joomla.filesystem.file');
             // Possibly the file name has to be changed because of another image format
             $temp_filename = $files['name'][$type];
             $columnname = 'imgfilename';
             if ($type == 'thumb') {
                 $columnname = 'imgthumbname';
             }
             $filename = $row->{$columnname};
             $new_ext = JFile::getExt($temp_filename);
             $old_ext = JFile::getExt($filename);
             if ($new_ext != $old_ext) {
                 $row->{$columnname} = substr_replace($row->{$columnname}, '.' . $new_ext, -(strlen($old_ext) + 1));
             }
             // Upload the file
             $file = $this->_ambit->getImg($type . '_path', $row);
             //JFile::delete($file);
             if (!JFile::upload($files['tmp_name'][$type], $file)) {
                 JError::raiseWarning(500, JText::sprintf('COM_JOOMGALLERY_UPLOAD_ERROR_UPLOADING', $this->_ambit->getImg($type . '_path', $row)));
                 // Revert database entry
                 $row->{$columnname} = $filename;
             }
             // Resize image
             $debugoutput = '';
             switch ($type) {
                 case 'thumb':
                     $return = JoomFile::resizeImage($debugoutput, $file, $file, $this->_config->get('jg_useforresizedirection'), $this->_config->get('jg_thumbwidth'), $this->_config->get('jg_thumbheight'), $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'));
                     break;
                 case 'img':
                     $return = JoomFile::resizeImage($debugoutput, $file, $file, false, $this->_config->get('jg_maxwidth'), false, $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_picturequality'), true);
                     break;
                 default:
                     break;
             }
         }
     }
     $move = false;
     if (isset($catid_old) && $catid_old != $row->catid) {
         $move = true;
         // Check whether the new category is a valid one
         if (!$category) {
             // If that's not the case store the image in the old category and leave a message
             $move = false;
             $row->catid = $catid_old;
             $this->_mainframe->enqueueMessage(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_VALID_CATEGORY_SELECTED'), 'notice');
         } else {
             // Access check for the selected new category
             if (!$this->_user->authorise('joom.upload', _JOOM_OPTION . '.category.' . $row->catid) && (!$this->_user->authorise('joom.upload.inown', _JOOM_OPTION . '.category.' . $row->catid) || !$category->owner || $category->owner != $this->_user->get('id'))) {
                 $move = false;
                 $row->catid = $catid_old;
                 $this->_mainframe->enqueueMessage(JText::_('COM_JOOMGALLERY_COMMON_MSG_NOT_ALLOWED_STORE_IMAGE_IN_CATEGORY'), 'notice');
             }
         }
     }
     // Move the image if necessary (the data is stored in function moveImage because
     // we have ensured that the old and new category ID are different from each other)
     if ($move && !$this->moveImage($row, $row->catid, $catid_old)) {
         $this->_mainframe->enqueueMessage(JText::_('COM_JOOMGALLERY_COULD_NOT_MOVE_IMAGE'), 'notice');
         return false;
     } else {
         // Make sure the record is valid
         if (!$row->check()) {
             $this->setError($row->getError());
             return false;
         }
         // Store the entry to the database
         if (!$row->store()) {
             $this->setError($row->getError());
             return false;
         }
     }
     // Successfully stored image (and moved)
     $row->reorder('catid = ' . $row->catid);
     if (isset($catid_old) and $catid_old != $row->catid) {
         $row->reorder('catid = ' . $catid_old);
     }
     $this->_mainframe->triggerEvent('onContentAfterSave', array(_JOOM_OPTION . '.image', &$row, false));
     return $row->id;
 }
Ejemplo n.º 2
0
 /**
  * Recreates thumbnails of the selected images.
  * If original image is existent, detail image will be recreated, too.
  *
  * @return  array   An array of result information (thumbnail number, detail image number, array with information which image types have been recreated)
  * @since   1.5.5
  */
 public function recreate()
 {
     jimport('joomla.filesystem.file');
     $cids = $this->_mainframe->getUserStateFromRequest('joom.recreate.cids', 'cid', array(), 'array');
     $type = $this->_mainframe->getUserStateFromRequest('joom.recreate.type', 'type', '', 'cmd');
     $thumb_count = $this->_mainframe->getUserState('joom.recreate.thumbcount');
     $img_count = $this->_mainframe->getUserState('joom.recreate.imgcount');
     $recreated = $this->_mainframe->getUserState('joom.recreate.recreated');
     $row = $this->getTable('joomgalleryimages');
     // Before first loop check for selected images
     if (is_null($thumb_count) && !count($cids)) {
         $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_IMAGES_SELECTED'));
         return array(false);
     }
     if (is_null($recreated)) {
         $recreated = array();
     }
     require_once JPATH_COMPONENT . '/helpers/refresher.php';
     $refresher = new JoomRefresher(array('controller' => 'images', 'task' => 'recreate', 'remaining' => count($cids), 'start' => JRequest::getBool('cid')));
     $debugoutput = '';
     // Loop through selected images
     foreach ($cids as $key => $cid) {
         $row->load($cid);
         $orig = $this->_ambit->getImg('orig_path', $row);
         $img = $this->_ambit->getImg('img_path', $row);
         $thumb = $this->_ambit->getImg('thumb_path', $row);
         // Check if there is an original image
         if (JFile::exists($orig)) {
             $orig_existent = true;
         } else {
             // If not, use detail image to create thumbnail
             $orig_existent = false;
             if (JFile::exists($img)) {
                 $orig = $img;
             } else {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_IMAGE_NOT_EXISTENT', $img));
                 $this->_mainframe->setUserState('joom.recreate.cids', array());
                 $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                 $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                 $this->_mainframe->setUserState('joom.recreate.recreated', null);
                 return false;
             }
         }
         // Recreate thumbnail
         if (!$type || $type == 'thumb') {
             // TODO: Move image into a trash instead of deleting immediately for possible rollback
             if (JFile::exists($thumb)) {
                 JFile::delete($thumb);
             }
             $return = JoomFile::resizeImage($debugoutput, $orig, $thumb, $this->_config->get('jg_useforresizedirection'), $this->_config->get('jg_thumbwidth'), $this->_config->get('jg_thumbheight'), $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'), false, $this->_config->get('jg_cropposition'));
             if (!$return) {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_COULD_NOT_CREATE_THUMB', $thumb));
                 $this->_mainframe->setUserState('joom.recreate.cids', array());
                 $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                 $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                 $this->_mainframe->setUserState('joom.recreate.recreated', null);
                 return false;
             }
             //$this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_SUCCESSFULLY_CREATED_THUMB', $row->id, $row->imgtitle));
             $recreated[$cid][] = 'thumb';
             $thumb_count++;
         }
         // Recreate detail image if original image is existent
         if ($orig_existent && (!$type || $type == 'img')) {
             // TODO: Move image into a trash instead of deleting immediately for possible rollback
             if (JFile::exists($img)) {
                 JFile::delete($img);
             }
             $return = JoomFile::resizeImage($debugoutput, $orig, $img, false, $this->_config->get('jg_maxwidth'), false, $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_picturequality'), true, 0);
             if (!$return) {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_COULD_NOT_CREATE_IMG', $img));
                 $this->_mainframe->setUserState('joom.recreate.cids', array());
                 $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                 $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                 $this->_mainframe->setUserState('joom.recreate.recreated', null);
                 return false;
             }
             //$this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_SUCCESSFULLY_CREATED_IMG', $row->id, $row->imgtitle));
             $recreated[$cid][] = 'img';
             $img_count++;
         }
         unset($cids[$key]);
         // Check remaining time
         if (!$refresher->check()) {
             $this->_mainframe->setUserState('joom.recreate.cids', $cids);
             $this->_mainframe->setUserState('joom.recreate.thumbcount', $thumb_count);
             $this->_mainframe->setUserState('joom.recreate.imgcount', $img_count);
             $this->_mainframe->setUserState('joom.recreate.recreated', $recreated);
             $refresher->refresh(count($cids));
         }
     }
     $this->_mainframe->setUserState('joom.recreate.cids', array());
     $this->_mainframe->setUserState('joom.recreate.type', null);
     $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
     $this->_mainframe->setUserState('joom.recreate.imgcount', null);
     $this->_mainframe->setUserState('joom.recreate.recreated', null);
     return array($thumb_count, $img_count, $recreated);
 }
Ejemplo n.º 3
0
 /**
  * Creates images from the original one or moves the existing ones
  * into the folders of their category.
  *
  * Required parameters are the first two ($row and $origimage) with $row being the data object with image
  * information and $origimage being the path and filename of the image to migrate. $origimage will be the one
  * stored in the original images directory of JoomGallery.
  * You can also specify $detailimage and $thumbnail which will store them in the respective folders. If you
  * don't specify them they will be created from the original image.
  *
  * [jimport('joomla.filesystem.file') has to be called afore]
  *
  * @param   object  $row          Holds information about the new image
  * @param   string  $origimage    The original image
  * @param   string  $detailimage  The detail image
  * @param   string  $thumbnail    The thumbnail
  * @param   boolean $newfilename  True if a new file name shall be generated for the files
  * @param   boolean $copy         True if the image shall be copied into the new directory, not moved
  * @param   boolean $checkOwner   Determines whether the owner ID shall be checked against the existing users
  * @return  boolean True on success, false otherwise
  * @since   1.5.0
  */
 public function moveAndResizeImage($row, $origimage, $detailimage = null, $thumbnail = null, $newfilename = true, $copy = null, $checkOwner = null)
 {
     if (is_null($copy)) {
         $copy = $this->copyImages;
     }
     if (is_null($checkOwner)) {
         $checkOwner = $this->checkOwner;
     }
     // Some checks
     if (!isset($row->id) || $row->id < 1) {
         $this->setError('Invalid image ID');
         return false;
     }
     if (!isset($row->imgfilename)) {
         $this->setError('Image file name wasn\'t found.');
         return false;
     }
     if (!isset($row->catid) || $row->catid < 1) {
         $this->setError('Invalid category ID');
         return false;
     } else {
         // If image with category ID 1 comes in we have to set
         // the category ID to the newly created one because
         // category with ID 1 is the ROOT category in JoomGallery
         if ($row->catid == 1) {
             $row->catid = $this->newCatid;
         }
     }
     if (!isset($row->catpath)) {
         $row->catpath = JoomHelper::getCatpath($row->catid);
         if (!$row->catpath) {
             $this->setError('Category with ID ' . $row->catid . ' does not exist for image with ID ' . $row->id . '. Image cannot be migrated.');
             return false;
         }
     }
     if (!isset($row->imgtitle)) {
         $row->imgtitle = str_replace(JFile::getExt($row->imgfilename), '', $row->imgfilename);
     }
     if (!isset($row->alias)) {
         // Will be created later on
         $row->alias = '';
     }
     if (!isset($row->imgauthor)) {
         $row->imgauthor = '';
     }
     if (!isset($row->imgtext)) {
         $row->imgtext = '';
     }
     if (!isset($row->imgdate) || is_numeric($row->imgdate)) {
         $date = JFactory::getDate();
         $row->imgdate = $date->toSQL();
     }
     if (!isset($row->hits)) {
         $row->hits = 0;
     }
     if (!isset($row->downloads)) {
         $row->downloads = 0;
     }
     if (!isset($row->imgvotes)) {
         $row->imgvotes = 0;
     }
     if (!isset($row->imgvotesum)) {
         $row->imgvotesum = 0;
     }
     if (!isset($row->access) || $row->access < 1) {
         $row->access = $this->_mainframe->getCfg('access');
     }
     if (!isset($row->published)) {
         $row->published = 0;
     }
     if (!isset($row->hidden)) {
         $row->hidden = 0;
     }
     if (!isset($row->imgthumbname)) {
         $row->imgthumbname = $row->imgfilename;
     }
     if (!isset($row->checked_out)) {
         $row->checked_out = 0;
     }
     if (!isset($row->owner) || !is_numeric($row->owner) || $row->owner < 1 || $checkOwner && !JUser::getTable()->load($row->owner)) {
         $row->owner = 0;
     }
     if (!isset($row->approved)) {
         $row->approved = 1;
     }
     if (!isset($row->useruploaded)) {
         $row->useruploaded = 0;
     }
     if (!isset($row->ordering)) {
         $row->ordering = 0;
     }
     if (!isset($row->params)) {
         $row->params = '';
     }
     if (!isset($row->metakey)) {
         $row->metakey = '';
     }
     if (!isset($row->metadesc)) {
         $row->metadesc = '';
     }
     // Check whether one of the images to migrate already exist in the destination directory
     $orig_exists = false;
     $img_exists = false;
     $thumb_exists = false;
     $neworigimage = $this->_ambit->getImg('orig_path', $row);
     $newdetailimage = $this->_ambit->getImg('img_path', $row);
     $newthumbnail = $this->_ambit->getImg('thumb_path', $row);
     if (JFile::exists($neworigimage)) {
         $orig_exists = true;
     }
     if (JFile::exists($newdetailimage)) {
         $img_exists = true;
     }
     if (JFile::exists($newthumbnail)) {
         $thumb_exists = true;
     }
     // Generate a new file name if requested or if a file with the current name already exists
     if ($newfilename || $orig_exists || $img_exists || $thumb_exists) {
         $row->imgfilename = $this->genFilename($row->imgtitle, $origimage, $row->catid);
         $row->imgthumbname = $row->imgfilename;
     }
     $result = array();
     // Copy or move original image into the folder of the original images
     if (!$orig_exists) {
         // If it doesn't already exists with another name try to copy or move from source directory
         if (!JFile::exists($origimage)) {
             $this->setError('Original image not found: ' . $origimage);
             return false;
         }
         $neworigimage = $this->_ambit->getImg('orig_path', $row);
         if ($copy) {
             $result['orig'] = JFile::copy(JPath::clean($origimage), JPath::clean($neworigimage));
             if (!$result['orig']) {
                 $this->setError('Could not copy original image from ' . $origimage . ' to ' . $neworigimage);
                 return false;
             }
         } else {
             $result['orig'] = JFile::move(JPath::clean($origimage), JPath::clean($neworigimage));
             if (!$result['orig']) {
                 $this->setError('Could not move original image from ' . $origimage . ' to ' . $neworigimage);
                 return false;
             }
         }
     } else {
         // If it already exists with another name copy it to a file with the new name
         if (!JFile::copy($neworigimage, $this->_ambit->getImg('orig_path', $row))) {
             $this->setError('Could not copy original image from ' . $neworigimage . ' to ' . $this->_ambit->getImg('orig_path', $row));
             return false;
         }
         // Populate the new original file name and path because it will be
         // necessary for deleting it of deleting original images is configured
         $neworigimage = $this->_ambit->getImg('orig_path', $row);
     }
     if (!$img_exists) {
         // If it doesn't already exists with another name try to copy or move from source directory or create a new one
         $newdetailimage = $this->_ambit->getImg('img_path', $row);
         if (is_null($detailimage) || !JFile::exists($detailimage)) {
             // Create new detail image
             $debugoutput = '';
             $result['detail'] = JoomFile::resizeImage($debugoutput, $neworigimage, $newdetailimage, false, $this->_config->get('jg_maxwidth'), false, $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'), true, 0);
             if (!$result['detail']) {
                 $this->setError('Could not create detail image ' . $newdetailimage);
             }
         } else {
             // Copy or move existing detail image
             if ($copy) {
                 $result['detail'] = JFile::copy(JPath::clean($detailimage), JPath::clean($newdetailimage));
                 if (!$result['detail']) {
                     $this->setError('Could not copy detail image from ' . $detailimage . ' to ' . $newdetailimage);
                 }
             } else {
                 $result['detail'] = JFile::move(JPath::clean($detailimage), JPath::clean($newdetailimage));
                 if (!$result['detail']) {
                     $this->setError('Could not move detail image from ' . $detailimage . ' to ' . $newdetailimage);
                 }
             }
         }
     } else {
         // If it already exists with another name copy it to a file with the new name
         $result['detail'] = JFile::copy($newdetailimage, $this->_ambit->getImg('img_path', $row));
         if (!$result['detail']) {
             $this->setError('Could not copy detail image from ' . $newdetailimage . ' to ' . $this->_ambit->getImg('img_path', $row));
         }
     }
     if (!$thumb_exists) {
         // If it doesn't already exists with another name try to copy or move from source directory or create a new one
         $newthumbnail = $this->_ambit->getImg('thumb_path', $row);
         if (is_null($thumbnail) || !JFile::exists($thumbnail)) {
             // Create new thumbnail
             $debugoutput = '';
             $result['thumb'] = JoomFile::resizeImage($debugoutput, $neworigimage, $newthumbnail, $this->_config->get('jg_useforresizedirection'), $this->_config->get('jg_thumbwidth'), $this->_config->get('jg_thumbheight'), $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'), false, $this->_config->get('jg_cropposition'));
             if (!$result['thumb']) {
                 $this->setError('Could not create thumbnail ' . $newthumbnail);
             }
         } else {
             // Copy or move existing thumbnail
             if ($copy) {
                 $result['thumb'] = JFile::copy(JPath::clean($thumbnail), JPath::clean($newthumbnail));
                 if (!$result['thumb']) {
                     $this->setError('Could not copy thumbnail from ' . $thumbnail . ' to ' . $newthumbnail);
                 }
             } else {
                 $result['thumb'] = JFile::move(JPath::clean($thumbnail), JPath::clean($newthumbnail));
                 if (!$result['thumb']) {
                     $this->setError('Could not move thumbnail from ' . $thumbnail . ' to ' . $newthumbnail);
                 }
             }
         }
     } else {
         // If it already exists with another name copy it to a file with the new name
         $result['thumb'] = JFile::copy($newthumbnail, $this->_ambit->getImg('thumb_path', $row));
         if (!$result['thumb']) {
             $this->setError('Could not copy thumbnail from ' . $newthumbnail . ' to ' . $this->_ambit->getImg('thumb_path', $row));
         }
     }
     // Delete original image if configured in JoomGallery
     if ($this->_config->get('jg_delete_original') == 1) {
         $result['delete_orig'] = JFile::delete($neworigimage);
         if (!$result['delete_orig']) {
             $this->setError('Could not delete original image ' . $neworigimage);
         }
     }
     // Create database entry
     $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_IMAGES)->columns('id, catid, imgtitle, alias, imgauthor, imgtext, imgdate, hits, downloads, imgvotes, imgvotesum, access, published, hidden, imgfilename, imgthumbname, checked_out, owner, approved, useruploaded, ordering, params, metakey, metadesc')->values((int) $row->id . ',' . (int) $row->catid . ',' . $this->_db->quote($row->imgtitle) . ',' . $this->_db->quote($row->alias) . ',' . $this->_db->quote($row->imgauthor) . ',' . $this->_db->quote($row->imgtext) . ',' . $this->_db->quote($row->imgdate) . ',' . (int) $row->hits . ',' . (int) $row->downloads . ',' . (int) $row->imgvotes . ',' . (int) $row->imgvotesum . ',' . (int) $row->access . ',' . (int) $row->published . ',' . (int) $row->hidden . ',' . $this->_db->quote($row->imgfilename) . ',' . $this->_db->quote($row->imgthumbname) . ',' . (int) $row->checked_out . ',' . (int) $row->owner . ',' . (int) $row->approved . ',' . (int) $row->useruploaded . ',' . (int) $row->ordering . ',' . $this->_db->quote($row->params) . ',' . $this->_db->quote($row->metakey) . ',' . $this->_db->quote($row->metadesc));
     $this->_db->setQuery($query);
     $result[] = $this->runQuery();
     // Create asset and alias
     $table = JTable::getInstance('joomgalleryimages', 'Table');
     $table->load($row->id);
     if ($table->check()) {
         $result['db'] = $table->store();
         if (!$result['db']) {
             $this->setError($table->getError(), true);
         }
     }
     if (!in_array(false, $result)) {
         $this->writeLogfile('Image successfully migrated: ' . $row->id . ' Title: ' . $row->imgtitle);
         return true;
     } else {
         $this->writeLogfile('-> Error migrating image: ' . $row->id . ' Title: ' . $row->imgtitle);
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * Creates thumbnail and detail image for an image file
  *
  * @param   string  $source         The source file for which the thumbnail and the detail image shall be created
  * @param   string  $filename       The file name for the created files
  * @param   boolean $is_in_original Determines whether the source file is already in the original images folders
  * @param   boolean $delete_source  Determines whether the source file shall be deleted after the procedure
  * @return  boolean True on success, false otherwise
  * @since   1.5.7
  */
 protected function resizeImage($source, $filename, $is_in_original = true, $delete_source = false)
 {
     if (!getimagesize($source)) {
         // getimagesize didn't find a valid image
         $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_INVALID_IMAGE_FILE') . '<br />';
         $this->debug = true;
         return false;
     }
     // Check the possible available memory for image resizing.
     // If not available echo error message and return false
     $tag = JFile::getExt($source);
     if (!$this->checkMemory($source, $tag)) {
         $this->debug = true;
         return false;
     }
     // Create thumb
     $return = JoomFile::resizeImage($this->_debugoutput, $source, $this->_ambit->getImg('thumb_path', $filename, null, $this->catid), $this->_config->get('jg_useforresizedirection'), $this->_config->get('jg_thumbwidth'), $this->_config->get('jg_thumbheight'), $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'), false, $this->_config->get('jg_cropposition'));
     if (!$return) {
         $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_THUMBNAIL_NOT_CREATED', $this->_ambit->getImg('thumb_path', $filename, null, $this->catid)) . '<br />';
         $this->debug = true;
         return false;
     }
     $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_THUMBNAIL_CREATED') . '<br />';
     // Optionally create detail image
     $detail_image_created = false;
     if ($this->_config->get('jg_resizetomaxwidth') && ($this->_site && $this->_config->get('jg_special_gif_upload') == 0 || !$this->_mainframe->getUserStateFromRequest('joom.upload.create_special_gif', 'create_special_gif', false, 'bool') || $tag != 'gif' && $tag != 'png')) {
         $return = JoomFile::resizeImage($this->_debugoutput, $source, $this->_ambit->getImg('img_path', $filename, null, $this->catid), false, $this->_config->get('jg_maxwidth'), false, $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_picturequality'), true, 0);
         if (!$return) {
             $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_IMG_NOT_CREATED', $this->_ambit->getImg('img_path', $filename, null, $this->catid)) . '<br />';
             $this->debug = true;
             return false;
         }
         $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_RESIZED_TO_MAXWIDTH') . '<br />';
         $detail_image_created = true;
     }
     $delete_original = $this->_mainframe->getUserStateFromRequest('joom.upload.delete_original', 'original_delete', false, 'bool');
     $delete_original = $this->_site && $this->_config->get('jg_delete_original_user') == 1 || $this->_site && $this->_config->get('jg_delete_original_user') == 2 && $delete_original || !$this->_site && $this->_config->get('jg_delete_original') == 1 || !$this->_site && $this->_config->get('jg_delete_original') == 2 && $delete_original;
     if ($delete_original && !$is_in_original && $delete_source || $delete_original && $is_in_original) {
         if ($detail_image_created) {
             // Remove image from originals if chosen in backend
             if (JFile::delete($source)) {
                 $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_ORIGINAL_DELETED') . '<br />';
             } else {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_DELETING_ORIGINAL', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . ' ' . JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS') . '<br />';
                 $this->debug = true;
                 return false;
             }
         } else {
             // Move original image to detail images folder if original image shall be deleted and detail image wasn't resized
             $return = JFile::move($source, $this->_ambit->getImg('img_path', $filename, null, $this->catid));
             if (!$return) {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_MOVING', $this->_ambit->getImg('img_path', $filename, null, $this->catid)) . '<br />';
                 $this->debug = true;
                 return false;
             }
         }
     } else {
         if (!$detail_image_created) {
             // Copy original image into detail images folder if original image shouldn't be deleted and detail image wasn't resized
             $return = JFile::copy($source, $this->_ambit->getImg('img_path', $filename, null, $this->catid));
             if (!$return) {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_COPYING', $this->_ambit->getImg('img_path', $filename, null, $this->catid)) . '<br />';
                 $this->debug = true;
                 return false;
             }
             if ($delete_original && !$is_in_original && !$delete_source) {
                 if (JFile::delete($source)) {
                     $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_ORIGINAL_DELETED') . '<br />';
                 } else {
                     $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_DELETING_ORIGINAL', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . ' ' . JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS') . '<br />';
                     $this->debug = true;
                     return false;
                 }
             }
         }
     }
     // Set permissions of detail image
     if ($detail_image_created) {
         $return = JoomFile::chmod($this->_ambit->getImg('img_path', $filename, null, $this->catid), '0644');
         /*if(!$return)
           {
             $this->_debugoutput .= $this->_ambit->getImg('img_path', $filename, null, $this->catid).' '.JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS').'<br />';
             $this->debug        = true;
             return false;
           }*/
     }
     if (!$delete_original && !$is_in_original && !$delete_source) {
         // Copy source file to orginal images folder if original image shouldn't be deleted and if it's not already there
         $return = JFile::copy($source, $this->_ambit->getImg('orig_path', $filename, null, $this->catid));
         if (!$return) {
             $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_COPYING', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . '<br />';
             $this->debug = true;
             return false;
         }
     } else {
         if (!$delete_original && !$is_in_original && $delete_source) {
             // Move source file to orginal images folder if original image shall be deleted and if it's not already there
             $return = JFile::move($source, $this->_ambit->getImg('orig_path', $filename, null, $this->catid));
             if (!$return) {
                 $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_MOVING', $this->_ambit->getImg('orig_path', $filename, null, $this->catid)) . '<br />';
                 $this->debug = true;
                 return false;
             }
         }
     }
     return true;
 }