예제 #1
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__);
 }
예제 #2
0
파일: photos.php 프로젝트: bizanto/Hooked
 public function upload()
 {
     $my = $this->plugin->get('user');
     $config = CFactory::getConfig();
     $returns = array();
     // Load up required models and properties
     CFactory::load('controllers', 'photos');
     CFactory::load('libraries', 'photos');
     CFactory::load('models', 'photos');
     CFactory::load('helpers', 'image');
     $photos = JRequest::get('Files');
     $albumId = JRequest::getVar('albumid', '', 'REQUEST');
     $album =& JTable::getInstance('Album', 'CTable');
     $album->load($albumId);
     $handler = $this->_getHandler($album);
     foreach ($photos as $imageFile) {
         if (!$this->_validImage($imageFile)) {
             $this->_showUploadError(true, $this->getError());
             return;
         }
         if ($this->_imageLimitExceeded(filesize($imageFile['tmp_name']))) {
             $this->_showUploadError(true, JText::_('CC IMAGE FILE SIZE EXCEEDED'));
             return;
         }
         // We need to read the filetype as uploaded always return application/octet-stream
         // regardless od the actual file type
         $info = getimagesize($imageFile['tmp_name']);
         $isDefaultPhoto = JRequest::getVar('defaultphoto', false, 'REQUEST');
         if ($album->id == 0 || $my->id != $album->creator && $album->type != PHOTOS_GROUP_TYPE) {
             $this->_showUploadError(true, JText::_('CC INVALID ALBUM'));
             return;
         }
         if (!$album->hasAccess($my->id, 'upload')) {
             $this->_showUploadError(true, JText::_('CC INVALID ALBUM'));
             return;
         }
         // Hash the image file name so that it gets as unique possible
         $fileName = JUtility::getHash($imageFile['tmp_name'] . time());
         $hashFilename = JString::substr($fileName, 0, 24);
         $imgType = image_type_to_mime_type($info[2]);
         // Load the tables
         $photoTable =& JTable::getInstance('Photo', 'CTable');
         // @todo: configurable paths?
         $storage = JPATH_ROOT . DS . $config->getString('photofolder');
         $albumPath = empty($album->path) ? '' : $album->id . DS;
         // Test if the photos path really exists.
         jimport('joomla.filesystem.file');
         jimport('joomla.filesystem.folder');
         CFactory::load('helpers', 'limits');
         $originalPath = $handler->getOriginalPath($storage, $albumPath, $album->id);
         CFactory::load('helpers', 'owner');
         // @rule: Just in case user tries to exploit the system, we should prevent this from even happening.
         if ($handler->isExceedUploadLimit() && !COwnerHelper::isCommunityAdmin()) {
             $config = CFactory::getConfig();
             $photoLimit = $config->get('groupphotouploadlimit');
             echo JText::sprintf('CC GROUP PHOTO UPLOAD LIMIT REACHED', $photoLimit);
             return;
         }
         if (!JFolder::exists($originalPath)) {
             if (!JFolder::create($originalPath, (int) octdec($config->get('folderpermissionsphoto')))) {
                 $this->_showUploadError(true, JText::_('CC ERROR CREATING USERS PHOTO FOLDER'));
                 return;
             }
         }
         $locationPath = $handler->getLocationPath($storage, $albumPath, $album->id);
         if (!JFolder::exists($locationPath)) {
             if (!JFolder::create($locationPath, (int) octdec($config->get('folderpermissionsphoto')))) {
                 $this->_showUploadError(true, JText::_('CC ERROR CREATING USERS PHOTO FOLDER'));
                 return;
             }
         }
         $thumbPath = $handler->getThumbPath($storage, $album->id);
         $thumbPath = $thumbPath . DS . $albumPath . 'thumb_' . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         CPhotos::generateThumbnail($imageFile['tmp_name'], $thumbPath, $imgType);
         // Original photo need to be kept to make sure that, the gallery works
         $useAlbumId = empty($album->path) ? 0 : $album->id;
         $originalFile = $originalPath . $hashFilename . CImageHelper::getExtension($imgType);
         $this->_storeOriginal($imageFile['tmp_name'], $originalFile, $useAlbumId);
         $photoTable->original = JString::str_ireplace(JPATH_ROOT . DS, '', $originalFile);
         // Set photos properties
         $photoTable->albumid = $albumId;
         $photoTable->caption = $imageFile['name'];
         $photoTable->creator = $my->id;
         $photoTable->created = gmdate('Y-m-d H:i:s');
         // Remove the filename extension from the caption
         if (JString::strlen($photoTable->caption) > 4) {
             $photoTable->caption = JString::substr($photoTable->caption, 0, JString::strlen($photoTable->caption) - 4);
         }
         // @todo: configurable options?
         // Permission should follow album permission
         $photoTable->published = '1';
         $photoTable->permissions = $album->permissions;
         // Set the relative path.
         // @todo: configurable path?
         $storedPath = $handler->getStoredPath($storage, $albumId);
         $storedPath = $storedPath . DS . $albumPath . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         $photoTable->image = JString::str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         $photoTable->thumbnail = JString::str_ireplace(JPATH_ROOT . DS, '', $thumbPath);
         //photo filesize, use sprintf to prevent return of unexpected results for large file.
         $photoTable->filesize = sprintf("%u", filesize($originalPath));
         // @rule: Set the proper ordering for the next photo upload.
         $photoTable->setOrdering();
         // Store the object
         $photoTable->store();
         // We need to see if we need to rotate this image, from EXIF orientation data
         // Only for jpeg image.
         if ($config->get('photos_auto_rotate') && $imgType == 'image/jpeg') {
             // Read orientation data from original file
             $orientation = CImageHelper::getOrientation($imageFile['tmp_name']);
             //echo $orientation; exit;
             // A newly uplaoded image might not be resized yet, do it now
             $displayWidth = $config->getInt('photodisplaysize');
             JRequest::setVar('imgid', $photoTable->id, 'GET');
             JRequest::setVar('maxW', $displayWidth, 'GET');
             JRequest::setVar('maxH', $displayWidth, 'GET');
             $this->showimage(false);
             // Rotata resized files ince it is smaller
             switch ($orientation) {
                 case 1:
                     // nothing
                     break;
                 case 2:
                     // horizontal flip
                     // $image->flipImage($public,1);
                     break;
                 case 3:
                     // 180 rotate left
                     //  $image->rotateImage($public,180);
                     CImageHelper::rotate($storedPath, $storedPath, 180);
                     CImageHelper::rotate($thumbPath, $thumbPath, 180);
                     break;
                 case 4:
                     // vertical flip
                     //  $image->flipImage($public,2);
                     break;
                 case 5:
                     // vertical flip + 90 rotate right
                     //$image->flipImage($public, 2);
                     //$image->rotateImage($public, -90);
                     break;
                 case 6:
                     // 90 rotate right
                     // $image->rotateImage($public, -90);
                     CImageHelper::rotate($storedPath, $storedPath, -90);
                     CImageHelper::rotate($thumbPath, $thumbPath, -90);
                     break;
                 case 7:
                     // horizontal flip + 90 rotate right
                     // 			            $image->flipImage($public,1);
                     // 			            $image->rotateImage($public, -90);
                     break;
                 case 8:
                     // 90 rotate left
                     // 			            $image->rotateImage($public, 90);
                     CImageHelper::rotate($storedPath, $storedPath, 90);
                     CImageHelper::rotate($thumbPath, $thumbPath, 90);
                     break;
             }
         }
         // Trigger for onPhotoCreate
         CFactory::load('libraries', 'apps');
         $apps =& CAppPlugins::getInstance();
         $apps->loadApplications();
         $params = array();
         $params[] =& $photoTable;
         $apps->triggerEvent('onPhotoCreate', $params);
         // Set image as default if necessary
         // Load photo album table
         if ($isDefaultPhoto) {
             // Set the photo id
             $album->photoid = $photoTable->id;
             $album->store();
         }
         // @rule: Set first photo as default album cover if enabled
         if (!$isDefaultPhoto && $config->get('autoalbumcover')) {
             $photosModel = CFactory::getModel('Photos');
             $totalPhotos = $photosModel->getTotalPhotos($album->id);
             if ($totalPhotos <= 1) {
                 $album->photoid = $photoTable->id;
                 $album->store();
             }
         }
         $act = new stdClass();
         $act->cmd = 'photo.upload';
         $act->actor = $my->id;
         $act->access = $my->getParam('privacyPhotoView');
         $act->target = 0;
         $act->title = JText::sprintf($handler->getUploadActivityTitle(), '{photo_url}', $album->name);
         $act->content = '<img src="' . rtrim(JURI::root(), '/') . '/' . $photoTable->thumbnail . '" style=\\"border: 1px solid #eee;margin-right: 3px;" />';
         $act->app = 'photos';
         $act->cid = $albumId;
         $params = new JParameter('');
         $params->set('multiUrl', $handler->getAlbumURI($albumId, false));
         $params->set('photoid', $photoTable->id);
         $params->set('action', 'upload');
         $params->set('photo_url', $handler->getPhotoURI($albumId, $photoTable->id, false));
         // Add activity logging
         CFactory::load('libraries', 'activities');
         CActivityStream::add($act, $params->toString());
         //add user points
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('photo.upload');
         // Photo upload was successfull, display a proper message
         //$this->_showUploadError( false , JText::sprintf('CC PHOTO UPLOADED SUCCESSFULLY', $photoTable->caption ) , $photoTable->getThumbURI(), $albumId );
         $returns[] = array('album_id' => $albumId, 'image_id' => $photoTable->id, 'caption' => $photoTable->caption, 'created' => $photoTable->created, 'storage' => $photoTable->storage, 'thumbnail' => $photoTable->getThumbURI(), 'image' => $photoTable->getImageURI());
     }
     return $returns;
     exit;
 }
예제 #3
0
파일: image.php 프로젝트: bizanto/Hooked
/**
 * Deprecated since 1.8
 * Use CImageHelper::getExtension instead. 
 */
function cImageTypeToExt($type)
{
    return CImageHelper::getExtension($type);
}
예제 #4
0
 public function save()
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $id = JRequest::getInt('id', 0, 'POST');
     $post = JRequest::get('POST');
     $fields = $jinput->get('fields', '', 'NONE');
     $name = $jinput->get('name', '', 'STRING');
     $tmpParents = $jinput->get('parents', '', 'NONE');
     $mainframe = JFactory::getApplication();
     $task = JRequest::getCmd('task');
     $isNew = $id == 0 ? true : false;
     $validated = true;
     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($id);
     // Skip watermarking if it's the same location
     $skipWatermark = isset($multiprofile->watermark_location) && isset($post['watermark_location']) && $post['watermark_location'] == $multiprofile->watermark_location ? true : false;
     // Bind with form post
     $multiprofile->bind($post);
     // Can't have an empty name now can we?
     if (empty($name)) {
         $validated = false;
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_NAME_EMPTY'), 'error');
     }
     $date = JFactory::getDate();
     $isNew = $multiprofile->id == 0 ? true : false;
     if ($isNew) {
         $multiprofile->created = $date->toSql();
     }
     // Store watermarks for profile types.
     $watermark = $jinput->files->get('watermark', '', 'NONE');
     //JRequest::getVar( 'watermark' , '' , 'FILES');
     if (!empty($watermark['tmp_name'])) {
         // Do not allow image size to exceed maximum width and height
         if (isset($watermark['name']) && !empty($watermark['name'])) {
             list($width, $height) = getimagesize($watermark['tmp_name']);
             /**
              * watermark can't large than 16px
              * @todo use define for min width & height instead fixed number here
              */
             if ($width > 16 || $height > 16) {
                 $validated = false;
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error');
             }
         }
     }
     if ($validated) {
         $multiprofile->store();
         // If image file is specified, we need to store the thumbnail.
         if (!empty($watermark['tmp_name'])) {
             if (isset($watermark['name']) && !empty($watermark['name'])) {
                 if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
                     JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH);
                 }
                 $watermarkFile = 'watermark_' . $multiprofile->id . CImageHelper::getExtension($watermark['type']);
                 JFile::copy($watermark['tmp_name'], JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $watermarkFile);
                 $multiprofile->watermark = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $watermarkFile;
                 $multiprofile->store();
             }
         }
         // @rule: Create the watermarks folder if doesn't exists.
         if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
             if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
             }
         }
         // @rule: Create original folder within watermarks to store original user photos.
         if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/original')) {
             if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/original')) {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
             }
         }
         if (!empty($watermark['tmp_name']) || !$isNew && !$skipWatermark) {
             if (isset($watermark['name']) && !empty($watermark['name'])) {
                 $watermarkPath = $watermark['tmp_name'];
                 $watermark_hash = md5($watermark['name'] . time());
             } else {
                 $watermarkPath = JPATH_ROOT . '/' . $multiprofile->watermark;
                 $watermark_hash = $multiprofile->watermark_hash;
             }
             // Create default watermarks for avatar and thumbnails.
             // Generate filename
             $fileName = CImageHelper::getHashName($multiprofile->id . time()) . '.jpg';
             $thumbFileName = 'thumb_' . $fileName;
             // Paths where the thumbnail and avatar should be saved.
             $thumbPath = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $thumbFileName;
             $avatarPath = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $fileName;
             // Copy existing default thumbnails into the path first.
             JFile::copy(JPATH_ROOT . '/' . DEFAULT_USER_THUMB, $thumbPath);
             JFile::copy(JPATH_ROOT . '/' . DEFAULT_USER_AVATAR, $avatarPath);
             $watermarkPath = $watermarkPath;
             list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
             $oldDefaultAvatar = $multiprofile->avatar;
             $oldDefaultThumb = $multiprofile->thumb;
             // Avatar Properties
             $avatarInfo = getimagesize($avatarPath);
             $avatarWidth = $avatarInfo[0];
             $avatarHeight = $avatarInfo[1];
             $avatarMime = $avatarInfo['mime'];
             $avatarPosition = $this->_getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
             CImageHelper::addWatermark($avatarPath, $avatarPath, $avatarMime, $watermarkPath, $avatarPosition->x, $avatarPosition->y);
             $multiprofile->avatar = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $fileName;
             // Thumbnail properties.
             $thumbInfo = getimagesize($thumbPath);
             $thumbWidth = $thumbInfo[0];
             $thumbHeight = $thumbInfo[1];
             $thumbMime = $thumbInfo['mime'];
             $thumbPosition = $this->_getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
             CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermarkPath, $thumbPosition->x, $thumbPosition->y);
             $multiprofile->thumb = CString::str_ireplace('/', '/', COMMUNITY_WATERMARKS_PATH) . '/' . $thumbFileName;
             // Since the default thumbnail is used by current users, we need to update their existing values.
             $multiprofile->updateUserDefaultImage('avatar', $oldDefaultAvatar);
             $multiprofile->updateUserDefaultImage('thumb', $oldDefaultThumb);
             $multiprofile->watermark_hash = $watermark_hash;
             $multiprofile->store();
         }
         // Since it would be very tedious to check if previous fields were enabled or disabled.
         // We delete all existing mapping and remap it again to ensure data integrity.
         if (!$isNew && empty($fields)) {
             $multiprofile->deleteChilds();
         }
         if (!empty($fields)) {
             $parents = array();
             // We need to unique the parents first.
             foreach ($fields as $id) {
                 $customProfile = JTable::getInstance('Profiles', 'CommunityTable');
                 $customProfile->load($id);
                 // Need to only
                 $parent = $customProfile->getCurrentParentId();
                 if (in_array($parent, $tmpParents)) {
                     $parents[] = $parent;
                 }
             }
             $parents = array_unique($parents);
             $fields = array_merge($fields, $parents);
             $fieldTable = JTable::getInstance('MultiProfileFields', 'CTable');
             $fieldTable->cleanField($multiprofile->id);
             foreach ($fields as $id) {
                 $field = JTable::getInstance('MultiProfileFields', 'CTable');
                 $field->parent = $multiprofile->id;
                 $field->field_id = $id;
                 $field->store();
             }
         }
         if ($isNew) {
             $message = JText::_('COM_COMMUNITY_MULTIPROFILE_CREATED_SUCCESSFULLY');
         } else {
             $message = JText::_('COM_COMMUNITY_MULTIPROFILE_UPDATED_SUCCESSFULLY');
         }
         switch ($task) {
             case 'apply':
                 $link = 'index.php?option=com_community&view=multiprofile&layout=edit&id=' . $multiprofile->id;
                 break;
             case 'save':
             default:
                 $link = 'index.php?option=com_community&view=multiprofile';
                 break;
         }
         $mainframe->redirect($link, $message, 'message');
         return;
     }
     $document = JFactory::getDocument();
     $viewName = JRequest::getCmd('view', 'community');
     // Get the view type
     $viewType = $document->getType();
     // Get the view
     $view = $this->getView($viewName, $viewType);
     $view->setLayout('edit');
     $model = $this->getModel('Profiles');
     if ($model) {
         $view->setModel($model, $viewName);
     }
     $view->display();
 }
예제 #5
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__);
 }
예제 #6
0
 public function save()
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     CFactory::load('helpers', 'image');
     $id = JRequest::getInt('id', 0, 'POST');
     $post = JRequest::get('POST');
     $fields = JRequest::getVar('fields', '');
     $name = JRequest::getVar('name', '');
     $tmpParents = JRequest::getVar('parents', '');
     $mainframe =& JFactory::getApplication();
     $isNew = $id == 0 ? true : false;
     $multiprofile =& JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($id);
     $multiprofile->bind($post);
     // Can't have an empty name now can we?
     if (empty($name)) {
         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_NAME_EMPTY'), 'error');
         $mainframe->redirect('index.php?option=com_community&view=multiprofile&layout=edit');
         return;
     }
     $date =& JFactory::getDate();
     $isNew = $multiprofile->id == 0;
     if ($isNew) {
         $multiprofile->created = $date->toMySQL();
     }
     // Store watermarks for profile types.
     $watermark = JRequest::getVar('watermark', '', 'FILES');
     // Do not allow image size to exceed maximum width and height
     if (isset($watermark['name']) && !empty($watermark['name'])) {
         list($width, $height) = getimagesize($watermark['tmp_name']);
         if ($width > 64 || $height > 64) {
             $mainframe->redirect('index.php?option=com_community&view=multiprofile&layout=edit', JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error');
             exit;
         }
     }
     $multiprofile->store();
     // If image file is specified, we need to store the thumbnail.
     if (isset($watermark['name']) && !empty($watermark['name'])) {
         $watermarkFile = 'watermark_' . $multiprofile->id . CImageHelper::getExtension($watermark['type']);
         JFile::copy($watermark['tmp_name'], JPATH_ROOT . DS . COMMUNITY_WATERMARKS_PATH . DS . $watermarkFile);
         $multiprofile->watermark = CString::str_ireplace(DS, '/', COMMUNITY_WATERMARKS_PATH) . '/' . $watermarkFile;
         $multiprofile->store();
     }
     // @rule: Create the watermarks folder if doesn't exists.
     if (!JFolder::exists(COMMUNITY_WATERMARKS_PATH)) {
         if (!JFolder::create(COMMUNITY_WATERMARKS_PATH)) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
         }
     }
     // @rule: Create original folder within watermarks to store original user photos.
     if (!JFolder::exists(COMMUNITY_WATERMARKS_PATH . DS . 'original')) {
         if (!JFolder::create(COMMUNITY_WATERMARKS_PATH . DS . 'original')) {
             $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
         }
     }
     // Create default watermarks for avatar and thumbnails.
     if (isset($watermark['name']) && !empty($watermark['name']) || !empty($multiprofile->watermark)) {
         CFactory::load('helpers', 'image');
         // Generate filename
         $fileName = CImageHelper::getHashName($multiprofile->id . time()) . '.jpg';
         $thumbFileName = 'thumb_' . $fileName;
         // Paths where the thumbnail and avatar should be saved.
         $thumbPath = JPATH_ROOT . DS . COMMUNITY_WATERMARKS_PATH . DS . $thumbFileName;
         $avatarPath = JPATH_ROOT . DS . COMMUNITY_WATERMARKS_PATH . DS . $fileName;
         // Copy existing default thumbnails into the path first.
         JFile::copy(JPATH_ROOT . DS . DEFAULT_USER_THUMB, $thumbPath);
         JFile::copy(JPATH_ROOT . DS . DEFAULT_USER_AVATAR, $avatarPath);
         $watermarkPath = $watermark['tmp_name'];
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
         $oldDefaultAvatar = $multiprofile->avatar;
         $oldDefaultThumb = $multiprofile->thumb;
         // Avatar Properties
         $avatarInfo = getimagesize($avatarPath);
         $avatarWidth = $avatarInfo[0];
         $avatarHeight = $avatarInfo[1];
         $avatarMime = $avatarInfo['mime'];
         $avatarPosition = $this->_getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
         CImageHelper::addWatermark($avatarPath, $avatarPath, 'image/jpg', $watermarkPath, $avatarPosition->x, $avatarPosition->y);
         $multiprofile->avatar = CString::str_ireplace(DS, '/', COMMUNITY_WATERMARKS_PATH) . '/' . $fileName;
         // Thumbnail properties.
         $thumbInfo = getimagesize($thumbPath);
         $thumbWidth = $thumbInfo[0];
         $thumbHeight = $thumbInfo[1];
         $thumbMime = $thumbInfo['mime'];
         $thumbPosition = $this->_getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
         CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermarkPath, $thumbPosition->x, $thumbPosition->y);
         $multiprofile->thumb = CString::str_ireplace(DS, '/', COMMUNITY_WATERMARKS_PATH) . '/' . $thumbFileName;
         // Since the default thumbnail is used by current users, we need to update their existing values.
         $multiprofile->updateUserDefaultImage('avatar', $oldDefaultAvatar);
         $multiprofile->updateUserDefaultImage('thumb', $oldDefaultThumb);
         $multiprofile->watermark_hash = md5($watermark['name'] . time());
         $multiprofile->store();
     }
     // Since it would be very tedious to check if previous fields were enabled or disabled.
     // We delete all existing mapping and remap it again to ensure data integrity.
     if (!$isNew && !empty($fields)) {
         $multiprofile->deleteChilds();
     }
     if (!empty($fields)) {
         $parents = array();
         // We need to unique the parents first.
         foreach ($fields as $id) {
             $customProfile =& JTable::getInstance('Profiles', 'CommunityTable');
             $customProfile->load($id);
             // Need to only
             $parent = $customProfile->getCurrentParentId();
             if (in_array($parent, $tmpParents)) {
                 $parents[] = $parent;
             }
         }
         $parents = array_unique($parents);
         $fields = array_merge($fields, $parents);
         foreach ($fields as $id) {
             $field =& JTable::getInstance('MultiProfileFields', 'CTable');
             $field->parent = $multiprofile->id;
             $field->field_id = $id;
             $field->store();
         }
     }
     $message = JText::_('COM_COMMUNITY_MULTIPROFILE_UPDATED_SUCCESSFULLY');
     if ($isNew) {
         $message = JText::_('COM_COMMUNITY_MULTIPROFILE_CREATED_SUCCESSFULLY');
     }
     $mainframe->redirect('index.php?option=com_community&view=multiprofile', $message);
 }
예제 #7
0
파일: register.php 프로젝트: bizanto/Hooked
 /**
  * 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__);
 }
예제 #8
0
파일: profile.php 프로젝트: bizanto/Hooked
 /**
  * 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__);
 }
예제 #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);
     $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__);
 }
예제 #10
0
 public function changeAvatar()
 {
     $objResponse = new JAXResponse();
     $type = JRequest::getVar('type');
     $id = JRequest::getVar('id');
     $filter = JFilterInput::getInstance();
     $type = $filter->clean($type, 'string');
     $id = $filter->clean($id, 'integer');
     $cTable =& JTable::getInstance(ucfirst($type), 'CTable');
     $cTable->load($id);
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     CFactory::load('helpers', 'image');
     $file = JRequest::getVar('filedata', '', 'FILES', 'array');
     //check if file is allwoed
     if (!CImageHelper::isValidType($file['type'])) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         return;
     }
     //check upload file size
     $uploadlimit = (double) $config->get('maxuploadsize');
     $uploadlimit = $uploadlimit * 1024 * 1024;
     if (filesize($file['tmp_name']) > $uploadlimit && $uploadlimit != 0) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED'));
         return;
     }
     //start image processing
     $imageMaxWidth = 160;
     // Get a hash for the file name.
     $fileName = JUtility::getHash($file['tmp_name'] . time());
     $hashFileName = JString::substr($fileName, 0, 24);
     $avatarFolder = $type != 'profile' && $type != '' ? $type . DS : '';
     //avatar store path
     $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar' . DS . $avatarFolder;
     $storageImage = $storage . DS . $hashFileName . CImageHelper::getExtension($file['type']);
     $image = $config->getString('imagefolder') . '/avatar/' . $avatarFolder . $hashFileName . CImageHelper::getExtension($file['type']);
     //avatar thumbnail path
     $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
     $thumbnail = $config->getString('imagefolder') . '/avatar/' . $avatarFolder . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']);
     // Generate full image
     if (!CImageHelper::resizeProportional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage));
         return;
     }
     // Generate thumbnail
     if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) {
         $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage));
         return;
     }
     $cTable->setImage($image, 'avatar');
     $cTable->setImage($thumbnail, 'thumb');
     $this->_showUploadError(false, $cTable->getAvatar(), CUrlHelper::avatarURI($thumbnail, 'user_thumb.png'));
 }
예제 #11
0
 /**
  * This function will regenerate the thumbnail of videos
  * @param int $id
  * @param bool $returnThumb
  * @return bool
  */
 public function _fetchThumbnail($id = 0, $returnThumb = false)
 {
     if (!COwnerHelper::isRegisteredUser()) {
         return;
     }
     if (!$id) {
         return false;
     }
     $table = JTable::getInstance('Video', 'CTable');
     $table->load($id);
     $config = CFactory::getConfig();
     if ($table->type == 'file') {
         // We can only recreate the thumbnail for local video file only
         // it's not possible to process remote video file with ffmpeg
         if ($table->storage != 'file') {
             $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . 'FFmpeg cannot process remote video.');
             return false;
         }
         $videoLib = new CVideoLibrary();
         $videoFullPath = JPATH::clean(JPATH_ROOT . '/' . $table->path);
         if (!JFile::exists($videoFullPath)) {
             return false;
         }
         // Read duration
         $videoInfo = $videoLib->getVideoInfo($videoFullPath);
         if (!$videoInfo) {
             return false;
         } else {
             $videoFrame = CVideosHelper::formatDuration((int) ($videoInfo['duration']['sec'] / 2), 'HH:MM:SS');
             // Create thumbnail
             $oldThumb = $table->thumb;
             $thumbFolder = CVideoLibrary::getPath($table->creator, 'thumb');
             $thumbSize = CVideoLibrary::thumbSize();
             $thumbFilename = $videoLib->createVideoThumb($videoFullPath, $thumbFolder, $videoFrame, $thumbSize);
         }
         if (!$thumbFilename) {
             return false;
         }
     } else {
         if (!CRemoteHelper::curlExists()) {
             $this->setError(JText::_('COM_COMMUNITY_CURL_NOT_EXISTS'));
             return false;
         }
         $videoLib = new CVideoLibrary();
         $videoObj = $videoLib->getProvider($table->path);
         if ($videoObj == false) {
             $this->setError($videoLib->getError());
             return false;
         }
         if (!$videoObj->isValid()) {
             $this->setError($videoObj->getError());
             return false;
         }
         $remoteThumb = $videoObj->getThumbnail();
         $thumbData = CRemoteHelper::getContent($remoteThumb, true);
         if (empty($thumbData)) {
             $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $remoteThumb);
             return false;
         }
         // split the header and body
         list($headers, $body) = explode("\r\n\r\n", $thumbData, 2);
         preg_match('/Content-Type: image\\/(.*)/i', $headers, $matches);
         if (!empty($matches)) {
             $thumbPath = CVideoLibrary::getPath($table->creator, 'thumb');
             $thumbFileName = CFileHelper::getRandomFilename($thumbPath);
             $tmpThumbPath = $thumbPath . '/' . $thumbFileName;
             if (!JFile::write($tmpThumbPath, $body)) {
                 $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $thumbFileName);
                 return false;
             }
             // We'll remove the old or none working thumbnail after this
             $oldThumb = $table->thumb;
             // Get the image type first so we can determine what extensions to use
             $info = getimagesize($tmpThumbPath);
             $mime = image_type_to_mime_type($info[2]);
             $thumbExtension = CImageHelper::getExtension($mime);
             $thumbFilename = $thumbFileName . $thumbExtension;
             $thumbPath = $thumbPath . '/' . $thumbFilename;
             if (!JFile::move($tmpThumbPath, $thumbPath)) {
                 $this->setError(JText::_('WARNFS_ERR02') . ': ' . $thumbFileName);
                 return false;
             }
             // Resize the thumbnails
             //CImageHelper::resizeProportional( $thumbPath , $thumbPath , $mime , CVideoLibrary::thumbSize('width') , CVideoLibrary::thumbSize('height') );
             list($width, $height) = explode('x', $config->get('videosThumbSize'));
             CImageHelper::resizeAspectRatio($thumbPath, $thumbPath, $width, $height);
         } else {
             $this->setError(JText::_('COM_COMMUNITY_PHOTOS_IMAGE_NOT_PROVIDED_ERROR'));
             return false;
         }
     }
     // Update the DB with new thumbnail
     $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename;
     $table->set('thumb', $thumb);
     $table->store();
     // If this video storage is not on local, we move it to remote storage
     // and remove the old thumb if existed
     if ($table->storage != 'file') {
         // && ($table->storage == $storageType))
         $config = CFactory::getConfig();
         $storageType = $config->getString('videostorage');
         $storage = CStorage::getStorage($storageType);
         $storage->delete($oldThumb);
         $localThumb = JPATH::clean(JPATH_ROOT . '/' . $table->thumb);
         $tempThumbname = JPATH::clean(JPATH_ROOT . '/' . md5($table->thumb));
         if (JFile::exists($localThumb)) {
             JFile::copy($localThumb, $tempThumbname);
         }
         if (JFile::exists($tempThumbname)) {
             $storage->put($table->thumb, $tempThumbname);
             JFile::delete($localThumb);
             JFile::delete($tempThumbname);
         }
     } else {
         if (JFile::exists(JPATH_ROOT . '/' . $oldThumb)) {
             JFile::delete(JPATH_ROOT . '/' . $oldThumb);
         }
     }
     if ($returnThumb) {
         return $table->getThumbnail();
     }
     return true;
 }
예제 #12
0
파일: groups.php 프로젝트: bizanto/Hooked
 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);
 }
예제 #13
0
 public function createVideoThumbFromRemote(&$videoObj)
 {
     $thumbData = CRemoteHelper::getContent($video->thumb);
     if ($thumbData) {
         jimport('joomla.filesystem.file');
         $thumbPath = CVideos::getPath($table->creator, 'thumb');
         $thumbFileName = CFileHelper::getRandomFilename($thumbPath);
         $tmpThumbPath = $thumbPath . '/' . $thumbFileName;
         if (JFile::write($tmpThumbPath, $thumbData)) {
             // Get the image type first so we can determine what extensions to use
             $info = getimagesize($tmpThumbPath);
             $mime = image_type_to_mime_type($info[2]);
             $thumbExtension = CImageHelper::getExtension($mime);
             $thumbFilename = $thumbFileName . $thumbExtension;
             $thumbPath = $thumbPath . '/' . $thumbFilename;
             JFile::move($tmpThumbPath, $thumbPath);
             // Resize the thumbnails
             //CFactory::load( 'libraries', 'videos' );
             CImageHelper::resizeProportional($thumbPath, $thumbPath, $mime, CVideos::thumbSize('width'), CVideo::thumbSize('height'));
             // Save
             $config = CFactory::getConfig();
             $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename;
             $table->set('thumb', $thumb);
             $table->store();
         }
     }
 }
예제 #14
0
파일: groups.php 프로젝트: Jougito/DynWeb
 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);
 }
예제 #15
0
 private function _updateUserWatermark($user, $type, $hashName)
 {
     $config = CFactory::getConfig();
     $oldAvatar = $user->_avatar;
     // @rule: This is the original avatar path
     //CFactory::load( 'helpers' , 'image' );
     $userImageType = '_' . $type;
     $data = @getimagesize(JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $user->{$userImageType}));
     $original = JPATH_ROOT . '/images/watermarks/original' . '/' . md5($user->id . '_' . $type) . CImageHelper::getExtension($data['mime']);
     if (!$config->get('profile_multiprofile') || !JFile::exists($original)) {
         return false;
     }
     static $types = array();
     if (empty($types)) {
         $model = CFactory::getModel('Profile');
         $rows = $model->getProfileTypes();
         if ($rows) {
             foreach ($rows as $row) {
                 $types[$row->id] = $row;
             }
         }
     }
     $model = CFactory::getModel('User');
     if (isset($types[$user->_profile_id])) {
         // Bind the data to the current object so we can access it here.
         $this->bind($types[$user->_profile_id]);
         // Path to the watermark image.
         $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $this->watermark);
         // Retrieve original image info
         $originalData = getimagesize($original);
         // Generate image file name.
         $fileName = $type == 'thumb' ? 'thumb_' : '';
         $fileName .= $hashName;
         $fileName .= CImageHelper::getExtension($originalData['mime']);
         // Absolute path to the image (local)
         $newImagePath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $fileName;
         // Relative path to the image (uri)
         $newImageUri = $config->getString('imagefolder') . '/avatar/' . $fileName;
         // Retrieve the height and width for watermark and original image.
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
         list($originalWidth, $originalHeight) = getimagesize($original);
         // Retrieve the proper coordinates to the watermark location
         $position = CImageHelper::getPositions($this->watermark_location, $originalWidth, $originalHeight, $watermarkWidth, $watermarkHeight);
         // Create the new image with the watermarks.
         CImageHelper::addWatermark($original, $newImagePath, $originalData['mime'], $watermarkPath, $position->x, $position->y, false);
         $model->setImage($user->id, $newImageUri, $type);
         // Remove the user's old image
         $oldFile = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $user->{$userImageType});
         if (JFile::exists($oldFile)) {
             JFile::delete($oldFile);
         }
         if ($type == 'avatar') {
             $oldImg = explode('avatar/', $oldAvatar);
             $oldImg = explode('.', $oldImg[1]);
             $oldImg = $config->getString('imagefolder') . '/avatar/' . $oldImg[0] . '_stream_.' . $oldImg[1];
             JFile::copy($newImageUri, $oldImg);
         }
         // We need to update the property in CUser as well otherwise when we save the hash, it'll
         // use the old user avatar.
         $user->set($userImageType, $newImageUri);
         // We need to restore the storage method.
         $user->set('_storage', 'file');
         // Update the watermark hash with the latest hash
         $user->set('_watermark_hash', $this->watermark_hash);
         $user->save();
     }
     return true;
 }
예제 #16
0
 public function save($data = array())
 {
     jimport('joomla.filesystem.file');
     //CFactory::load('helpers', 'string');
     $config = JTable::getInstance('configuration', 'CommunityTable');
     $config->load('config');
     $config->name = 'config';
     $params = new JRegistry($config->params);
     $postData = count($data) > 0 ? $data : JRequest::get('post', 2);
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $session = JFactory::getSession();
     $token = $session->getFormToken(false);
     unset($postData[$token]);
     foreach ($postData as $key => $value) {
         echo $key . ' = ' . $value . '<br/>';
         if ($key != 'task' && $key != 'option' && $key != 'view' && $key != $token) {
             $params->set($key, $value);
         }
     }
     //@since 4.1, storing watermark for normal photo
     $watermark = $jinput->files->get('watermark', '', 'NONE');
     if (!empty($watermark['tmp_name'])) {
         // Do not allow image size to exceed maximum width and height
         if (isset($watermark['name']) && !empty($watermark['name'])) {
             list($width, $height) = getimagesize($watermark['tmp_name']);
             /**
              * watermark can't large than 16px
              * @todo use define for min width & height instead fixed number here
              */
             $validated = false;
             //watermark must be png
             if (CImageHelper::getExtension($watermark['type']) == '.png') {
                 $validated = true;
             } else {
                 $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE'), 'error');
             }
             if ($validated) {
                 // @rule: Create original folder within watermarks to store original user photos.
                 if (!JFolder::exists(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
                     if (!JFolder::create(JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH)) {
                         $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER'));
                     }
                 }
                 //move the watermark photo to the folder
                 $watermarkFile = WATERMARK_DEFAULT_NAME . CImageHelper::getExtension($watermark['type']);
                 JFile::copy($watermark['tmp_name'], JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . $watermarkFile);
             }
         }
     }
     $config->params = $params->toString();
     // Save it
     if (!$config->store()) {
         return false;
     }
     return true;
 }
예제 #17
0
파일: photos.php 프로젝트: Jougito/DynWeb
 /**
  * Process Uploaded Photo Cover
  * @return [JSON OBJECT] [description]
  */
 public function ajaxCoverUpload()
 {
     $jinput = JFactory::getApplication()->input;
     $parentId = $jinput->get->get('parentId', null, 'Int');
     $type = strtolower($jinput->get->get('type', null, 'String'));
     $file = $jinput->files->get('uploadCover');
     $config = CFactory::getConfig();
     $my = CFactory::getUser();
     $now = new JDate();
     $addStream = true;
     if (!CImageHelper::checkImageSize(filesize($file['tmp_name']))) {
         $msg['error'] = JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize'));
         echo json_encode($msg);
         exit;
     }
     //check if file is allwoed
     if (!CImageHelper::isValidType($file['type'])) {
         $msg['error'] = JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED');
         echo json_encode($msg);
         exit;
     }
     CImageHelper::autoRotate($file['tmp_name']);
     $album = JTable::getInstance('Album', 'CTable');
     if (!($albumId = $album->isCoverExist($type, $parentId))) {
         $albumId = $album->addCoverAlbum($type, $parentId);
     }
     $imgMaxWidht = 1140;
     // Get a hash for the file name.
     $fileName = JApplication::getHash($file['tmp_name'] . time());
     $hashFileName = JString::substr($fileName, 0, 24);
     if (!JFolder::exists(JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/')) {
         JFolder::create(JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/');
     }
     $dest = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/' . md5($type . '_cover' . time()) . CImageHelper::getExtension($file['type']);
     $thumbPath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/thumb_' . md5($type . '_cover' . time()) . CImageHelper::getExtension($file['type']);
     // Generate full image
     if (!CImageHelper::resizeProportional($file['tmp_name'], $dest, $file['type'], $imgMaxWidht)) {
         $msg['error'] = JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage);
         echo json_encode($msg);
         exit;
     }
     CPhotos::generateThumbnail($file['tmp_name'], $thumbPath, $file['type']);
     $cTable = JTable::getInstance(ucfirst($type), 'CTable');
     $cTable->load($parentId);
     if ($cTable->setCover(str_replace(JPATH_ROOT . '/', '', $dest))) {
         $photo = JTable::getInstance('Photo', 'CTable');
         $photo->albumid = $albumId;
         $photo->image = str_replace(JPATH_ROOT . '/', '', $dest);
         $photo->caption = $file['name'];
         $photo->filesize = $file['size'];
         $photo->creator = $my->id;
         $photo->created = $now->toSql();
         $photo->published = 1;
         $photo->thumbnail = str_replace(JPATH_ROOT . '/', '', $thumbPath);
         if ($photo->store()) {
             $album->load($albumId);
             $album->photoid = $photo->id;
             $album->store();
         }
         $msg['success'] = true;
         $msg['path'] = JURI::root() . str_replace(JPATH_ROOT . '/', '', $dest);
         $msg['cancelbutton'] = JText::_('COM_COMMUNITY_CANCEL_BUTTON');
         $msg['savebutton'] = JText::_("COM_COMMUNITY_SAVE_BUTTON");
         // Generate activity stream.
         $act = new stdClass();
         $act->cmd = 'cover.upload';
         $act->actor = $my->id;
         $act->target = 0;
         $act->title = '';
         $act->content = '';
         $act->access = $type == 'profile' ? $my->_cparams->get("privacyPhotoView") : 0;
         $act->app = 'cover.upload';
         $act->cid = $photo->id;
         $act->comment_id = CActivities::COMMENT_SELF;
         $act->comment_type = 'cover.upload';
         $act->groupid = $type == 'group' ? $parentId : 0;
         $act->eventid = $type == 'event' ? $parentId : 0;
         $act->group_access = $type == 'group' ? $cTable->approvals : 0;
         $act->event_access = $type == 'event' ? $cTable->permission : 0;
         $act->like_id = CActivities::LIKE_SELF;
         $act->like_type = 'cover.upload';
         $params = new JRegistry();
         $params->set('attachment', str_replace(JPATH_ROOT . '/', '', $dest));
         $params->set('type', $type);
         $params->set('album_id', $albumId);
         $params->set('photo_id', $photo->id);
         //assign points based on types.
         switch ($type) {
             case 'group':
                 $addStream = CUserPoints::assignPoint('group.cover.upload');
                 break;
             case 'event':
                 $addStream = CUserPoints::assignPoint('event.cover.upload');
                 break;
             default:
                 $addStream = CUserPoints::assignPoint('profile.cover.upload');
         }
         if ($type == 'event') {
             $event = JTable::getInstance('Event', 'CTable');
             $event->load($parentId);
             $group = JTable::getInstance('Group', 'CTable');
             $group->load($event->contentid);
             if ($group->approvals == 1) {
                 $addStream = false;
             }
         }
         if ($addStream) {
             // Add activity logging
             if ($type != 'profile' || $type == 'profile' && $parentId == $my->id) {
                 CActivityStream::add($act, $params->toString());
             }
         }
         echo json_encode($msg);
         exit;
     }
 }
예제 #18
0
    public static function uploadFile($file)
    {
    	require_once(JPATH_SITE.DS.'components'.DS.'com_community'.DS.'libraries'.DS.'core.php');
    	require_once(JPATH_SITE.DS.'components'.DS.'com_community'.DS.'helpers'.DS.'image.php');

		$config	= CFactory::getConfig();

    	$fileName = JUtility::getHash($file. time() );
		$hashFileName = JString::substr( $fileName , 0 , 24 );
		$fileType = self::getMimeType($file);

    	//$result['img_path'] = JURI::root().$config->getString('imagefolder').'/'.'avatar'.'/'.$hashFileName.CImageHelper::getExtension($uploadImg['type']);
		$result['avatar'] = $config->getString('imagefolder').'/'.'avatar'.'/'.$hashFileName.CImageHelper::getExtension($fileType);
		$result['thumb'] = $config->getString('imagefolder').'/'.'avatar'.'/'.'thumb_'.$hashFileName.CImageHelper::getExtension($fileType);
    	$avatar = JPATH_ROOT.DS.$config->getString('imagefolder').DS.'avatar'.DS.$hashFileName.CImageHelper::getExtension($fileType);
    	$thumbnail = JPATH_ROOT.DS.$config->getString('imagefolder').DS.'avatar'.DS.'thumb_'.$hashFileName.CImageHelper::getExtension($fileType);
   		$imageMaxWidth	= 160;
   		if(self::resizeProportional($file, $avatar , $fileType , $imageMaxWidth ))
   		{
   			if(self::createThumb($file, $thumbnail , $fileType ))
   			{
   				$result['uploaded'] = true;
   				return $result;
   			}
   		}else{
   			$result['uploaded'] = false;
   			return $result;
   		}
    }