summaryrefslogtreecommitdiff
path: root/actions/userauthorization.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-06-05 15:37:08 -0400
committerEvan Prodromou <evan@prodromou.name>2008-06-05 15:37:08 -0400
commit56021d95721c06b618dac6272e58d22a3e87037f (patch)
treef232f32b5f7e78f80704c76b1ec6e5d4fd633893 /actions/userauthorization.php
parentdcc915bd9305349ba6c1a0a716481de0806f5ecf (diff)
move avatar scaling and saving to Avatar and Profile
Extracted the code for setting a new original avatar to the Profile class, and moved some of it to Avatar, too. This makes it easier to have the same functionality whether an avatar is set using the profile settings (for our users), or on a remote subscription. Necessitated changing the filenaming function to just take an ID. darcs-hash:20080605193708-84dde-a441cc0474951ce7f1a1da9310b5145c0b7c3070.gz
Diffstat (limited to 'actions/userauthorization.php')
-rw-r--r--actions/userauthorization.php44
1 files changed, 3 insertions, 41 deletions
diff --git a/actions/userauthorization.php b/actions/userauthorization.php
index 94d92ea77..87040adad 100644
--- a/actions/userauthorization.php
+++ b/actions/userauthorization.php
@@ -257,7 +257,7 @@ class UserauthorizationAction extends Action {
}
if ($avatar_url) {
- $this->add_avatar($profile->id, $avatar_url);
+ $this->add_avatar($profile, $avatar_url);
}
$user = common_current_user();
@@ -278,47 +278,9 @@ class UserauthorizationAction extends Action {
}
function add_avatar($profile, $url) {
- $temp_filename = tempnam(sys_get_temp_dir(), 'ombavatar');
+ $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
copy($url, $temp_filename);
- $info = @getimagesize($temp_filename);
- $filename = common_avatar_filename($profile, image_type_to_extension($info[2]), NULL, common_timestamp());
- $filepath = common_avatar_path($filename);
- copy($temp_filename, $filename);
-
- $avatar = DB_DataObject::factory('avatar');
-
- $avatar->profile_id = $profile->id;
- $avatar->width = $info[0];
- $avatar->height = $info[1];
- $avatar->mediatype = image_type_to_mime_type($info[2]);
- $avatar->filename = $filename;
- $avatar->original = true;
- $avatar->url = common_avatar_url($filename);
- $avatar->created = DB_DataObject_Cast::dateTime(); # current time
-
- foreach (array(AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
- $scaled[] = $this->scale_avatar($user, $avatar, $size);
- }
-
- # XXX: start a transaction here
-
- if (!$this->delete_old_avatars($user)) {
- @unlink($filepath);
- common_server_error(_t('Error deleting old avatars.'));
- return;
- }
- if (!$avatar->insert()) {
- @unlink($filepath);
- common_server_error(_t('Error inserting avatar.'));
- return;
- }
-
- foreach ($scaled as $s) {
- if (!$s->insert()) {
- common_server_error(_t('Error inserting scaled avatar.'));
- return;
- }
- }
+ return $profile->setOriginal($temp_filename);
}
function show_accept_message($tok) {