Esempio n. 1
0
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     $orig = clone $this;
     $this->original_logo = Avatar::url($filename);
     $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
     $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE));
     $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE));
     common_debug(common_log_objstring($this));
     return $this->update($orig);
 }
Esempio n. 2
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropLogo()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         // TRANS: Server error displayed trying to crop an uploaded group logo that is no longer present.
         $this->serverError(_('Lost our file data.'));
         return;
     }
     // If image is not being cropped assume pos & dimentions of original
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $filedata['width'];
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $filedata['height'];
     $size = min($dest_w, $dest_h);
     $size = $size > MAX_ORIGINAL ? MAX_ORIGINAL : $size;
     $imagefile = new ImageFile($this->group->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($this->group->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         // TRANS: Form success message after updating a group logo.
         $this->showForm(_('Logo updated.'), true);
     } else {
         // TRANS: Form failure message after failing to update a group logo.
         $this->showForm(_('Failed updating logo.'));
     }
 }
Esempio n. 3
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropLogo()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         $this->serverError(_('Lost our file data.'));
         return;
     }
     // If image is not being cropped assume pos & dimentions of original
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $filedata['width'];
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $filedata['height'];
     $size = min($dest_w, $dest_h);
     $size = $size > MAX_ORIGINAL ? MAX_ORIGINAL : $size;
     $imagefile = new ImageFile($this->group->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($this->group->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         $this->showForm(_('Logo updated.'), true);
     } else {
         $this->showForm(_('Failed updating logo.'));
     }
 }
Esempio n. 4
0
 function setAvatar($user)
 {
     try {
         $picUrl = sprintf('http://graph.facebook.com/%d/picture?type=large', $this->fbuser->id);
         // fetch the picture from Facebook
         $client = new HTTPClient();
         // fetch the actual picture
         $response = $client->get($picUrl);
         if ($response->isOk()) {
             // seems to always be jpeg, but not sure
             $tmpname = "facebook-avatar-tmp-" . common_good_rand(4);
             $ok = file_put_contents(Avatar::path($tmpname), $response->getBody());
             if (!$ok) {
                 common_log(LOG_WARNING, 'Couldn\'t save tmp Facebook avatar: ' . $tmpname, __FILE__);
             } else {
                 // save it as an avatar
                 $file = new ImageFile($user->id, Avatar::path($tmpname));
                 $filename = $file->resize(180);
                 // size of the biggest img we get from Facebook
                 $profile = $user->getProfile();
                 if ($profile->setOriginal($filename)) {
                     common_log(LOG_INFO, sprintf('Saved avatar for %s (%d) from Facebook picture for ' . '%s (fbuid %d), filename = %s', $user->nickname, $user->id, $this->fbuser->name, $this->fbuid, $filename), __FILE__);
                     // clean up tmp file
                     @unlink(Avatar::path($tmpname));
                 }
             }
         }
     } catch (Exception $e) {
         common_log(LOG_WARNING, 'Couldn\'t save Facebook avatar: ' . $e->getMessage(), __FILE__);
         // error isn't fatal, continue
     }
 }
Esempio n. 5
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropAvatar()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         $this->serverError(_('Lost our file data.'));
         return;
     }
     $file_d = $filedata['width'] > $filedata['height'] ? $filedata['height'] : $filedata['width'];
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $file_d;
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $file_d;
     $size = min($dest_w, $dest_h, MAX_ORIGINAL);
     $user = common_current_user();
     $profile = $user->getProfile();
     $imagefile = new ImageFile($user->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($profile->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         $this->showForm(_('Avatar updated.'), true);
         common_broadcast_profile($profile);
     } else {
         $this->showForm(_('Failed updating avatar.'));
     }
 }
Esempio n. 6
0
 /**
  * Handle the results of jcrop.
  *
  * @return void
  */
 function cropAvatar()
 {
     $filedata = $_SESSION['FILEDATA'];
     if (!$filedata) {
         // TRANS: Server error displayed if an avatar upload went wrong somehow server side.
         $this->serverError(_('Lost our file data.'));
         return;
     }
     $file_d = $filedata['width'] > $filedata['height'] ? $filedata['height'] : $filedata['width'];
     $dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
     $dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
     $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $file_d;
     $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $file_d;
     $size = min($dest_w, $dest_h, MAX_ORIGINAL);
     $user = common_current_user();
     $profile = $user->getProfile();
     $imagefile = new ImageFile($user->id, $filedata['filepath']);
     $filename = $imagefile->resize($size, $dest_x, $dest_y, $dest_w, $dest_h);
     if ($profile->setOriginal($filename)) {
         @unlink($filedata['filepath']);
         unset($_SESSION['FILEDATA']);
         $this->mode = 'upload';
         // TRANS: Success message for having updated a user avatar.
         $this->showForm(_('Avatar updated.'), true);
         common_broadcast_profile($profile);
     } else {
         // TRANS: Error displayed on the avatar upload page if the avatar could not be updated for an unknown reason.
         $this->showForm(_('Failed updating avatar.'));
     }
 }
Esempio n. 7
0
 function setOriginal($filename)
 {
     $imagefile = new ImageFile($this->id, Avatar::path($filename));
     $avatar = new Avatar();
     $avatar->profile_id = $this->id;
     $avatar->width = $imagefile->width;
     $avatar->height = $imagefile->height;
     $avatar->mediatype = image_type_to_mime_type($imagefile->type);
     $avatar->filename = $filename;
     $avatar->original = true;
     $avatar->url = Avatar::url($filename);
     $avatar->created = DB_DataObject_Cast::dateTime();
     # current time
     # XXX: start a transaction here
     if (!$this->delete_avatars() || !$avatar->insert()) {
         @unlink(Avatar::path($filename));
         return null;
     }
     foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
         # We don't do a scaled one if original is our scaled size
         if (!($avatar->width == $size && $avatar->height == $size)) {
             $scaled_filename = $imagefile->resize($size);
             //$scaled = DB_DataObject::factory('avatar');
             $scaled = new Avatar();
             $scaled->profile_id = $this->id;
             $scaled->width = $size;
             $scaled->height = $size;
             $scaled->original = false;
             $scaled->mediatype = image_type_to_mime_type($imagefile->type);
             $scaled->filename = $scaled_filename;
             $scaled->url = Avatar::url($scaled_filename);
             $scaled->created = DB_DataObject_Cast::dateTime();
             # current time
             if (!$scaled->insert()) {
                 return null;
             }
         }
     }
     return $avatar;
 }