common_element('input', array('name' => 'avatarfile',
'type' => 'file',
'id' => 'avatarfile'));
- common_element('input', array('name' => 'submit',
- 'type' => 'submit',
- 'id' => 'submit',
- 'value' =>_t('Upload')));
+ common_submit('submit', _t('Upload'));
common_element_end('form');
common_show_footer();
}
$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]), NULL, common_timestamp());
$filepath = common_avatar_path($filename);
if (!move_uploaded_file($_FILES['avatarfile']['tmp_name'], $filepath)) {
$avatar->url = common_avatar_url($filename);
$avatar->created = DB_DataObject_Cast::dateTime(); # current time
- $val = $avatar->validate();
-
- if ($val !== TRUE) {
- $err = '';
- foreach ($val as $k=>$v) {
- $err .= _t('Something wrong with ') . $k;
- $this->show_form($err);
- return;
- }
- }
-
foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
- $scaled[] = $this->scale_avatar($user, $avatar, $size);
+ # We don't need a scaled one if the original is already of that size!
+ if ($avatar->width != $size && $avatar->height != $size) {
+ $scaled[] = $this->scale_avatar($user, $avatar, $size);
+ }
}
# XXX: start a transaction here
imagecopyresampled($image_s, $image_a, 0, 0, 0, 0,
$size, $size, $square, $square);
- $ext = ($avatar->mediattype == 'image/jpeg') ? ".jpg" : ".png";
+ $ext = ($avatar->mediattype == 'image/jpeg') ? ".jpeg" : ".png";
- $filename = common_avatar_filename($user, $ext, $size);
+ $filename = common_avatar_filename($user, $ext, $size, common_timestamp());
if ($avatar->mediatype == 'image/jpeg') {
imagejpeg($image_s, common_avatar_path($filename));