Пример #1
0
 /**
  * Responsible to handle temporary file uploads. This is useful for services that may want
  * to upload files before their real items are created.
  *
  * @since	1.0
  * @access	public
  */
 public function uploadTemporary()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Only registered users are allowed here.
     FD::requireLogin();
     // Get the view.
     $view = $this->getCurrentView();
     $type = JRequest::getVar('type');
     $config = FD::config();
     $limit = $config->get($type . '.attachments.maxsize');
     // Set uploader options
     $options = array('name' => 'file', 'maxsize' => $limit . 'M');
     // Get uploaded file
     $data = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($data instanceof SocialException) {
         $view->setMessage($data);
         return $view->call(__FUNCTION__);
     }
     if (!$data) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_UPLOADER_FILE_DID_NOT_GET_UPLOADED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get the current logged in user.
     $my = FD::user();
     // Let's get the temporary uploader table.
     $uploader = FD::table('Uploader');
     $uploader->user_id = $my->id;
     // Pass uploaded data to the uploader.
     $uploader->bindFile($data);
     $state = $uploader->store();
     if (!$state) {
         $view->setMessage($uploader->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, $uploader);
     }
     return $view->call(__FUNCTION__, $uploader);
 }
Пример #2
0
 public function explorer()
 {
     $ajax = FD::ajax();
     // Note: This is a just a sample code to mock requests.
     $hook = JRequest::getCmd('hook');
     switch ($hook) {
         case 'getFolders':
             $start = JRequest::getInt('start');
             $limit = JRequest::getInt('limit');
             $folders = $this->folders($start, $limit);
             // // Sample code to use
             // $explorer 	= FD::explorer( 1 , SOCIAL_TYPE_GROUP );
             // $result 	= $explorer->hook( $hook );
             // Take all files and build file map
             $files = $this->files(0, 1500);
             $map = array();
             foreach ($files as $file) {
                 $map[] = $file->id;
             }
             $folders[0]->map = $map;
             $ajax->resolve($folders);
             break;
         case 'addFolder':
             $name = JRequest::getCmd('name');
             if (empty($name)) {
                 $exception = FD::exception('Invalid name provided');
                 $ajax->reject($exception->toArray());
             } else {
                 $data = array('id' => mt_rand(10, 999), 'name' => $name, 'count' => 0, 'data' => (object) array(), 'settings' => (object) array());
                 $ajax->resolve($data);
             }
             break;
         case 'removeFolder':
             // Mock error removal by adding error=1
             $error = JRequest::getBool('error', false);
             if ($error) {
                 $exception = FD::exception('Unable to remove folder.');
                 $ajax->reject($exception);
             } else {
                 $exception = FD::exception('Remove successful!', SOCIAL_MSG_SUCCESS);
                 $ajax->resolve($exception);
             }
             break;
         case 'getFiles':
             $id = JRequest::getInt('id');
             $start = JRequest::getInt('start');
             $limit = JRequest::getInt('limit');
             switch ($id) {
                 // 1500 files
                 case 0:
                     $files = $this->files($start, $limit);
                     $ajax->resolve($files);
                     break;
                     // 0 files
                 // 0 files
                 case 1:
                     $ajax->resolve(array());
                     break;
                     // 1 files
                 // 1 files
                 case 2:
                     $files = $this->smallfiles($start, $limit);
                     $ajax->resolve($files);
                     break;
             }
             break;
         case 'addFile':
             // Define uploader options
             $options = array('name' => 'file', 'maxsize' => '32M');
             // Get uploaded file
             $file = FD::uploader($options)->getFile();
             // If there was an error getting uploaded file, stop.
             if ($file instanceof SocialException) {
                 $ajax->reject($file->toArray());
             }
             // Get filename
             $name = $file['name'];
             $data = array('id' => mt_rand(1501, 2000), 'name' => $name, 'folder' => 0, 'count' => 0, 'data' => (object) array(), 'settings' => (object) array());
             $ajax->resolve($data);
             break;
         case 'removeFile':
             // Mock error removal by adding error=1
             $error = JRequest::getBool('error', false);
             if ($error) {
                 $exception = FD::exception('Unable to remove file.');
                 $ajax->reject($exception);
             } else {
                 $exception = FD::exception('Remove successful!', SOCIAL_MSG_SUCCESS);
                 $ajax->resolve($exception);
             }
             break;
         default:
             $exception = FD::exception('Invalid hook provided.');
             $ajax->reject($exception->toArray());
             break;
     }
     $ajax->send();
 }
Пример #3
0
 public function uploadPhoto($log_usr = 0, $type = null)
 {
     // Get current logged in user.
     $my = FD::user($log_usr);
     // Get user access
     $access = FD::access($my->id, SOCIAL_TYPE_USER);
     // Load up the photo library
     $lib = FD::photo($log_usr, $type);
     // Define uploader options
     $options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // Load the iamge object
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Detect if this is a really valid image file.
     if (!$image->isValid()) {
         return "invalid image";
     }
     // Load up the album's model.
     $albumsModel = FD::model('Albums');
     // Create the default album if necessary
     $album = $albumsModel->getDefaultAlbum($log_usr, $type, SOCIAL_ALBUM_STORY_ALBUM);
     // Bind photo data
     $photo = FD::table('Photo');
     $photo->uid = $log_usr;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->state = 1;
     $photo->ordering = 0;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     // Load the photos model
     $photosModel = FD::model('Photos');
     // Get the storage path for this photo
     $storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     if ($paths) {
         foreach ($paths as $type => $fileName) {
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_PATH;
             $meta->property = $type;
             $meta->value = $storage . '/' . $fileName;
             $meta->store();
             // We need to store the photos dimension here
             list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo dimensions
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_WIDTH;
             $meta->property = $type;
             $meta->value = $width;
             $meta->store();
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_HEIGHT;
             $meta->property = $type;
             $meta->value = $height;
             $meta->store();
         }
     }
     // After storing the photo, trigger rules that should occur after a photo is stored
     //$photo->afterStore( $file , $image );
     //$sphoto = new SocialPhotos($photo_obj->id);
     return $photo;
 }
Пример #4
0
 /**
  * Allows caller to upload files
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function addFile($title = null)
 {
     if (!$this->hasWriteAccess()) {
         return FD::exception(JText::_('COM_EASYSOCIAL_EXPLORER_NO_ACCESS_TO_UPLOAD'));
     }
     // Ensure that the storage path really exists on the site
     FD::makeFolder($this->storagePath);
     // Get the maximum size allowed from the child
     $max = $this->getMaxSize();
     // Define uploader options
     $options = array('name' => 'file', 'maxsize' => $max);
     // Get uploaded file from $_FILE
     $file = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($file instanceof SocialException) {
         return $file;
     }
     // Get filename
     $name = $file['name'];
     // Get the folder to store this item to.
     $collectionId = JRequest::getInt('id', 0);
     $table = FD::table('File');
     $table->name = $name;
     $table->collection_id = $collectionId;
     $table->hits = 0;
     $table->hash = md5('tmp');
     $table->uid = $this->uid;
     $table->type = $this->type;
     $table->created = JFactory::getDate()->toSql();
     $table->user_id = FD::user()->id;
     $table->size = filesize($file['tmp_name']);
     $table->mime = $file['type'];
     $table->state = SOCIAL_STATE_PUBLISHED;
     $table->storage = SOCIAL_STORAGE_JOOMLA;
     // Try to store the data on the database.
     $table->store();
     // Now we need to really upload the file.
     $state = $table->storeWithFile($file);
     // Format the data now
     $result = $this->format(array($table));
     return $result[0];
 }
Пример #5
0
 /**
  * Allows caller to create an avatar by posted the $_FILE data
  *
  * @since   1.0
  * @access  public
  * @param   string
  * @return
  */
 public function createAvatarFromFile()
 {
     // Check for request forgeries
     FD::checkToken();
     // Only registered users should be allowed to upload photos
     FD::requireLogin();
     // Get the current view
     $view = $this->getCurrentView();
     $config = FD::config();
     // Get the unique item id
     $uid = JRequest::getInt('uid');
     $type = JRequest::getCmd('type');
     // Get current user.
     $my = FD::user();
     if (!$uid && !$type) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call('createAvatar');
     }
     // Load up the photo library
     $lib = FD::photo($uid, $type);
     // Set uploader options
     $options = array('name' => 'avatar_file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($file instanceof SocialException) {
         $view->setMessage($file);
         return $view->call('createAvatar');
     }
     // Load the image
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Check if there's a profile photos album that already exists.
     $albumModel = FD::model('Albums');
     // Retrieve the default album for this node.
     $album = $lib->getDefaultAlbum();
     $photo = FD::table('Photo');
     $photo->uid = $uid;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->ordering = 0;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // We need to set the photo state to "SOCIAL_PHOTOS_STATE_TMP"
     $photo->state = SOCIAL_PHOTOS_STATE_TMP;
     // Try to store the photo first
     $state = $photo->store();
     // Bind any exif data if there are any.
     // Only bind exif data for jpg files (if want to add tiff, then do add it here)
     if ($image->hasExifSupport()) {
         $photo->mapExif($file);
     }
     if (!$state) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_ERROR_CREATING_IMAGE_FILES'), SOCIAL_MSG_ERROR);
         return $view->call('createAvatar');
     }
     // Push all the ordering of the photo down
     $photosModel = FD::model('photos');
     $photosModel->pushPhotosOrdering($album->id, $photo->id);
     // Render photos library
     $photoLib = FD::get('Photos', $image);
     $storage = $photoLib->getStoragePath($album->id, $photo->id);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     foreach ($paths as $type => $fileName) {
         $meta = FD::table('PhotoMeta');
         $meta->photo_id = $photo->id;
         $meta->group = SOCIAL_PHOTOS_META_PATH;
         $meta->property = $type;
         $meta->value = $storage . '/' . $fileName;
         $meta->store();
     }
     // Retrieve the original photo again.
     $image = $photo->getImageObject('original');
     return $view->call('createAvatar', $photo);
 }
Пример #6
0
 public function addPhotoAlbum($log_usr = 0, $album_id)
 {
     $my = FD::user();
     // Load up the configuration
     $config = FD::config();
     // Load the album table
     $album = FD::table('Album');
     $album->load($album_id);
     // Check if the album id provided is valid
     if (!$album->id || !$album->id) {
         return "album not valid";
     }
     // Get the uid and the type
     $uid = $album->uid;
     $type = $album->type;
     // Load the photo library
     $lib = FD::photo($uid, $type);
     // Set uploader options
     $options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($file instanceof SocialException) {
         return false;
     }
     // Load the image object
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Detect if this is a really valid image file.
     if (!$image->isValid()) {
         return false;
     }
     // Bind the photo data now
     $photo = FD::table('Photo');
     $photo->uid = $uid;
     $photo->type = $type;
     $photo->user_id = $album->uid;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->ordering = 0;
     $photo->state = SOCIAL_STATE_PUBLISHED;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // Cleanup photo title.
     $photo->cleanupTitle();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     if (!$state) {
         return false;
     }
     // If album doesn't have a cover, set the current photo as the cover.
     //~ if (!$album->hasCover()) {
     //~ $album->cover_id    = $photo->id;
     //~
     //~ // Store the album
     //~ $album->store();
     //~ }
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     // Get the storage path for this photo
     $storageContainer = FD::cleanPath($config->get('photos.storage.container'));
     $storage = $photoLib->getStoragePath($album->id, $photo->id);
     $paths = $photoLib->create($storage);
     // We need to calculate the total size used in each photo (including all the variants)
     $totalSize = 0;
     // Create metadata about the photos
     if ($paths) {
         foreach ($paths as $type => $fileName) {
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_PATH;
             $meta->property = $type;
             // do not store the container path as this path might changed from time to time
             $tmpStorage = str_replace('/' . $storageContainer . '/', '/', $storage);
             $meta->value = $tmpStorage . '/' . $fileName;
             $meta->store();
             // We need to store the photos dimension here
             list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo size
             $totalSize += filesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo dimensions
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_WIDTH;
             $meta->property = $type;
             $meta->value = $width;
             $meta->store();
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_HEIGHT;
             $meta->property = $type;
             $meta->value = $height;
             $meta->store();
         }
     }
     // Set the total photo size
     $photo->total_size = $totalSize;
     $photo->store();
     // After storing the photo, trigger rules that should occur after a photo is stored
     $photo->afterStore($file, $image);
     // Determine if we should create a stream item for this upload
     $createStream = JRequest::getBool('createStream');
     // Add Stream when a new photo is uploaded
     if ($createStream) {
         $photo->addPhotosStream('create');
     }
     if ($isAvatar) {
         return $photo;
     }
     // After storing the photo, trigger rules that should occur after a photo is stored
     return $photo;
 }
Пример #7
0
 /**
  * Allows caller to upload a photo
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function upload()
 {
     // Check for request forgeries
     FD::checkToken();
     // Ensure that the user must be logged in
     FD::requireLogin();
     // Get the current view.
     $view = $this->getCurrentView();
     // Get the unique item stuffs
     $uid = JRequest::getInt('uid');
     $type = JRequest::getCmd('type');
     if (!$uid && !$type) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load the photo library now since we have the unique keys
     $lib = FD::photo($uid, $type);
     // Check if the user is allowed to upload cover photos
     if (!$lib->canUploadCovers()) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_NO_PERMISSION_TO_UPLOAD_COVER'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get the current logged in user.
     $my = FD::user();
     // Set uploader options
     $options = array('name' => 'cover_file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($file instanceof SocialException) {
         $view->setMessage($file);
         return $view->call(__FUNCTION__);
     }
     // Load the image
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Check if there's a profile photos album that already exists.
     $model = FD::model('Albums');
     // Retrieve the user's default album
     $album = $model->getDefaultAlbum($uid, $type, SOCIAL_ALBUM_PROFILE_COVERS);
     $photo = FD::table('Photo');
     $photo->uid = $uid;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->ordering = 0;
     $photo->assigned_date = FD::date()->toMySQL();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     if (!$state) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_ERROR_CREATING_IMAGE_FILES'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Trigger rules that should occur after a photo is stored
     $photo->afterStore($file, $image);
     // If album doesn't have a cover, set the current photo as the cover.
     if (!$album->hasCover()) {
         $album->cover_id = $photo->id;
         // Store the album
         $album->store();
     }
     // Render photos library
     $photoLib = FD::get('Photos', $image);
     $storage = $photoLib->getStoragePath($album->id, $photo->id);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     foreach ($paths as $type => $fileName) {
         $meta = FD::table('PhotoMeta');
         $meta->photo_id = $photo->id;
         $meta->group = SOCIAL_PHOTOS_META_PATH;
         $meta->property = $type;
         $meta->value = $storage . '/' . $fileName;
         $meta->store();
     }
     return $view->call(__FUNCTION__, $photo);
 }