/** * Deletes folders of an existing category * * @param string $catpath The catpath of the category * @return boolean True on success, false otherwise * @since 1.5.5 */ protected function _deleteFolders($catpath) { if (!$catpath) { return false; } $orig_path = JPath::clean($this->_ambit->get('orig_path') . $catpath); $img_path = JPath::clean($this->_ambit->get('img_path') . $catpath); $thumb_path = JPath::clean($this->_ambit->get('thumb_path') . $catpath); // Delete the folder of the category for the original images if (!JFolder::delete($orig_path)) { // If not successfull return false; } else { // Delete the folder of the category for the detail images if (!JFolder::delete($img_path)) { // If not successful if (JFolder::create($orig_path)) { JoomFile::copyIndexHtml($orig_path); } return false; } else { // Delete the folder of the category for the thumbnails if (!JFolder::delete($thumb_path)) { // If not successful if (JFolder::create($orig_path)) { JoomFile::copyIndexHtml($orig_path); } if (JFolder::create($img_path)) { JoomFile::copyIndexHtml($img_path); } return false; } } } return true; }
/** * Method to copy/move the files for a new image. * This method also creates new file names for the images and stores the row. * * @param object $row Holds the data of the new image. * @param string $catpath The catpath of the new image * @param string $detail_catpath The catpath of the detail image to copy * @param string $thumb_catpath The catpath of the thumbnail to copy * @param int $copy_original Indicates whether the original image should be copied, too * @return boolean True on success, false otherwise * @since 1.5.5 */ protected function _newImage($row, $catpath, $detail_catpath, $thumb_catpath, $copy_original) { jimport('joomla.filesystem.file'); // Create new file names $date = date('Ymd'); $filename = JoomFile::fixFilename($row->imgtitle); $img_tag = JFile::getExt($row->imgfilename); $thumb_tag = JFile::getExt($row->imgthumbname); $src_imgfilename = $row->imgfilename; $src_imgthumbname = $row->imgthumbname; do { mt_srand(); $randomnumber = mt_rand(1000000000, 2099999999); // New filename $newfilename = $filename . '_' . $date . '_' . $randomnumber; } while (JFile::exists($this->_ambit->getImg('orig_path', $newfilename . '.' . $img_tag, null, $row->catid)) || JFile::exists($this->_ambit->getImg('img_path', $newfilename . '.' . $img_tag, null, $row->catid)) || JFile::exists($this->_ambit->getImg('thumb_path', $newfilename . '.' . $thumb_tag, null, $row->catid))); $row->imgfilename = $newfilename . '.' . $img_tag; $row->imgthumbname = $newfilename . '.' . $thumb_tag; // If the destination thumbnail directory doesn't exist if (!JFolder::exists($this->_ambit->get('thumb_path') . $catpath)) { // Raise an error message and abort $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_FOLDER_NOT_EXISTENT', $this->_ambit->get('thumb_path') . $catpath), 'error'); return false; } // Try to copy the thumbnail from source to destination $result = JFile::copy(JPath::clean($this->_ambit->get('thumb_path') . $thumb_catpath . $src_imgthumbname), JPath::clean($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname)); if (!$result) { // Raise an error message and abort $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_ERROR_COPYING_THUMB', $this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname), 'error'); return false; } // Same procedure like thumbnail for copying the detail image // In case of error delete the copied thumbnail from destination if (!JFolder::exists($this->_ambit->get('img_path') . $catpath)) { JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_FOLDER_NOT_EXISTENT', $this->_ambit->get('img_path') . $catpath), 'error'); return false; } $result = JFile::copy(JPath::clean($this->_ambit->get('img_path') . $detail_catpath . $src_imgfilename), JPath::clean($this->_ambit->get('img_path') . $catpath . $row->imgfilename)); if (!$result) { JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_ERROR_COPYING_IMAGE', $this->_ambit->get('img_path') . $catpath . $row->imgfilename), 'error'); return false; } // If setted to create an original image do the following action, // otherwise do not copy the image $orig_created = false; if ($copy_original) { if (JFile::exists($this->_ambit->get('orig_path') . $detail_catpath . $src_imgfilename)) { // Use the path to original images from now on $imagepath = $this->_ambit->get('orig_path') . $detail_catpath; } else { // Image doesn't exist // Use the path to detail images from now and use detail image as original image $imagepath = $this->_ambit->get('img_path') . $detail_catpath; } if (!JFolder::exists($this->_ambit->get('orig_path') . $catpath)) { // Directory doesn't exist, so delete the thumbnail and the detail image JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); JFile::delete($this->_ambit->get('img_path') . $catpath . $row->imgfilename); // Raise an error message and abort $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_FOLDER_NOT_EXISTENT', $this->_ambit->get('orig_path') . $catpath), 'error'); return false; } // Destination directory exists, so try to copy the image from source to destination $result = JFile::copy(JPath::clean($imagepath . $src_imgfilename), JPath::clean($this->_ambit->get('orig_path') . $catpath . $row->imgfilename)); if (!$result) { // Delete thumbnail and detail image JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); JFile::delete($this->_ambit->get('img_path') . $catpath . $row->imgfilename); $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_ERROR_COPYING_ORIGINAL%s', $this->_ambit->get('orig_path') . $catpath . $row->imgfilename), 'error'); return false; } $orig_created = true; } // Store the record // If not succesful raise an error messages and abort if (!$row->store()) { // Delete the thumbnail, detail image and original image JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); JFile::delete($this->_ambit->get('img_path') . $catpath . $row->imgfilename); if ($orig_created) { JFile::delete($this->_ambit->get('orig_path') . $catpath . $row->imgfilename); } $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } return true; }
/** * 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); }
/** * Generates a new filename * e.g. <Name/gen. Title>_<Date>_<Random Number>.<Extension> * * @param string $title The title of the image * @param string $file Path and file name of the old image file * @param int $catid ID of the category into which the image will be stored * @param string $tag File extension e.g. 'jpg' * @return string The generated filename * @since 2.0 */ protected function genFilename($title, $file, $catid) { $date = date('Ymd'); $tag = strtolower(JFile::getExt($file)); $filename = JoomFile::fixFilename($title); // Remove filetag = $tag incl '.' $filename = substr($filename, 0, strlen($filename) - strlen($tag) - 1); do { mt_srand(); $randomnumber = mt_rand(1000000000, 2099999999); // New filename $newfilename = $filename . '_' . $date . '_' . $randomnumber . '.' . $tag; } while (JFile::exists($this->_ambit->getImg('orig_path', $newfilename, null, $catid)) || JFile::exists($this->_ambit->getImg('img_path', $newfilename, null, $catid)) || JFile::exists($this->_ambit->getImg('thumb_path', $newfilename, null, $catid))); return $newfilename; }
/** * Method to create the zip archive with all selected images * * @return boolean True on success, false otherwise * @since 1.0.0 */ public function createZip() { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); $zip_adapter = JArchive::getAdapter('zip'); // Check whether zip download is allowed if (!$this->_config->get('jg_zipdownload') && ($this->_user->get('id') || !$this->_config->get('jg_usefavouritesforpubliczip'))) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), JText::_('COM_JOOMGALLERY_FAVOURITES_MSG_NOT_ALLOWED'), 'notice'); } if (is_null($this->piclist)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice'); } $query = $this->_db->getQuery(true)->select('id')->select('catid')->select('imgfilename')->from(_JOOM_TABLE_IMAGES . ' AS a')->from(_JOOM_TABLE_CATEGORIES . ' AS c')->where('id IN (' . $this->piclist . ')')->where('a.catid = c.cid')->where('a.published = 1')->where('a.approved = 1')->where('c.published = 1')->where('a.access IN (' . implode(',', $this->_user->getAuthorisedViewLevels()) . ')')->where('c.access IN (' . implode(',', $this->_user->getAuthorisedViewLevels()) . ')'); $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); if (!count($rows)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice'); } // Name of the zip archive $zipname = 'components/' . _JOOM_OPTION . '/joomgallery_' . date('d_m_Y') . '__'; if ($userid = $this->_user->get('id')) { $zipname .= $userid . '_'; } $zipname .= mt_rand(10000, 99999) . '.zip'; $files = array(); if ($this->_config->get('jg_downloadwithwatermark')) { $include_watermark = true; // Get the 'image' model $imageModel = parent::getInstance('image', 'joomgallerymodel'); // Get the temp path for storing the watermarked image temporarily if (!JFolder::exists($this->_ambit->get('temp_path'))) { $this->setError(JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_TEMP_MISSING')); return false; } else { $tmppath = $this->_ambit->get('temp_path'); } } else { $include_watermark = false; } $categories = $this->_ambit->getCategoryStructure(); foreach ($rows as &$row) { if (!isset($categories[$row->catid])) { continue; } // Get the original image if existent, otherwise the detail image $orig = $this->_ambit->getImg('orig_path', $row->id); $img = $this->_ambit->getImg('img_path', $row->id); if (file_exists($orig)) { $image = $orig; } else { if (file_exists($img)) { $image = $img; } else { $image = null; continue; } } $files[$row->id]['name'] = $row->imgfilename; // Watermark the image before if needed if ($include_watermark) { // Get the image resource of watermarked image $imgres = $imageModel->includeWatermark($image); // Start output buffering ob_start(); // According to mime type output the watermarked image resource to file $info = getimagesize($image); switch ($info[2]) { case 1: imagegif($imgres); break; case 2: imagejpeg($imgres); break; case 3: imagepng($imgres); break; default: JError::raiseError(404, JText::sprintf('COM_JOOMGALLERY_COMMON_MSG_MIME_NOT_ALLOWED', $mime)); break; } // Read the content from output buffer and fill the array element $files[$row->id]['data'] = ob_get_contents(); // Delete the output buffer ob_end_clean(); } else { $files[$row->id]['data'] = JFile::read($image); } // Increase download counter for that image $this->download($row->id); } if (!count($files)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false), $this->output('NO_IMAGES'), 'notice'); } // Trigger event 'onJoomBeforeZipDownload' $plugins = $this->_mainframe->triggerEvent('onJoomBeforeZipDownload', array(&$files)); if (in_array(false, $plugins, true)) { $this->_mainframe->redirect(JRoute::_('index.php?view=favourites', false)); } $createzip = $zip_adapter->create($zipname, $files); if (!$createzip) { // Workaround for servers with wwwwrun problem JoomFile::chmod(JPATH_COMPONENT, '0777', true); $createzip = $zip_adapter->create($zipname, $files, 'zip'); JoomFile::chmod(JPATH_COMPONENT, '0755', true); } if (!$createzip) { $this->setError(JText::_('COM_JOOMGALLERY_FAVOURITES_ERROR_CREATEZIP')); return false; } if ($this->_user->get('id')) { if ($this->user_exists) { $query = $this->_db->getQuery(true)->select('zipname')->from(_JOOM_TABLE_USERS)->where('uuserid = ' . $this->_user->get('id')); $this->_db->setQuery($query); if ($old_zip = $this->_db->loadResult()) { if (file_exists($old_zip)) { jimport('joomla.filesystem.file'); JFile::delete($old_zip); } } $query = $this->_db->getQuery(true)->update(_JOOM_TABLE_USERS)->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname))->where('uuserid = ' . $this->_user->get('id')); $this->_db->setQuery($query); } else { $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_USERS)->set('uuserid = ' . $this->_user->get('id'))->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname)); $this->_db->setQuery($query); } } else { $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_USERS)->set('time = NOW()')->set('zipname = ' . $this->_db->q($zipname)); $this->_db->setQuery($query); } $this->_db->query(); $this->_mainframe->setUserState('joom.favourites.zipname', $zipname); // Message about new zip download if (!$this->_user->get('username')) { $username = JText::_('COM_JOOMGALLERY_COMMON_GUEST'); } else { $username = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username'); } if ($this->_config->get('jg_msg_zipdownload')) { $imagefiles = implode(",\n", $files); require_once JPATH_COMPONENT . '/helpers/messenger.php'; $messenger = new JoomMessenger(); $message = array('subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_ZIPDOWNLOAD_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_ZIPDOWNLOAD_BODY', $zipname, $username, $imagefiles), 'mode' => 'zipdownload'); $messenger->send($message); } return true; }
/** * Creates new folders for categories. * * @return int/boolean Number of created folders on success, false otherwise * @since 1.5.5 */ public function create() { $cids = JRequest::getVar('cid', array(), '', 'array'); $types = JRequest::getVar('type', array('thumb', 'img', 'orig'), '', 'array'); if (!count($cids)) { $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_CATEGORIES_SELECTED')); return false; } // Get selected category IDs $query = $this->_db->getQuery(true)->select('refid')->from($this->_db->qn(_JOOM_TABLE_MAINTENANCE))->where('id IN (' . implode(',', $cids) . ')')->where('type != 0'); $this->_db->setQuery($query); if (!($ids = $this->_db->loadColumn())) { $this->setError($this->_db->getErrorMsg()); return false; } $count = 0; foreach ($types as $type) { foreach ($ids as $cid) { // Create the folder $folder = $this->_ambit->get($type . '_path') . JoomHelper::getCatPath($cid); if (!JFolder::create($folder)) { continue; } JoomFile::copyIndexHtml($folder); // Update maintenance table $query = $this->_db->getQuery(true)->update($this->_db->qn(_JOOM_TABLE_MAINTENANCE))->set($type . ' = ' . $this->_db->q($this->_db->escape($folder)))->where('refid = ' . $cid)->where('type != 0'); $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $count++; } } return $count; }
/** * Resize image with functions from gd/gd2/imagemagick * * Cropping function adapted from * 'Resize Image with Different Aspect Ratio' * Author: Nash * Website: http://nashruddin.com/Resize_Image_to_Different_Aspect_Ratio_on_the_fly * * @param &string $debugoutput debug information * @param string $src_file Path to source file * @param string $dest_file Path to destination file * @param int $useforresizedirection Thumbnails only: * Resize to width/height ratio or free setting * @param int $new_width Width to resize * @param int $thumbheight Height to resize * @param int $method 1=gd1, 2=gd2, 3=im * @param int $dest_qual $config->jg_thumbquality/jg_picturequality * @param boolean $max_width true=resize to maxwidth * @param int $cropposition $config->jg_cropposition * @return boolean True on success, false otherwise * @since 1.0.0 */ public static function resizeImage(&$debugoutput, $src_file, $dest_file, $useforresizedirection, $new_width, $thumbheight, $method, $dest_qual, $max_width = false, $cropposition) { $config = JoomConfig::getInstance(); // Ensure that the pathes are valid and clean $src_file = JPath::clean($src_file); $dest_file = JPath::clean($dest_file); // Doing resize instead of thumbnail, copy original and remove it. $imginfo = getimagesize($src_file); if (!$imginfo) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_FILE_NOT_FOUND') . '<br />'; return false; } // GD can only handle JPG & PNG images if ($imginfo[2] != IMAGETYPE_JPEG && $imginfo[2] != IMAGETYPE_PNG && $imginfo[2] != IMAGETYPE_GIF && ($method == 'gd1' || $method == 'gd2')) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_ONLY_JPG_PNG') . '<br />'; return false; } $imagetype = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF', 8 => 'TIFF', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF'); $imginfo[2] = $imagetype[$imginfo[2]]; // Height/width $srcWidth = $imginfo[0]; $srcHeight = $imginfo[1]; if ($max_width && $srcWidth <= $new_width && $srcHeight <= $new_width || !$max_width && $srcWidth <= $new_width && $srcHeight <= $thumbheight) { // If source image is already of the same size or smaller than the image // which shall be created only copy the source image to destination $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_RESIZE_NOT_NECESSARY') . '<br />'; if (!JFile::copy($src_file, $dest_file)) { $debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_PROBLEM_COPYING', $dest_file) . ' ' . JText::_('COM_JOOMGALLERY_COMMON_CHECK_PERMISSIONS') . '<br />'; return false; } return true; } // For free resizing and cropping the center $offsetx = null; $offsety = null; if ($max_width) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_RESIZE_TO_MAX') . '<br />'; if ($new_width <= 0) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_NO_VALID_WIDTH_OR_HEIGHT') . '<br />'; return false; } $ratio = max($srcHeight, $srcWidth) / $new_width; } else { // Resizing to thumbnail $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_CREATE_THUMBNAIL_FROM') . ' ' . $imginfo[2] . ', ' . $imginfo[0] . ' x ' . $imginfo[1] . '...<br />'; if ($new_width <= 0 || $thumbheight <= 0) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_NO_VALID_WIDTH_OR_HEIGHT') . '<br />'; return false; } switch ($useforresizedirection) { // Convert to height ratio case 0: $ratio = $srcHeight / $thumbheight; $testwidth = $srcWidth / $ratio; // If new width exceeds setted max. width if ($testwidth > $new_width) { $ratio = $srcWidth / $new_width; } break; // Convert to width ratio // Convert to width ratio case 1: $ratio = $srcWidth / $new_width; $testheight = $srcHeight / $ratio; // If new height exceeds the setted max. height if ($testheight > $thumbheight) { $ratio = $srcHeight / $thumbheight; } break; // Free resizing and cropping the center // Free resizing and cropping the center case 2: if ($srcWidth < $new_width) { $new_width = $srcWidth; } if ($srcHeight < $thumbheight) { $thumbheight = $srcHeight; } // Expand the thumbnail's aspect ratio // to fit the width/height of the image $ratiowidth = $srcWidth / $new_width; $ratioheight = $srcHeight / $thumbheight; if ($ratiowidth < $ratioheight) { $ratio = $ratiowidth; } else { $ratio = $ratioheight; } // Calculate the offsets for cropping the source image according // to thumbposition switch ($cropposition) { // Left upper corner case 0: $offsetx = 0; $offsety = 0; break; // Right upper corner // Right upper corner case 1: $offsetx = floor($srcWidth - $new_width * $ratio); $offsety = 0; break; // Left lower corner // Left lower corner case 3: $offsetx = 0; $offsety = floor($srcHeight - $thumbheight * $ratio); break; // Right lower corner // Right lower corner case 4: $offsetx = floor($srcWidth - $new_width * $ratio); $offsety = floor($srcHeight - $thumbheight * $ratio); break; // Default center // Default center default: $offsetx = floor(($srcWidth - $new_width * $ratio) * 0.5); $offsety = floor(($srcHeight - $thumbheight * $ratio) * 0.5); break; } } } if (is_null($offsetx) && is_null($offsety)) { $ratio = max($ratio, 1.0); $destWidth = (int) ($srcWidth / $ratio); $destHeight = (int) ($srcHeight / $ratio); } else { $destWidth = $new_width; $destHeight = $thumbheight; $srcWidth = (int) ($destWidth * $ratio); $srcHeight = (int) ($destHeight * $ratio); } // Method for creation of the resized image switch ($method) { case 'gd1': if (!function_exists('imagecreatefromjpeg')) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_LIBARY_NOT_INSTALLED'); return false; } if ($imginfo[2] == 'JPG') { $src_img = imagecreatefromjpeg($src_file); } else { if ($imginfo[2] == 'PNG') { $src_img = imagecreatefrompng($src_file); } else { $src_img = imagecreatefromgif($src_file); } } if (!$src_img) { return false; } $dst_img = imagecreate($destWidth, $destHeight); if (!is_null($offsetx) && !is_null($offsety)) { imagecopyresized($dst_img, $src_img, 0, 0, $offsetx, $offsety, $destWidth, (int) $destHeight, $srcWidth, $srcHeight); } else { imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight); } if (!@imagejpeg($dst_img, $dest_file, $dest_qual)) { // Workaround for servers with wwwrun problem $dir = dirname($dest_file); JoomFile::chmod($dir, '0777', true); imagejpeg($dst_img, $dest_file, $dest_qual); JoomFile::chmod($dir, '0755', true); } imagedestroy($src_img); imagedestroy($dst_img); break; case 'gd2': if (!function_exists('imagecreatefromjpeg')) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_LIBARY_NOT_INSTALLED'); return false; } if (!function_exists('imagecreatetruecolor')) { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_GD_NO_TRUECOLOR'); return false; } if ($imginfo[2] == 'JPG') { $src_img = imagecreatefromjpeg($src_file); } else { if ($imginfo[2] == 'PNG') { $src_img = imagecreatefrompng($src_file); } else { $src_img = imagecreatefromgif($src_file); } } if (!$src_img) { return false; } $dst_img = imagecreatetruecolor($destWidth, $destHeight); if ($config->jg_fastgd2thumbcreation == 0) { if (!is_null($offsetx) && !is_null($offsety)) { imagecopyresampled($dst_img, $src_img, 0, 0, $offsetx, $offsety, $destWidth, (int) $destHeight, $srcWidth, $srcHeight); } else { imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight); } } else { if (!is_null($offsetx) && !is_null($offsety)) { JoomFile::fastImageCopyResampled($dst_img, $src_img, 0, 0, $offsetx, $offsety, $destWidth, (int) $destHeight, $srcWidth, $srcHeight); } else { JoomFile::fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int) $destHeight, $srcWidth, $srcHeight); } } if (!@imagejpeg($dst_img, $dest_file, $dest_qual)) { // Workaround for servers with wwwrun problem $dir = dirname($dest_file); JoomFile::chmod($dir, '0777', true); imagejpeg($dst_img, $dest_file, $dest_qual); JoomFile::chmod($dir, '0755', true); } imagedestroy($src_img); imagedestroy($dst_img); break; case 'im': $disabled_functions = explode(',', ini_get('disabled_functions')); foreach ($disabled_functions as $disabled_function) { if (trim($disabled_function) == 'exec') { $debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_EXEC_DISABLED') . '<br />'; return false; } } if (!empty($config->jg_impath)) { $convert_path = $config->jg_impath . 'convert'; } else { $convert_path = 'convert'; } $commands = ''; // Crop the source image before resiszing if offsets setted before // example of crop: convert input -crop destwidthxdestheight+offsetx+offsety +repage output // +repage needed to delete the canvas if (!is_null($offsetx) && !is_null($offsety)) { $commands .= ' -crop "' . $srcWidth . 'x' . $srcHeight . '+' . $offsetx . '+' . $offsety . '" +repage'; } // Finally the resize $commands .= ' -resize "' . $destWidth . 'x' . $destHeight . '" -quality "' . $dest_qual . '" -unsharp "3.5x1.2+1.0+0.10"'; $convert = $convert_path . ' ' . $commands . ' "' . $src_file . '" "' . $dest_file . '"'; $return_var = null; $dummy = null; @exec($convert, $dummy, $return_var); if ($return_var != 0) { // Workaround for servers with wwwrun problem $dir = dirname($dest_file); JoomFile::chmod($dir, '0777', true); @exec($convert, $dummy, $return_var); JoomFile::chmod($dir, '0755', true); if ($return_var != 0) { return false; } } break; default: JError::raiseError(500, JText::_('COM_JOOMGALLERY_UPLOAD_UNSUPPORTED_RESIZING_METHOD')); break; } // Set mode of uploaded picture JPath::setPermissions($dest_file); // We check that the image is valid $imginfo = getimagesize($dest_file); if (!$imginfo) { return false; } return true; }
/** * Creates a new category out of the information of the given object * * @param object $obj Should hold all the information about the new category * @param int The ID of the new category, false, if an error occured * @since 1.5.0 */ public function createCategory($obj) { jimport('joomla.filesystem.file'); JLoader::register('JoomFile', JPATH_ADMINISTRATOR . '/components/' . _JOOM_OPTION . '/helpers/file.php'); $row = JTable::getInstance('joomgallerycategories', 'Table'); $row->bind($obj); if (!$row->name) { $this->_mainframe->enqueueMessage(JText::_('No valid category name given'), 'error'); return false; } $row->parent_id = (int) $row->parent_id; if ($row->parent_id < 1) { $row->parent_id = 1; } // Determine location in category tree if (!isset($obj->ordering) || !$obj->ordering || $obj->ordering == 'first-child') { $row->setLocation($row->parent_id, 'first-child'); } else { if ($obj->ordering == 'last-child') { $row->setLocation($row->parent_id, 'last-child'); } else { $row->setLocation($obj->ordering, 'after'); } } // Ensure that the data is valid if (!$row->check()) { $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } // Store the data in the database if (!$row->store()) { $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } // Now we have the ID of the new category // and the catpath can be built $row->catpath = JoomFile::fixFilename($row->name) . '_' . $row->cid; if ($row->parent_id > 1) { $row->catpath = JoomHelper::getCatPath($row->parent_id) . $row->catpath; } // So store again, but afore let's create the alias $row->check(); if (!$row->store()) { $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } // Create necessary folders and files $origpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_pathoriginalimages') . $row->catpath; $imgpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_pathimages') . $row->catpath; $thumbpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_paththumbs') . $row->catpath; $result = array(); $result[] = JFolder::create($origpath); $result[] = JoomFile::copyIndexHtml($origpath); $result[] = JFolder::create($imgpath); $result[] = JoomFile::copyIndexHtml($imgpath); $result[] = JFolder::create($thumbpath); $result[] = JoomFile::copyIndexHtml($thumbpath); if (in_array(false, $result)) { // Delete the just stored database entry $row->delete(); return false; } else { // New category successfully created return $row->cid; } }
/** * Install method * * @return boolean True on success, false otherwise * @since 2.0 */ public function install() { $app = JFactory::getApplication(); jimport('joomla.filesystem.file'); // Create image directories require_once JPATH_ADMINISTRATOR . '/components/com_joomgallery/helpers/file.php'; $thumbpath = JPATH_ROOT . '/images/joomgallery/thumbnails'; $imgpath = JPATH_ROOT . '/images/joomgallery/details'; $origpath = JPATH_ROOT . '/images/joomgallery/originals'; $result = array(); $result[] = JFolder::create($thumbpath); $result[] = JoomFile::copyIndexHtml($thumbpath); $result[] = JFolder::create($imgpath); $result[] = JoomFile::copyIndexHtml($imgpath); $result[] = JFolder::create($origpath); $result[] = JoomFile::copyIndexHtml($origpath); $result[] = JoomFile::copyIndexHtml(JPATH_ROOT . '/images/joomgallery'); if (in_array(false, $result)) { $app->enqueueMessage(JText::_('Unable to create image directories!'), 'error'); return false; } // Create news feed module $subdomain = ''; $language = JFactory::getLanguage(); if (strpos($language->getTag(), 'de-') === false) { $subdomain = 'en.'; } $row = JTable::getInstance('module'); $row->title = 'JoomGallery News'; $row->ordering = 1; $row->position = 'joom_cpanel'; $row->published = 1; $row->module = 'mod_feed'; $row->access = $app->getCfg('access'); $row->showtitle = 1; $row->params = 'cache=1 cache_time=15 moduleclass_sfx= rssurl=http://www.' . $subdomain . 'joomgallery.net/feed/rss.html rssrtl=0 rsstitle=1 rssdesc=0 rssimage=1 rssitems=3 rssitemdesc=1 word_count=200'; $row->client_id = 1; $row->language = '*'; if (!$row->store()) { $app->enqueueMessage(JText::_('Unable to insert feed module data!'), 'error'); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->insert('#__modules_menu'); $query->set('moduleid = ' . $row->id); $query->set('menuid = 0'); $db->setQuery($query); if (!$db->query()) { $app->enqueueMessage(JText::_('Unable to assign feed module!'), 'error'); } // joom_settings.css $temp = JPATH_ROOT . '/media/joomgallery/css/joom_settings.temp.css'; $dest = JPATH_ROOT . '/media/joomgallery/css/joom_settings.css'; if (!JFile::move($temp, $dest)) { $app->enqueueMessage(JText::_('Unable to copy joom_settings.css!'), 'error'); return false; } ?> <div class="hero-unit"> <img src="../media/joomgallery/images/joom_logo.png" alt="JoomGallery Logo" /> <div class="alert alert-success"> <h3>JoomGallery <?php echo $this->version; ?> was installed successfully.</h3> </div> <p>You may now start using JoomGallery or download specific language files afore:</p> <p> <a title="Start" class="btn" onclick="location.href='index.php?option=com_joomgallery'; return false;" href="#">Start now!</a> <a title="Languages" class="btn btn-primary" onclick="location.href='index.php?option=com_joomgallery&controller=help'; return false;" href="#">Languages</a> </p> </div> <?php }
/** * Creates the folders for a category * * @param string The category path for the category * @return boolean True on success, false otherwise * @since 1.5.5 */ protected function _createFolders($catpath) { $catpath = JPath::clean($catpath); // Create the folder of the category for the original images if (!JFolder::create($this->_ambit->get('orig_path') . $catpath)) { // If not successfull return false; } else { // Copy an index.html file into the new folder JoomFile::copyIndexHtml($this->_ambit->get('orig_path') . $catpath); // Create the folder of the category for the detail images if (!JFolder::create($this->_ambit->get('img_path') . $catpath)) { // If not successful JFolder::delete($this->_ambit->get('orig_path') . $catpath); return false; } else { // Copy an index.html file into the new folder JoomFile::copyIndexHtml($this->_ambit->get('img_path') . $catpath); // Create the folder of the category for the thumbnails if (!JFolder::create($this->_ambit->get('thumb_path') . $catpath)) { // If not successful JFolder::delete($this->_ambit->get('orig_path') . $catpath); JFolder::delete($this->_ambit->get('img_path') . $catpath); return false; } else { // Copy an index.html file into the new folder JoomFile::copyIndexHtml($this->_ambit->get('thumb_path') . $catpath); } } } return true; }
/** * 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; }