timestamps for avatar
darcs-hash:20080518194653-84dde-33205b1f2f6297006d63aec41fa91a8bcffda1ef.gz
This commit is contained in:
parent
6396504aa6
commit
88483fe3b8
@ -102,7 +102,7 @@ class AvatarAction extends SettingsAction {
|
|||||||
$this->show_form(_t('Unsupported image file format.'));
|
$this->show_form(_t('Unsupported image file format.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
|
||||||
$filename = common_avatar_filename($user, image_type_to_extension($info[2]));
|
$filename = common_avatar_filename($user, image_type_to_extension($info[2]));
|
||||||
@ -124,6 +124,7 @@ class AvatarAction extends SettingsAction {
|
|||||||
$avatar->original = true;
|
$avatar->original = true;
|
||||||
$avatar->url = common_avatar_url($filename);
|
$avatar->url = common_avatar_url($filename);
|
||||||
$avatar->created = DB_DataObject_Cast::dateTime(); # current time
|
$avatar->created = DB_DataObject_Cast::dateTime(); # current time
|
||||||
|
|
||||||
foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
|
foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
|
||||||
$scaled[] = $this->scale_avatar($user, $avatar, $size);
|
$scaled[] = $this->scale_avatar($user, $avatar, $size);
|
||||||
}
|
}
|
||||||
@ -153,26 +154,26 @@ class AvatarAction extends SettingsAction {
|
|||||||
|
|
||||||
$this->show_form(_t('Avatar updated.'), true);
|
$this->show_form(_t('Avatar updated.'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scale_avatar($user, $avatar, $size) {
|
function scale_avatar($user, $avatar, $size) {
|
||||||
$image_s = imagecreatetruecolor($size, $size);
|
$image_s = imagecreatetruecolor($size, $size);
|
||||||
$image_a = $this->avatar_to_image($avatar);
|
$image_a = $this->avatar_to_image($avatar);
|
||||||
|
|
||||||
$square = min($avatar->width, $avatar->height);
|
$square = min($avatar->width, $avatar->height);
|
||||||
|
|
||||||
imagecopyresampled($image_s, $image_a, 0, 0, 0, 0,
|
imagecopyresampled($image_s, $image_a, 0, 0, 0, 0,
|
||||||
$size, $size, $square, $square);
|
$size, $size, $square, $square);
|
||||||
|
|
||||||
$ext = ($avatar->mediattype == 'image/jpeg') ? ".jpg" : ".png";
|
$ext = ($avatar->mediattype == 'image/jpeg') ? ".jpg" : ".png";
|
||||||
|
|
||||||
$filename = common_avatar_filename($user, $ext, $size);
|
$filename = common_avatar_filename($user, $ext, $size);
|
||||||
|
|
||||||
if ($avatar->mediatype == 'image/jpeg') {
|
if ($avatar->mediatype == 'image/jpeg') {
|
||||||
imagejpeg($image_s, common_avatar_path($filename));
|
imagejpeg($image_s, common_avatar_path($filename));
|
||||||
} else {
|
} else {
|
||||||
imagepng($image_s, common_avatar_path($filename));
|
imagepng($image_s, common_avatar_path($filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
$scaled = DB_DataObject::factory('avatar');
|
$scaled = DB_DataObject::factory('avatar');
|
||||||
$scaled->profile_id = $avatar->profile_id;
|
$scaled->profile_id = $avatar->profile_id;
|
||||||
$scaled->width = $size;
|
$scaled->width = $size;
|
||||||
@ -182,16 +183,16 @@ class AvatarAction extends SettingsAction {
|
|||||||
$scaled->filename = $filename;
|
$scaled->filename = $filename;
|
||||||
$scaled->url = common_avatar_url($filename);
|
$scaled->url = common_avatar_url($filename);
|
||||||
$scaled->created = DB_DataObject_Cast::dateTime(); # current time
|
$scaled->created = DB_DataObject_Cast::dateTime(); # current time
|
||||||
|
|
||||||
return $scaled;
|
return $scaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function avatar_to_image($avatar) {
|
function avatar_to_image($avatar) {
|
||||||
$filepath = common_avatar_path($avatar->filename);
|
$filepath = common_avatar_path($avatar->filename);
|
||||||
if ($avatar->mediatype == 'image/gif') {
|
if ($avatar->mediatype == 'image/gif') {
|
||||||
return imagecreatefromgif($filepath);
|
return imagecreatefromgif($filepath);
|
||||||
} else if ($avatar->mediatype == 'image/jpeg') {
|
} else if ($avatar->mediatype == 'image/jpeg') {
|
||||||
return imagecreatefromjpeg($filepath);
|
return imagecreatefromjpeg($filepath);
|
||||||
} else if ($avatar->mediatype == 'image/png') {
|
} else if ($avatar->mediatype == 'image/png') {
|
||||||
return imagecreatefrompng($filepath);
|
return imagecreatefrompng($filepath);
|
||||||
} else {
|
} else {
|
||||||
@ -199,7 +200,7 @@ class AvatarAction extends SettingsAction {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_old_avatars($user) {
|
function delete_old_avatars($user) {
|
||||||
$avatar = DB_DataObject::factory('avatar');
|
$avatar = DB_DataObject::factory('avatar');
|
||||||
$avatar->profile_id = $user->id;
|
$avatar->profile_id = $user->id;
|
||||||
|
@ -22,6 +22,8 @@ create table avatar (
|
|||||||
mediatype varchar(32) not null comment 'file type',
|
mediatype varchar(32) not null comment 'file type',
|
||||||
filename varchar(255) null comment 'local filename, if local',
|
filename varchar(255) null comment 'local filename, if local',
|
||||||
url varchar(255) unique key comment 'avatar location',
|
url varchar(255) unique key comment 'avatar location',
|
||||||
|
created datetime not null comment 'date this record was created',
|
||||||
|
modified timestamp comment 'date this record was modified',
|
||||||
|
|
||||||
constraint primary key (profile_id, width, height),
|
constraint primary key (profile_id, width, height),
|
||||||
index avatar_profile_id_idx (profile_id)
|
index avatar_profile_id_idx (profile_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user