예제 #1
0
파일: photos.php 프로젝트: Jougito/DynWeb
 /**
  * Rotate the given photo
  * @param  int $photoId photo to rotate
  * @param  string $orientation left/right
  * @return stinr              response
  */
 public function ajaxRotatePhoto($photoId, $orientation)
 {
     $filter = JFilterInput::getInstance();
     $photoId = $filter->clean($photoId, 'int');
     $app = JFactory::getApplication();
     // $orientation pending filter
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $photo = JTable::getInstance('Photo', 'CTable');
     $photo->load($photoId);
     if ($photo->storage != 'file') {
         // download the image files to local server
         $currentStorage = CStorage::getStorage($photo->storage);
         if ($currentStorage->exists($photo->image)) {
             $jTempPath = $app->getCfg('tmp_path');
             $tempFilename = $jTempPath . '/' . md5($photo->image) . '.' . JFIle::getExt($photo->image);
             $currentStorage->get($photo->image, $tempFilename);
             $thumbsTemp = $jTempPath . '/thumb_' . md5($photo->thumbnail) . '.' . JFIle::getExt($photo->image);
             $currentStorage->get($photo->thumbnail, $thumbsTemp);
         }
     }
     if ($photo->storage == 'file') {
         $photoPath = JPath::clean($photo->image);
         $thumbPath = JPath::clean($photo->thumbnail);
     } else {
         $thumbPath = CString::str_ireplace(JPATH_ROOT . "/", "", $thumbsTemp);
         $photoPath = CString::str_ireplace(JPATH_ROOT . "/", "", $tempFilename);
     }
     // Hash the image file name so that it gets as unique possible
     $fileName = JApplication::getHash($photo->image . time());
     $fileName = JString::substr($fileName, 0, 24);
     $fileName = $fileName . '.' . JFile::getExt($photo->image);
     $fileNameLength = strlen($photo->image) - strrpos($photo->image, '/') - 1;
     $newPhotoPath = substr_replace($photoPath, $fileName, -$fileNameLength);
     $newThumbPath = substr_replace($photoPath, 'thumb_' . $fileName, -$fileNameLength);
     $degrees = 0;
     if (JFile::exists($photoPath) && JFile::exists($thumbPath)) {
         switch ($orientation) {
             case 'left':
                 $degrees = 90;
                 break;
             case 'right':
                 $degrees = -90;
                 break;
             default:
                 $degrees = 0;
                 break;
         }
         if ($degrees !== 0) {
             // Trim any '/' at the beginning of the filename
             $photoPath = ltrim($photoPath, '/');
             $photoPath = ltrim($photoPath, '/');
             $photoPath = ltrim($photoPath, '/');
             $photoPath = ltrim($photoPath, '/');
             $imageResult = CImageHelper::rotate(JPATH_ROOT . '/' . $photoPath, JPATH_ROOT . '/' . $newPhotoPath, $degrees);
             $thumbResult = CImageHelper::rotate(JPATH_ROOT . '/' . $thumbPath, JPATH_ROOT . '/' . $newThumbPath, $degrees);
             if ($imageResult !== false && $thumbResult !== false) {
                 // This part is not really necessary for newer installations
                 $newPhotoPath = CString::str_ireplace(JPATH_ROOT . '/', '', $newPhotoPath);
                 $newThumbPath = CString::str_ireplace(JPATH_ROOT . '/', '', $newThumbPath);
                 $newPhotoPath = CString::str_ireplace('\\', '/', $newPhotoPath);
                 $newThumbPath = CString::str_ireplace('\\', '/', $newThumbPath);
                 $photo->storage = 'file';
                 //just to make sure it's in the local server
                 $photo->image = $newPhotoPath;
                 $photo->thumbnail = $newThumbPath;
                 $photo->store();
                 //Delete the original file
                 JFile::delete(JPATH_ROOT . '/' . $photoPath);
                 JFile::delete(JPATH_ROOT . '/' . $thumbPath);
             }
         }
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_ACTIVITIES));
     $json = array('thumbnail' => $photo->getThumbURI(), 'url' => $photo->getImageURI());
     die(json_encode($json));
 }
예제 #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
파일: photos.php 프로젝트: bizanto/Hooked
 public function ajaxRotatePhoto($photoId, $orientation)
 {
     CFactory::load('helpers', 'owner');
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $photo =& JTable::getInstance('Photo', 'CTable');
     $photo->load($photoId);
     if ($photo->storage != 'file') {
         // we don't want to support s3
         return false;
     }
     if ($photo->storage != 'file') {
         // download the image files to local server
         CFactory::load('libraries', 'storage');
         $storage = CStorage::getStorage($photoStorage);
         $currentStorage = CStorage::getStorage($photo->storage);
         if ($currentStorage->exists($photo->image)) {
             $jconfig = JFactory::getConfig();
             $jTempPath = $jconfig->getValue('tmp_path');
             $tempFilename = $jTempPath . DS . md5($photo->image);
             $currentStorage->get($photo->image, $tempFilename);
             $thumbsTemp = $jTempPath . DS . 'thumb_' . md5($photo->thumbnail);
             $currentStorage->get($photo->thumbnail, $thumbsTemp);
             if (JFile::exists($tempFilename) && JFile::exists($thumbsTemp) && $storage->put($row->image, $tempFilename) && $storage->put($photo->thumbnail, $thumbsTemp)) {
                 $currentStorage->delete($photo->image);
                 $currentStorage->delete($photo->thumbnail);
                 JFile::delete($tempFilename);
                 JFile::delete($thumbsTemp);
             }
         }
     }
     $photoPath = JPath::clean(JPATH_ROOT . DS . $photo->image);
     $thumbPath = JPath::clean(JPATH_ROOT . DS . $photo->thumbnail);
     // Hash the image file name so that it gets as unique possible
     $fileName = JUtility::getHash($photo->image . time());
     $fileName = JString::substr($fileName, 0, 24);
     $fileName = $fileName . '.' . JFile::getExt($photo->image);
     $fileNameLength = strlen($photo->image) - strrpos($photo->image, '/') - 1;
     $newPhotoPath = substr_replace($photoPath, $fileName, -$fileNameLength);
     $newThumbPath = substr_replace($photoPath, 'thumb_' . $fileName, -$fileNameLength);
     $degrees = 0;
     if (JFile::exists($photoPath) && JFile::exists($thumbPath)) {
         switch ($orientation) {
             case 'left':
                 $degrees = 90;
                 break;
             case 'right':
                 $degrees = -90;
                 break;
             default:
                 $degrees = 0;
                 break;
         }
         if ($degrees !== 0) {
             CFactory::load('helpers', 'image');
             CImageHelper::rotate($photoPath, $newPhotoPath, $degrees);
             CImageHelper::rotate($thumbPath, $newThumbPath, $degrees);
             $newPhotoPath = JString::str_ireplace(JPATH_ROOT . DS, '', $newPhotoPath);
             $newThumbPath = JString::str_ireplace(JPATH_ROOT . DS, '', $newThumbPath);
             $newPhotoPath = JString::str_ireplace('\\', '/', $newPhotoPath);
             $newThumbPath = JString::str_ireplace('\\', '/', $newThumbPath);
             $photo->storage = 'file';
             //just to make sure it's in the local server
             $photo->image = $newPhotoPath;
             $photo->thumbnail = $newThumbPath;
             $photo->store();
         }
     }
     $response = new JAXResponse();
     $response->addScriptCall('__callback', $photo->id, $photo->getImageURI(), $photo->getThumbURI());
     return $response->sendResponse();
 }
예제 #4
0
 public function ajaxRotateAvatar($type, $id, $direction = 'right')
 {
     $my = CFactory::getUser();
     if ($my->id == 0) {
         return $this->blockUnregister();
     }
     if (!(COwnerHelper::isCommunityAdmin() || $my->id == $id)) {
         $json = array('error' => JText::_('Forbidden access.'));
         die(json_encode($json));
     }
     $config = CFactory::getConfig();
     $avatar = $my->get('_avatar');
     if (!$avatar) {
         $json = array('error' => JText::_('Avatar not set.'));
         die(json_encode($json));
     }
     $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar/';
     $avatarFilename = $storage . basename($avatar);
     $cropperFilename = $storage . 'profile-' . basename($avatar);
     if ($direction === 'left') {
         $direction = 90;
     } else {
         $direction = -90;
     }
     CImageHelper::rotate($avatarFilename, $avatarFilename, $direction);
     CImageHelper::rotate($cropperFilename, $cropperFilename, $direction);
     $json = array('success' => true, 'avatar' => JURI::root(true) . '/' . $avatar);
     die(json_encode($json));
 }
예제 #5
0
파일: image.php 프로젝트: Jougito/DynWeb
 public static function autoRotate($imagePath, $orientation = null)
 {
     if (!$orientation) {
         // Read orientation data from original file
         $orientation = CImageHelper::getOrientation($imagePath);
     }
     // Rotate resized files ince it is smaller
     switch ($orientation) {
         case 1:
             // nothing
             break;
         case 2:
             // horizontal flip
             break;
         case 3:
             // 180 rotate left
             CImageHelper::rotate($imagePath, $imagePath, 180);
             break;
         case 4:
             // vertical flip
             break;
         case 5:
             // vertical flip + 90 rotate right
             break;
         case 6:
             // 90 rotate right
             CImageHelper::rotate($imagePath, $imagePath, -90);
             break;
         case 7:
             // horizontal flip + 90 rotate right
             break;
         case 8:
             // 90 rotate left
             CImageHelper::rotate($imagePath, $imagePath, 90);
             break;
     }
 }