Example #1
0
 private function _validImage($image)
 {
     $config = CFactory::getConfig();
     if ($image['error'] > 0 && $image['error'] !== 'UPLOAD_ERR_OK') {
         $this->setError(JText::sprintf('COM_COMMUNITY_PHOTOS_UPLOAD_ERROR', $image['error']));
         return false;
     }
     if (empty($image['tmp_name'])) {
         $this->setError(JText::_('COM_COMMUNITY_PHOTOS_MISSING_FILENAME_ERROR'));
         return false;
     }
     // This is only applicable for html uploader because flash uploader uploads all 'files' as application/octet-stream
     //if( !$config->get('flashuploader') && !CImageHelper::isValidType( $image['type'] ) )
     if (!CImageHelper::isValidType($image['type'])) {
         $this->setError(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         return false;
     }
     if (!CImageHelper::isMemoryNeededExceed($image['tmp_name'])) {
         $this->setError(JText::_('COM_COMMUNITY_IMAGE_NOT_ENOUGH_MEMORY'));
         return false;
     }
     if (!CImageHelper::isValid($image['tmp_name'])) {
         $this->setError(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         return false;
     }
     return true;
 }
Example #2
0
/**
 * Deprecated since 1.8
 * Use CImageHelper::isValid instead. 
 */
function cValidImage($file)
{
    return CImageHelper::isValid($file);
}
Example #3
0
 /**
  * Step 5
  * Upload a new user avatar
  */
 public function registerAvatar()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $mySess = JFactory::getSession();
     $user = $mySess->get('tmpUser', '');
     /* Just for incase this's incomplete object */
     if (!is_object($user) && gettype($user) == 'object') {
         $user = unserialize(serialize($user));
     }
     if (empty($user)) {
         //throw error.
         JError::raiseError(500, JText::_('COM_COMMUNITY_REGISTRATION_MISSING_USER_OBJ'));
         return;
     }
     $view = $this->getView('register');
     $profileType = JRequest::getInt('profileType', 0);
     // If uplaod is detected, we process the uploaded avatar
     if ($jinput->post->get('action', '')) {
         $my = CFactory::getUser($user->id);
         $fileFilter = new JInput($_FILES);
         $file = $fileFilter->get('Filedata', '', 'array');
         if ($my->id == 0) {
             return $this->blockUnregister();
         }
         if (!CImageHelper::isValidType($file['type'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             $url = $profileType !== 0 ? CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false) : CRoute::_('index.php?option=com_community&view=register&task=registerAvatar', false);
             $mainframe->redirect($url);
             return;
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error');
         } else {
             $config = CFactory::getConfig();
             $uploadLimit = (double) $config->get('maxuploadsize');
             $uploadLimit = $uploadLimit * 1024 * 1024;
             if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                 $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), 'error');
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerAvatar&profileType=' . $profileType, false));
             }
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             } else {
                 $config = CFactory::getConfig();
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') ? true : false;
                 // @todo: configurable width?
                 $imageMaxWidth = 160;
                 // Get a hash for the file name.
                 $fileName = JApplication::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 //@todo: configurable path for avatar storage?
                 $config = CFactory::getConfig();
                 $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar';
                 $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 // Generate full image
                 if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
                 }
                 if ($useWatermark) {
                     if (!JFolder::exists(JPATH_ROOT . '/images/watermarks/original')) {
                         JFolder::create(JPATH_ROOT . '/images/watermarks/original');
                     }
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
                     $multiprofile->load($profileType);
                     if ($multiprofile->watermark) {
                         $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
                         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                         list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                         list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                         $watermarkImage = $storageImage;
                         $watermarkThumbnail = $storageThumbnail;
                         // Avatar Properties
                         $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                         // The original image file will be removed from the system once it generates a new watermark image.
                         CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                         //Thumbnail Properties
                         $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                         // The original thumbnail file will be removed from the system once it generates a new watermark image.
                         CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                         $my->set('_watermark_hash', $multiprofile->watermark_hash);
                         $my->save();
                     }
                 }
                 // Since this is a new registration, we definitely do not want to remove the old image.
                 $removeOldImage = false;
                 $userModel->setImage($my->id, $image, 'avatar', $removeOldImage);
                 $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage);
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
Example #4
0
 /**
  * Upload a new user avatar, called from the profile/change avatar page
  */
 public function uploadAvatar()
 {
     CFactory::setActiveProfile();
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $view = $this->getView('profile');
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     // If uplaod is detected, we process the uploaded avatar
     if ($jinput->post->get('action', '')) {
         $mainframe = JFactory::getApplication();
         $fileFilter = new JInput($_FILES);
         $file = $fileFilter->get('Filedata', '', 'array');
         $userid = $my->id;
         if ($jinput->post->get('userid', '', 'INT') != '') {
             $userid = JRequest::getInt('userid', '', 'POST');
             $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid);
             $my = CFactory::getUser($userid);
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error');
             if (isset($url)) {
                 $mainframe->redirect($url);
             }
         } else {
             $config = CFactory::getConfig();
             $uploadLimit = (double) $config->get('maxuploadsize');
             $uploadLimit = $uploadLimit * 1024 * 1024;
             // @rule: Limit image size based on the maximum upload allowed.
             if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                 $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValidType($file['type'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
             } else {
                 // @todo: configurable width?
                 //$imageMaxWidth    = 160;
                 //$imageMaxHeight   = 240;
                 // Get a hash for the file name.
                 $profileType = $my->getProfileType();
                 $fileName = JApplication::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
                 $multiprofile->load($profileType);
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
                 //@todo: configurable path for avatar storage?
                 $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar';
                 /* physical path */
                 $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 /**
                  * reverse image use for cropping feature
                  * @uses <type>-<hashFileName>.<ext>
                  */
                 $storageReserve = $storage . '/profile-' . $hashFileName . CImageHelper::getExtension($file['type']);
                 /* relative path to save in database */
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 // filename for stream attachment
                 $imageAttachment = $config->getString('imagefolder') . '/avatar/' . $hashFileName . '_stream_' . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 //Minimum height/width checking for Avatar uploads
                 list($currentWidth, $currentHeight) = getimagesize($file['tmp_name']);
                 /**
                  * Do square avatar 160x160
                  * @since 3.0
                  */
                 if ($currentWidth < COMMUNITY_AVATAR_PROFILE_WIDTH || $currentHeight < COMMUNITY_AVATAR_PROFILE_HEIGHT) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MINIMUM_AVATAR_DIMENSION', COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT), 'error');
                     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=uploadAvatar', false));
                 }
                 //					// Only resize when the width exceeds the max.
                 //					if ( ! CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth, $imageMaxHeight))
                 //					{
                 //						$mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                 //
                 //						if (isset($url))
                 //						{
                 //							$mainframe->redirect($url);
                 //						}
                 //					}
                 /**
                  * Generate square avatar
                  */
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageImage, $file['type'], COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT)) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 /**
                  * Generate large image use for avatar thumb cropping
                  * It must be larget than profile avatar size because we'll use it for profile avatar recrop also
                  */
                 if ($currentWidth >= $currentHeight) {
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageReserve, $file['type'], 0, COMMUNITY_AVATAR_RESERVE_HEIGHT)) {
                         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageReserve));
                         return;
                     }
                 } else {
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageReserve, $file['type'], COMMUNITY_AVATAR_RESERVE_WIDTH, 0)) {
                         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageReserve));
                         return;
                     }
                 }
                 if ($useWatermark) {
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     if (!JFolder::exists(JPATH_ROOT . '/images/watermarks/original/')) {
                         JFolder::create(JPATH_ROOT . '/images/watermarks/original/');
                     }
                     JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
                     list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                     list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                     list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                     $watermarkImage = $storageImage;
                     $watermarkThumbnail = $storageThumbnail;
                     // Avatar Properties
                     $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                     // The original image file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                     //Thumbnail Properties
                     $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                     // The original thumbnail file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                     $my->set('_watermark_hash', $multiprofile->watermark_hash);
                     $my->save();
                 }
                 // Autorotate avatar based on EXIF orientation value
                 if ($file['type'] == 'image/jpeg') {
                     $orientation = CImageHelper::getOrientation($file['tmp_name']);
                     CImageHelper::autoRotate($storageImage, $orientation);
                     CImageHelper::autoRotate($storageThumbnail, $orientation);
                     CImageHelper::autoRotate($storageReserve, $orientation);
                 }
                 // @todo: Change to use table code and get rid of model code
                 $userModel->setImage($userid, $image, 'avatar');
                 $userModel->setImage($userid, $thumbnail, 'thumb');
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
                 // @rule: once user changes their profile picture, storage method should always be file.
                 $my->set('_storage', 'file');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 // Generate activity stream.
                 $this->_addAvatarUploadActivity($userid, $thumbnail);
                 $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES, COMMUNITY_CACHE_TAG_FRONTPAGE));
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
Example #5
0
 private function _validImage($image)
 {
     CFactory::load('helpers', 'image');
     $config = CFactory::getConfig();
     if ($image['error'] > 0 && $image['error'] !== 'UPLOAD_ERR_OK') {
         $this->setError('Upload Error ' . $image['error']);
         return false;
     }
     if (empty($image['tmp_name'])) {
         $this->setError('Missing upload filename');
         return false;
     }
     // This is only applicable for html uploader because flash uploader uploads all 'files' as application/octet-stream
     //if( !$config->get('flashuploader') && !CImageHelper::isValidType( $image['type'] ) )
     //{
     //	$this->setError(JText::_('CC IMAGE FILE NOT SUPPORTED'));
     //	return false;
     //}
     if (!CImageHelper::isValid($image['tmp_name'])) {
         $this->setError(JText::_('CC IMAGE FILE NOT SUPPORTED'));
         return false;
     }
     return true;
 }
Example #6
0
 /**
  * Upload a new user avatar
  */
 public function registerAvatar()
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $mySess =& JFactory::getSession();
     $user = $mySess->get('tmpUser', '');
     if (empty($user)) {
         //throw error.
         JError::raiseError(500, JText::_('CC REGISTRATION MISSING USER OBJ'));
         return;
     }
     //CFactory::setActiveProfile($user->id);
     $view =& $this->getView('register');
     CFactory::load('helpers', 'image');
     $profileType = JRequest::getInt('profileType', 0);
     // If uplaod is detected, we process the uploaded avatar
     if (JRequest::getVar('action', '', 'POST')) {
         // Load avatar library
         CFactory::load('libraries', 'avatar');
         $my = CFactory::getUser($user->id);
         $file = JRequest::getVar('Filedata', '', 'FILES', 'array');
         if ($my->id == 0) {
             return $this->blockUnregister();
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error');
         } else {
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
             } else {
                 $config = CFactory::getConfig();
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') ? true : false;
                 // @todo: configurable width?
                 $imageMaxWidth = 160;
                 // Get a hash for the file name.
                 $fileName = JUtility::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 //@todo: configurable path for avatar storage?
                 $config = CFactory::getConfig();
                 $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar';
                 $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 // Generate full image
                 if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error');
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error');
                 }
                 if ($useWatermark) {
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     JFile::copy($storageImage, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
                     $multiprofile->load($profileType);
                     $watermarkPath = JPATH_ROOT . DS . JString::str_ireplace('/', DS, $multiprofile->watermark);
                     list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                     list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                     list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                     $watermarkImage = $storageImage;
                     $watermarkThumbnail = $storageThumbnail;
                     // Avatar Properties
                     $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                     // The original image file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageImage, $watermarkImage, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                     //Thumbnail Properties
                     $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                     // The original thumbnail file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, 'image/jpg', $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                     $my->set('_watermark_hash', $multiprofile->watermark_hash);
                     $my->save();
                 }
                 // Since this is a new registration, we definitely do not want to remove the old image.
                 $removeOldImage = false;
                 $userModel->setImage($my->id, $image, 'avatar', $removeOldImage);
                 $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage);
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
             }
         }
         //redirect to successful page
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=register&task=registerSucess&profileType=' . $profileType, false));
     }
     echo $view->get(__FUNCTION__);
 }
Example #7
0
 public function uploadAvatar()
 {
     $mainframe =& JFactory::getApplication();
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     $view =& $this->getView($viewName, '', $viewType);
     $eventid = JRequest::getInt('eventid', '0', 'REQUEST');
     $model =& $this->getModel('events');
     $event =& JTable::getInstance('Event', 'CTable');
     $event->load($eventid);
     CFactory::load('helpers', 'event');
     $handler = CEventHelper::getHandler($event);
     if (!$handler->manageable()) {
         echo JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN');
         return;
     }
     if (JRequest::getMethod() == 'POST') {
         JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
         CFactory::load('libraries', 'apps');
         $my = CFactory::getUser();
         $config = CFactory::getConfig();
         $appsLib =& CAppPlugins::getInstance();
         $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-events-uploadavatar'));
         if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
             CFactory::load('helpers', 'image');
             $file = JRequest::getVar('filedata', '', 'FILES', 'array');
             if (!CImageHelper::isValidType($file['type'])) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                 $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id . '&task=uploadAvatar', false));
             }
             if (empty($file)) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error');
             } else {
                 $uploadLimit = (double) $config->get('maxuploadsize');
                 $uploadLimit = $uploadLimit * 1024 * 1024;
                 // @rule: Limit image size based on the maximum upload allowed.
                 if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                     $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED'), 'error');
                     $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false));
                 }
                 if (!CImageHelper::isValid($file['tmp_name'])) {
                     $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                     $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false));
                 } else {
                     // @todo: configurable width?
                     $imageMaxWidth = 160;
                     // Get a hash for the file name.
                     $fileName = JUtility::getHash($file['tmp_name'] . time());
                     $hashFileName = JString::substr($fileName, 0, 24);
                     // @todo: configurable path for avatar storage?
                     $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar' . DS . 'events';
                     $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
                     $image = $config->getString('imagefolder') . '/avatar/events/' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $thumbnail = $config->getString('imagefolder') . '/avatar/events/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                     // Generate full image
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false));
                     }
                     // Generate thumbnail
                     if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=uploadavatar&eventid=' . $event->id, false));
                     }
                     // Update the event with the new image
                     $event->setImage($image, 'avatar');
                     $event->setImage($thumbnail, 'thumb');
                     CFactory::load('helpers', 'event');
                     $handler = CEventHelper::getHandler($event);
                     if ($handler->isPublic()) {
                         $actor = $my->id;
                         $target = 0;
                         $content = '<img class="event-thumb" src="' . rtrim(JURI::root(), '/') . '/' . $image . '" style="border: 1px solid #eee;margin-right: 3px;" />';
                         $cid = $event->id;
                         $app = 'events';
                         $act = $handler->getActivity('events.avatar.upload', $actor, $target, $content, $cid, $app);
                         $act->eventid = $event->id;
                         $params = new CParameter('');
                         $params->set('event_url', $handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false, true, false));
                         CFactory::load('libraries', 'activities');
                         CActivityStream::add($act, $params->toString());
                     }
                     //add user points
                     CFactory::load('libraries', 'userpoints');
                     CUserPoints::assignPoint('event.avatar.upload');
                     //$this->cacheClean( array(COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_FRONTPAGE,COMMUNITY_CACHE_TAG_ACTIVITIES) );
                     $mainframe =& JFactory::getApplication();
                     $mainframe->redirect($handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $eventid, false), JText::_('COM_COMMUNITY_EVENTS_AVATAR_UPLOADED'));
                     exit;
                 }
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
Example #8
0
 /**
  * Upload a new user avatar
  */
 public function uploadAvatar()
 {
     CFactory::setActiveProfile();
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.utility');
     $view =& $this->getView('profile');
     CFactory::load('helpers', 'image');
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     // If uplaod is detected, we process the uploaded avatar
     if (JRequest::getVar('action', '', 'POST')) {
         $mainframe =& JFactory::getApplication();
         $file = JRequest::getVar('Filedata', '', 'FILES', 'array');
         $userid = $my->id;
         if (JRequest::getVar('userid', '', 'POST') != '') {
             $userid = JRequest::getInt('userid', '', 'POST');
             $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid);
         }
         if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
             $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error');
             if (isset($url)) {
                 $mainframe->redirect($url);
             }
         } else {
             $config = CFactory::getConfig();
             $uploadLimit = (double) $config->get('maxuploadsize');
             $uploadLimit = $uploadLimit * 1024 * 1024;
             // @rule: Limit image size based on the maximum upload allowed.
             if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE SIZE EXCEEDED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValidType($file['type'])) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid . '&task=uploadAvatar', false));
             }
             if (!CImageHelper::isValid($file['tmp_name'])) {
                 $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
             } else {
                 // @todo: configurable width?
                 $imageMaxWidth = 160;
                 // Get a hash for the file name.
                 $profileType = $my->getProfileType();
                 $fileName = JUtility::getHash($file['tmp_name'] . time());
                 $hashFileName = JString::substr($fileName, 0, 24);
                 $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
                 $multiprofile->load($profileType);
                 $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
                 //@todo: configurable path for avatar storage?
                 $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar';
                 $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
                 $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                 $userModel = CFactory::getModel('user');
                 // Only resize when the width exceeds the max.
                 if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 // Generate thumbnail
                 if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                     $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error');
                     if (isset($url)) {
                         $mainframe->redirect($url);
                     }
                 }
                 if ($useWatermark) {
                     // @rule: Before adding the watermark, we should copy the user's original image so that when the admin tries to reset the avatar,
                     // it will be able to grab the original picture.
                     JFile::copy($storageImage, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type']));
                     JFile::copy($storageThumbnail, JPATH_ROOT . DS . 'images' . DS . 'watermarks' . DS . 'original' . DS . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type']));
                     $watermarkPath = JPATH_ROOT . DS . JString::str_ireplace('/', DS, $multiprofile->watermark);
                     list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
                     list($avatarWidth, $avatarHeight) = getimagesize($storageImage);
                     list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail);
                     $watermarkImage = $storageImage;
                     $watermarkThumbnail = $storageThumbnail;
                     // Avatar Properties
                     $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
                     // The original image file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageImage, $watermarkImage, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y);
                     //Thumbnail Properties
                     $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                     // The original thumbnail file will be removed from the system once it generates a new watermark image.
                     CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, 'image/jpg', $watermarkPath, $thumbPosition->x, $thumbPosition->y);
                     $my->set('_watermark_hash', $multiprofile->watermark_hash);
                     $my->save();
                 }
                 $userModel->setImage($userid, $image, 'avatar');
                 $userModel->setImage($userid, $thumbnail, 'thumb');
                 // Update the user object so that the profile picture gets updated.
                 $my->set('_avatar', $image);
                 $my->set('_thumb', $thumbnail);
                 // @rule: once user changes their profile picture, storage method should always be file.
                 $my->set('_storage', 'file');
                 if (isset($url)) {
                     $mainframe->redirect($url);
                 }
                 //add user points
                 CFactory::load('libraries', 'userpoints');
                 CFactory::load('libraries', 'activities');
                 $act = new stdClass();
                 $act->cmd = 'profile.avatar.upload';
                 $act->actor = $userid;
                 $act->target = 0;
                 $act->title = JText::_('CC ACTIVITIES NEW AVATAR');
                 $act->content = '';
                 $act->app = 'profile';
                 $act->cid = 0;
                 // Add activity logging
                 CFactory::load('libraries', 'activities');
                 CActivityStream::add($act);
                 CUserPoints::assignPoint('profile.avatar.upload');
             }
         }
     }
     echo $view->get(__FUNCTION__);
 }
Example #9
0
 public function uploadAvatar()
 {
     $mainframe =& JFactory::getApplication();
     $document =& JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     $view =& $this->getView($viewName, '', $viewType);
     $my =& JFactory::getUser();
     $config = CFactory::getConfig();
     $groupid = JRequest::getVar('groupid', '', 'REQUEST');
     $data = new stdClass();
     $data->id = $groupid;
     $groupsModel =& $this->getModel('groups');
     $group =& JTable::getInstance('Group', 'CTable');
     $group->load($groupid);
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     if (!$group->isAdmin($my->id) && !COwnerHelper::isCommunityAdmin()) {
         echo $view->noAccess();
         return;
     }
     if (JRequest::getMethod() == 'POST') {
         CFactory::load('helpers', 'image');
         $file = JRequest::getVar('filedata', '', 'FILES', 'array');
         if (!CImageHelper::isValidType($file['type'])) {
             $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id . '&task=uploadAvatar', false));
         }
         CFactory::load('libraries', 'apps');
         $appsLib =& CAppPlugins::getInstance();
         $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-uploadavatar'));
         if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
             if (empty($file)) {
                 $mainframe->enqueueMessage(JText::_('CC NO POST DATA'), 'error');
             } else {
                 $uploadLimit = (double) $config->get('maxuploadsize');
                 $uploadLimit = $uploadLimit * 1024 * 1024;
                 // @rule: Limit image size based on the maximum upload allowed.
                 if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                     $mainframe->enqueueMessage(JText::_('CC IMAGE FILE SIZE EXCEEDED'), 'error');
                     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=uploadavatar&groupid=' . $group->id, false));
                 }
                 if (!CImageHelper::isValid($file['tmp_name'])) {
                     $mainframe->enqueueMessage(JText::_('CC IMAGE FILE NOT SUPPORTED'), 'error');
                 } else {
                     // @todo: configurable width?
                     $imageMaxWidth = 160;
                     // Get a hash for the file name.
                     $fileName = JUtility::getHash($file['tmp_name'] . time());
                     $hashFileName = JString::substr($fileName, 0, 24);
                     // @todo: configurable path for avatar storage?
                     $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar' . DS . 'groups';
                     $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
                     $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $image = $config->getString('imagefolder') . '/avatar/groups/' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $thumbnail = $config->getString('imagefolder') . '/avatar/groups/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                     // Generate full image
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                         $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageImage), 'error');
                     }
                     // Generate thumbnail
                     if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                         $mainframe->enqueueMessage(JText::sprintf('CC ERROR MOVING UPLOADED FILE', $storageThumbnail), 'error');
                     }
                     // Update the group with the new image
                     $groupsModel->setImage($groupid, $image, 'avatar');
                     $groupsModel->setImage($groupid, $thumbnail, 'thumb');
                     // @rule: only add the activities of the news if the group is not private.
                     if ($group->approvals == COMMUNITY_PUBLIC_GROUP) {
                         $url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid);
                         $act = new stdClass();
                         $act->cmd = 'group.avatar.upload';
                         $act->actor = $my->id;
                         $act->target = 0;
                         $act->title = JText::sprintf('CC ACTIVITIES NEW GROUP AVATAR', '{group_url}', $group->name);
                         $act->content = '<img src="' . rtrim(JURI::root(), '/') . '/' . $thumbnail . '" style="border: 1px solid #eee;margin-right: 3px;" />';
                         $act->app = 'groups';
                         $act->cid = $group->id;
                         $params = new JParameter('');
                         $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id);
                         CFactory::load('libraries', 'activities');
                         CActivityStream::add($act, $params->toString());
                     }
                     //add user points
                     CFactory::load('libraries', 'userpoints');
                     CUserPoints::assignPoint('group.avatar.upload');
                     $mainframe =& JFactory::getApplication();
                     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid, false), JText::_('CC GROUP AVATAR UPLOADED'));
                     exit;
                 }
             }
         }
     }
     echo $view->get(__FUNCTION__, $data);
 }
Example #10
0
 public function uploadAvatar()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     $view = $this->getView($viewName, '', $viewType);
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $groupid = $jinput->request->get('groupid', '', 'INT');
     $data = new stdClass();
     $data->id = $groupid;
     $groupsModel = $this->getModel('groups');
     $group = JTable::getInstance('Group', 'CTable');
     $group->load($groupid);
     if (!$my->authorise('community.upload', 'groups.avatar.' . $groupid, $group)) {
         $errorMsg = $my->authoriseErrorMsg();
         if (!$errorMsg) {
             return $this->blockUnregister();
         } else {
             echo $errorMsg;
         }
         return;
     }
     if ($jinput->getMethod() == 'POST') {
         //CFactory::load( 'helpers' , 'image' );
         $fileFilter = new JInput($_FILES);
         $file = $fileFilter->get('filedata', '', 'array');
         //$file		= JRequest::getVar('filedata' , '' , 'FILES' , 'array');
         if (!CImageHelper::isValidType($file['type'])) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id . '&task=uploadAvatar', false));
         }
         //CFactory::load( 'libraries' , 'apps' );
         $appsLib = CAppPlugins::getInstance();
         $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-uploadavatar'));
         if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
             if (empty($file)) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_NO_POST_DATA'), 'error');
             } else {
                 $uploadLimit = (double) $config->get('maxuploadsize');
                 $uploadLimit = $uploadLimit * 1024 * 1024;
                 // @rule: Limit image size based on the maximum upload allowed.
                 if (filesize($file['tmp_name']) > $uploadLimit && $uploadLimit != 0) {
                     $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize')), 'error');
                     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=uploadavatar&groupid=' . $group->id, false));
                 }
                 if (!CImageHelper::isValid($file['tmp_name'])) {
                     $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'), 'error');
                 } else {
                     // @todo: configurable width?
                     $imageMaxWidth = 160;
                     // Get a hash for the file name.
                     $fileName = JApplication::getHash($file['tmp_name'] . time());
                     $hashFileName = JString::substr($fileName, 0, 24);
                     // @todo: configurable path for avatar storage?
                     $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar/groups';
                     $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $image = $config->getString('imagefolder') . '/avatar/groups/' . $hashFileName . CImageHelper::getExtension($file['type']);
                     $thumbnail = $config->getString('imagefolder') . '/avatar/groups/' . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
                     // Generate full image
                     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
                     }
                     // Generate thumbnail
                     if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
                     }
                     // Autorotate avatar based on EXIF orientation value
                     if ($file['type'] == 'image/jpeg') {
                         $orientation = CImageHelper::getOrientation($file['tmp_name']);
                         CImageHelper::autoRotate($storageImage, $orientation);
                         CImageHelper::autoRotate($storageThumbnail, $orientation);
                     }
                     // Update the group with the new image
                     $groupsModel->setImage($groupid, $image, 'avatar');
                     $groupsModel->setImage($groupid, $thumbnail, 'thumb');
                     // @rule: only add the activities of the news if the group is not private.
                     if ($group->approvals == COMMUNITY_PUBLIC_GROUP) {
                         $url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid);
                         $act = new stdClass();
                         $act->cmd = 'group.avatar.upload';
                         $act->actor = $my->id;
                         $act->target = 0;
                         $act->title = JText::sprintf('COM_COMMUNITY_GROUPS_NEW_GROUP_AVATAR', '{group_url}', $group->name);
                         $act->content = '<img src="' . JURI::root(true) . '/' . $thumbnail . '" style="border: 1px solid #eee;margin-right: 3px;" />';
                         $act->app = 'groups';
                         $act->cid = $group->id;
                         $act->groupid = $group->id;
                         $params = new CParameter('');
                         $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id);
                         CActivityStream::add($act, $params->toString());
                     }
                     //add user points
                     //CFactory::load( 'libraries' , 'userpoints' );
                     CUserPoints::assignPoint('group.avatar.upload');
                     $mainframe = JFactory::getApplication();
                     $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid, false), JText::_('COM_COMMUNITY_GROUPS_AVATAR_UPLOADED'));
                     exit;
                 }
             }
         }
     }
     //ClearCache in frontpage
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_ACTIVITIES));
     echo $view->get(__FUNCTION__, $data);
 }