Beispiel #1
0
 /**
  * Some desc
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function createCover($file, $inputName)
 {
     // Load our own image library
     $image = FD::image();
     // Generates a unique name for this image.
     $name = $file['name'];
     // Load up the file.
     $image->load($file['tmp_name'], $name);
     // Ensure that the image is valid.
     if (!$image->isValid()) {
         // @TODO: Add some logging here.
         echo JText::_('PLG_FIELDS_AVATAR_VALIDATION_INVALID_IMAGE');
         exit;
     }
     // Get the storage path
     $storage = SocialFieldsUserCoverHelper::getStoragePath($inputName);
     // Create a new avatar object.
     $photos = FD::get('Photos', $image);
     // Create avatars
     $sizes = $photos->create($storage);
     // We want to format the output to get the full absolute url.
     $base = basename($storage);
     $result = array();
     foreach ($sizes as $size => $value) {
         $row = new stdClass();
         $row->title = $file['name'];
         $row->file = $value;
         $row->path = JPATH_ROOT . '/media/com_easysocial/tmp/' . $base . '/' . $value;
         $row->uri = rtrim(JURI::root(), '/') . '/media/com_easysocial/tmp/' . $base . '/' . $value;
         $result[$size] = $row;
     }
     return $result;
 }
 public function ajax_cover($file, $uname = 'cover_file')
 {
     /*
     $cls_obj = new SocialFieldsUserCover();
     $cover_obj = $cls_obj->createCover($file,$uname);
     
     return $cover_obj;
     */
     // Load our own image library
     $image = FD::image();
     // Generates a unique name for this image.
     $name = $file['name'];
     // Load up the file.
     $image->load($file['tmp_name'], $name);
     // Ensure that the image is valid.
     if (!$image->isValid()) {
         return false;
         //need error code here
     }
     // Get the storage path
     $storage = SocialFieldsUserCoverHelper::getStoragePath($uname);
     // Create a new avatar object.
     $photos = FD::get('Photos', $image);
     // Create avatars
     $sizes = $photos->create($storage);
     // We want to format the output to get the full absolute url.
     $base = basename($storage);
     $result = array();
     foreach ($sizes as $size => $value) {
         $row = new stdClass();
         $row->title = $file['name'];
         $row->file = $value;
         $row->path = JPATH_ROOT . '/media/com_easysocial/tmp/' . $base . '/' . $value;
         $row->uri = rtrim(JURI::root(), '/') . '/media/com_easysocial/tmp/' . $base . '/' . $value;
         $result[$size] = $row;
     }
     return $result;
 }
Beispiel #3
0
 public function saveCover(&$post, $uid, $type)
 {
     $coverData = !empty($post[$this->inputName]) ? $post[$this->inputName] : '';
     unset($post[$this->inputName]);
     if (empty($coverData)) {
         return true;
     }
     $coverData = FD::makeObject($coverData);
     // Get the cover table.
     $cover = FD::table('Cover');
     // Try to load existing cover
     $state = $cover->load(array('uid' => $uid, 'type' => $type));
     // If no existing cover, then we set the uid and type.
     if (!$state) {
         $cover->uid = $uid;
         $cover->type = $type;
     }
     // If both data does not exist, then we don't proceed to store the data.
     if (empty($coverData->data) && empty($coverData->position)) {
         return true;
     }
     if (!empty($coverData->data)) {
         if ($coverData->data === 'delete') {
             $cover->delete();
             return true;
         }
         $coverObj = FD::makeObject($coverData->data);
         // Get the cover album.
         $album = SocialFieldsUserCoverHelper::getDefaultAlbum($uid, $type);
         // Create the photo object.
         $photo = SocialFieldsUserCoverHelper::createPhotoObject($uid, $type, $album->id, $coverObj->stock->title, false);
         // If there are no cover set for this album, set it as cover.
         if (empty($album->cover_id)) {
             $album->cover_id = $photo->id;
             $album->store();
         }
         // Construct the path to where the photo is temporarily uploaded.
         // $tmpPath = SocialFieldsUserCoverHelper::getPath($this->inputName);
         $tmpPath = dirname($coverObj->stock->path);
         // Get the supposed path of where the cover should be
         // Instead of doing SocialPhotos::getStoragePath, I copied the logic from there but only to create the folders up until albumId section.
         // We do not want JPATH_ROOT to be included in the $storage variable
         $storage = '/' . FD::cleanPath(FD::config()->get('photos.storage.container'));
         FD::makeFolder(JPATH_ROOT . $storage);
         $storage .= '/' . $album->id;
         FD::makeFolder(JPATH_ROOT . $storage);
         $storage .= '/' . $photo->id;
         FD::makeFolder(JPATH_ROOT . $storage);
         // Copy the photo from the temporary path to the storage folder.
         $state = JFolder::copy($tmpPath, JPATH_ROOT . $storage, '', true);
         // If cannot copy out the photo, then don't proceed
         if ($state !== true) {
             $this->setError(JText::_('PLG_FIELDS_COVER_ERROR_UNABLE_TO_MOVE_FILE'));
             return false;
         }
         // Create the photo meta for each available sizes.
         foreach ($coverObj as $key => $value) {
             SocialFieldsUserCoverHelper::createPhotoMeta($photo, $key, $storage . '/' . $value->file);
         }
         // Set the uploaded photo as cover for this user.
         $cover->setPhotoAsCover($photo->id);
     }
     // Set the position of the cover if available.
     if (!empty($coverData->position)) {
         $position = FD::makeObject($coverData->position);
         if (isset($position->x)) {
             $cover->x = $position->x;
         }
         if (isset($position->y)) {
             $cover->y = $position->y;
         }
     }
     // Store the cover object
     $cover->store();
     // And we're done.
     return true;
 }
Beispiel #4
0
 public static function getStoragePath($inputName)
 {
     $path = SocialFieldsUserCoverHelper::getPath($inputName);
     // If the folder exists, delete them first.
     if (JFolder::exists($path)) {
         JFolder::delete($path);
     }
     // Create folder if necessary.
     FD::makeFolder($path);
     // Re-generate the storage path since we do not want to store the JPATH_ROOT
     $path = str_replace(JPATH_ROOT, '', $path);
     return $path;
 }