Exemple #1
0
 /**
  * Called during photo uploading.
  * @return type
  */
 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = $jinput->request->get('token', '', 'NONE');
         $userId = $jinput->request->get('uploaderid', '', 'NONE');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session = JFactory::getSession();
         $session->set('user', $my);
     }
     if (CLimitsLibrary::exceedDaily('photos', $my->id)) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_PHOTOS_LIMIT_PERDAY_REACHED'));
         return;
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     $photos = JRequest::get('Files');
     $albumId = $jinput->request->get('albumid', '', 'INT');
     $album = $this->_getRequestUserAlbum($albumId);
     // Uploaded images count in this batch
     $batchCount = $jinput->request->get('batchcount', '', 'INT');
     $handler = $this->_getHandler($album);
     /* Do process for all photos */
     foreach ($photos as $imageFile) {
         /* Validating */
         $result = $this->_checkUploadedFile($imageFile, $album, $handler);
         if (!$result['photoTable']) {
             continue;
         }
         //assign the result of the array and assigned to the right variable
         $photoTable = $result['photoTable'];
         $storage = $result['storage'];
         $albumPath = $result['albumPath'];
         $hashFilename = $result['hashFilename'];
         $thumbPath = $result['thumbPath'];
         $originalPath = $result['originalPath'];
         $imgType = $result['imgType'];
         $isDefaultPhoto = $result['isDefaultPhoto'];
         // 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, $album->id);
         $storedPath = $storedPath . '/' . $albumPath . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         $photoTable->image = CString::str_ireplace(JPATH_ROOT . '/', '', $storedPath);
         $photoTable->thumbnail = CString::str_ireplace(JPATH_ROOT . '/', '', $thumbPath);
         //In joomla 1.6, CString::str_ireplace is not replacing the path properly. Need to do a check here
         if ($photoTable->image == $storedPath) {
             $photoTable->image = str_ireplace(JPATH_ROOT . '/', '', $storedPath);
         }
         if ($photoTable->thumbnail == $thumbPath) {
             $photoTable->thumbnail = str_ireplace(JPATH_ROOT . '/', '', $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') {
             $this->_rotatePhoto($imageFile, $photoTable, $storedPath, $thumbPath);
         }
         // Trigger for onPhotoCreate
         $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();
             }
         }
         // Set the upload count per session
         $session = JFactory::getSession();
         $uploadSessionCount = $session->get('album-' . $album->id . '-upload', 0);
         $uploadSessionCount++;
         $session->set('album-' . $album->id . '-upload', $uploadSessionCount);
         //add user points
         CUserPoints::assignPoint('photo.upload');
         // Photo upload was successfull, display a proper message
         $this->_showUploadError(false, JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photoTable->caption), $photoTable->getThumbURI(), $album->id, $photoTable->id);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_ACTIVITIES));
     exit;
 }
Exemple #2
0
 public function multiUpload()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $type = $jinput->get('type', NULL, 'NONE');
     $id = $jinput->get('id', '0', 'Int');
     if ($my->id == 0) {
         $tokenId = $jinput->request->get('token', '', 'STRING');
         $userId = $jinput->request->get('uploaderid', '', 'INT');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session = JFactory::getSession();
         $session->set('user', $my);
     }
     $parentTable = JTable::getInstance(ucfirst($type), 'CTable');
     $parentTable->load($id);
     $table = JTable::getInstance('File', 'CTable');
     $_file = $jinput->files->get('file');
     $fileLib = new CFilesLibrary();
     if (CLimitsLibrary::exceedDaily('files', $my->id)) {
         $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED'));
         echo json_encode($json);
         exit;
     }
     if ($type == 'discussion' && !CLimitsHelper::exceededGroupFileUpload($parentTable->groupid)) {
         $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED'));
         echo json_encode($json);
         exit;
     }
     $now = new JDate();
     $ext = pathinfo($_file['name']);
     $file = new stdClass();
     $file->creator = $my->id;
     $file->filesize = sprintf("%u", $_file['size']);
     $file->name = JString::substr($_file['name'], 0, JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1));
     $file->created = $now->toSql();
     $file->type = CFileHelper::getExtensionIcon(CFileHelper::getFileExtension($_file['name']));
     $fileName = JApplication::getHash($_file['name'] . time()) . JString::substr($_file['name'], JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1));
     if ($_file['error'] > 0 && $_file['error'] !== 'UPLOAD_ERR_OK') {
         $json = array('msg' => JText::sprintf('COM_COMMUNITY_PHOTOS_UPLOAD_ERROR', $_file['error']));
         echo json_encode($json);
         exit;
     }
     if (!$fileLib->checkType($_file['name'])) {
         $json = array('msg' => JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         echo json_encode($json);
         exit;
     }
     switch ($type) {
         case 'discussion':
             $file->discussionid = $parentTable->id;
             $file->groupid = $parentTable->groupid;
             $file->filepath = 'images/files' . '/' . $type . '/' . $file->discussionid . '/' . $fileName;
             break;
         case 'bulletin':
             $file->bulletinid = $parentTable->id;
             $file->groupid = $parentTable->groupid;
             $file->filepath = 'images/files' . '/' . $type . '/' . $file->bulletinid . '/' . $fileName;
             break;
         case 'message':
             $file->messageid = -1;
             // set as -1 just in case this is not used and cron can clear it later
             if ($id) {
                 $file->filepath = 'images/files/' . $type . '/' . $id . '/' . $fileName;
                 if (!JFolder::exists(JPATH_ROOT . '/images/files/' . $type . '/' . $id)) {
                     JFolder::create(JPATH_ROOT . '/images/files/' . $type . '/' . $id, (int) octdec($config->get('folderpermissionsphoto')));
                     JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/images/files/' . $type . '/' . $id . '/index.html');
                 }
                 JFile::copy($_file['tmp_name'], JPATH_ROOT . '/' . $file->filepath);
             } else {
                 //this could be from new message, and there is no id given
                 $file->filepath = 'images/files/' . $type . '/temp/' . $fileName;
                 //create the folder here as the logic for bulletin and discussion is not the same
                 if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/temp')) {
                     JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/temp', (int) octdec($config->get('folderpermissionsphoto')));
                     JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/temp/index.html');
                 }
                 JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/temp/' . $fileName);
             }
             break;
     }
     if ($type != 'message') {
         if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/' . $parentTable->id)) {
             JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id, (int) octdec($config->get('folderpermissionsphoto')));
             JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/' . $parentTable->id . '/index.html');
         }
         JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id . '/' . $fileName);
     }
     $table->bind($file);
     $table->store();
     $params = new CParameter('');
     switch ($type) {
         case 'discussion':
             // Get repliers for this discussion and notify the discussion creator too
             $discussionModel = CFactory::getModel('Discussions');
             $discussion = JTable::getInstance('Discussion', 'CTable');
             $discussion->load($parentTable->id);
             $users = $discussionModel->getRepliers($discussion->id, $discussion->groupid);
             $users[] = $discussion->creator;
             // The person who post this, should not be getting notification email
             $key = array_search($my->id, $users);
             if ($key !== false && isset($users[$key])) {
                 unset($users[$key]);
             }
             $params->set('url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $discussion->groupid . '&topicid=' . $discussion->id);
             $params->set('filename', $_file['name']);
             $params->set('discussion', $discussion->title);
             $params->set('discussion_url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $discussion->groupid . '&topicid=' . $discussion->id);
             CNotificationLibrary::add('groups_discussion_newfile', $my->id, $users, JText::sprintf('COM_COMMUNITY_GROUP_DISCUSSION_NEW_FILE_SUBJECT'), '', 'groups.discussion.newfile', $params);
             break;
         case 'bulletin':
             break;
     }
     $json = array('id' => $table->id);
     die(json_encode($json));
 }
Exemple #3
0
 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = JRequest::getVar('token', '', 'REQUEST');
         $userId = JRequest::getVar('uploaderid', '', 'REQUEST');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     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);
     }
     exit;
 }
Exemple #4
0
 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = JRequest::getVar('token', '', 'REQUEST');
         $userId = JRequest::getVar('uploaderid', '', 'REQUEST');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session =& JFactory::getSession();
         $session->set('user', $my);
     }
     CFactory::load('libraries', 'limits');
     if (CLimitsLibrary::exceedDaily('photos', $my->id)) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_PHOTOS_LIMIT_PERDAY_REACHED'));
         return;
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     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) {
         $result = $this->_checkUploadedFile($imageFile, $album, $handler);
         if (!$result['photoTable']) {
             continue;
         }
         //assign the result of the array and assigned to the right variable
         $photoTable = $result['photoTable'];
         $storage = $result['storage'];
         $albumPath = $result['albumPath'];
         $hashFilename = $result['hashFilename'];
         $thumbPath = $result['thumbPath'];
         $originalPath = $result['originalPath'];
         $imgType = $result['imgType'];
         $isDefaultPhoto = $result['isDefaultPhoto'];
         // 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 = CString::str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         $photoTable->thumbnail = CString::str_ireplace(JPATH_ROOT . DS, '', $thumbPath);
         //In joomla 1.6, CString::str_ireplace is not replacing the path properly. Need to do a check here
         if ($photoTable->image == $storedPath) {
             $photoTable->image = str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         }
         if ($photoTable->thumbnail == $thumbPath) {
             $photoTable->thumbnail = 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') {
             $this->_rotatePhoto($imageFile, $photoTable, $storedPath, $thumbPath);
         }
         // 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();
             }
         }
         // Generate activity stream
         $act = new stdClass();
         $act->cmd = 'photo.upload';
         $act->actor = $my->id;
         $act->access = $album->permissions;
         $act->target = 0;
         //$act->title	  	= JText::sprintf( $handler->getUploadActivityTitle() , '{photo_url}', $album->name );
         $act->title = JText::sprintf($handler->getUploadActivityTitle(), '{multiUrl}', $album->name);
         $act->content = '';
         // Gegenerated automatically by stream. No need to add anything
         $act->app = 'photos';
         $act->cid = $albumId;
         $act->location = $album->location;
         // Store group info
         // I hate to load group here, but unfortunately, album does
         // not store group permission setting
         $group =& JTable::getInstance('Group', 'CTable');
         $group->load($album->groupid);
         $act->groupid = $album->groupid;
         $act->group_access = $group->approvals;
         // Allow comment on the album
         $act->comment_type = 'photos.album';
         $act->comment_id = $albumId;
         // Allow like on the album
         $act->like_type = 'photos.album';
         $act->like_id = $albumId;
         $params = new CParameter('');
         $params->set('multiUrl', $handler->getAlbumURI($albumId, false));
         $params->set('photoid', $photoTable->id);
         $params->set('action', 'upload');
         $params->set('photo_url', $photoTable->getThumbURI());
         // 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('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photoTable->caption), $photoTable->getThumbURI(), $albumId, $photoTable->id);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_ACTIVITIES));
     exit;
 }