forked from GNUsocial/gnu-social
Properly unlink all old avatars when deleting/uploading a new
We're also now using $config['image']['jpegquality'] to determine the quality setting for resized images. To set Avatar max size, adjust $config['avatar']['maxsize'] The getAvatar call now throws exceptions too. Related changes applied. Now let's move Profile->avatarUrl to the Avatar class!
This commit is contained in:
@@ -141,33 +141,27 @@ class AutocompleteAction extends Action
|
||||
$results = array();
|
||||
foreach($this->users as $user){
|
||||
$profile = $user->getProfile();
|
||||
$avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
|
||||
// sigh.... encapsulate this upstream!
|
||||
if ($avatar) {
|
||||
$avatar = $avatar->displayUrl();
|
||||
} else {
|
||||
$avatar = Avatar::defaultImage(AVATAR_MINI_SIZE);
|
||||
}
|
||||
$avatarUrl = $profile->avatarUrl(AVATAR_MINI_SIZE);
|
||||
$results[] = array(
|
||||
'value' => '@'.$profile->nickname,
|
||||
'nickname' => $profile->nickname,
|
||||
'label'=> $profile->getFancyName(),
|
||||
'avatar' => $avatar,
|
||||
'avatar' => $avatarUrl,
|
||||
'type' => 'user'
|
||||
);
|
||||
}
|
||||
foreach($this->groups as $group){
|
||||
// sigh.... encapsulate this upstream!
|
||||
if ($group->mini_logo) {
|
||||
$avatar = $group->mini_logo;
|
||||
$avatarUrl = $group->mini_logo;
|
||||
} else {
|
||||
$avatar = User_group::defaultLogo(AVATAR_MINI_SIZE);
|
||||
$avatarUrl = User_group::defaultLogo(AVATAR_MINI_SIZE);
|
||||
}
|
||||
$results[] = array(
|
||||
'value' => '!'.$group->nickname,
|
||||
'nickname' => $group->nickname,
|
||||
'label'=> $group->getFancyName(),
|
||||
'avatar' => $avatar,
|
||||
'avatar' => $avatarUrl,
|
||||
'type' => 'group');
|
||||
}
|
||||
print json_encode($results);
|
||||
|
@@ -97,7 +97,6 @@ class ApiTimelineBookmarksAction extends ApiBareAuthAction
|
||||
function showTimeline()
|
||||
{
|
||||
$profile = $this->user->getProfile();
|
||||
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
|
||||
$sitename = common_config('site', 'name');
|
||||
$title = sprintf(
|
||||
@@ -120,15 +119,10 @@ class ApiTimelineBookmarksAction extends ApiBareAuthAction
|
||||
$profile->getBestName(),
|
||||
$this->user->nickname
|
||||
);
|
||||
$logo = !empty($avatar)
|
||||
? $avatar->displayUrl()
|
||||
: Avatar::defaultImage(AVATAR_PROFILE_SIZE);
|
||||
|
||||
$link = common_local_url(
|
||||
'bookmarks',
|
||||
array('nickname' => $this->user->nickname)
|
||||
);
|
||||
|
||||
$logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
|
||||
$link = common_local_url('bookmarks',
|
||||
array('nickname' => $this->user->nickname));
|
||||
$self = $this->getSelfUri();
|
||||
|
||||
switch($this->format) {
|
||||
|
@@ -151,7 +151,7 @@ class UserEmailSummaryHandler extends QueueHandler
|
||||
continue;
|
||||
}
|
||||
|
||||
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
|
||||
$avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
|
||||
|
||||
$out->elementStart('tr');
|
||||
$out->elementStart('td', array('width' => AVATAR_STREAM_SIZE,
|
||||
@@ -159,9 +159,7 @@ class UserEmailSummaryHandler extends QueueHandler
|
||||
'align' => 'left',
|
||||
'valign' => 'top',
|
||||
'style' => 'border-bottom: 1px dotted #C5CEE3; padding: 10px 6px 10px 6px;'));
|
||||
$out->element('img', array('src' => ($avatar) ?
|
||||
$avatar->displayUrl() :
|
||||
Avatar::defaultImage(AVATAR_STREAM_SIZE),
|
||||
$out->element('img', array('src' => $avatarUrl,
|
||||
'width' => AVATAR_STREAM_SIZE,
|
||||
'height' => AVATAR_STREAM_SIZE,
|
||||
'alt' => $profile->getBestName()));
|
||||
|
@@ -46,7 +46,6 @@ class BioAction extends Action
|
||||
$this->profile = Profile::getKV('nickname', $args[1]['nickname']);
|
||||
//die(print_r($this->profile));
|
||||
gnusocial_profile_merge($this->profile);
|
||||
$this->avatar = $this->profile->getAvatar(96);
|
||||
|
||||
return true;
|
||||
|
||||
|
@@ -174,9 +174,12 @@ class ShowgroupmessageAction extends Action
|
||||
*/
|
||||
function etag()
|
||||
{
|
||||
$avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
|
||||
|
||||
$avtime = ($avatar) ? strtotime($avatar->modified) : 0;
|
||||
try {
|
||||
$avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
|
||||
$avtime = strtotime($avatar->modified);
|
||||
} catch (Exception $e) {
|
||||
$avtime = 0;
|
||||
}
|
||||
|
||||
return 'W/"' . implode(':', array($this->arg('action'),
|
||||
common_user_cache_hash(),
|
||||
|
@@ -78,10 +78,8 @@ class GroupMessageListItem extends Widget
|
||||
$this->out->elementStart('a',
|
||||
array('href' => $sender->profileurl,
|
||||
'class' => 'url'));
|
||||
$avatar = $sender->getAvatar(AVATAR_STREAM_SIZE);
|
||||
$this->out->element('img', array('src' => ($avatar) ?
|
||||
$avatar->displayUrl() :
|
||||
Avatar::defaultImage(AVATAR_STREAM_SIZE),
|
||||
$avatarUrl = $sender->avatarUrl(AVATAR_STREAM_SIZE);
|
||||
$this->out->element('img', array('src' => $avatarUrl,
|
||||
'width' => AVATAR_STREAM_SIZE,
|
||||
'height' => AVATAR_STREAM_SIZE,
|
||||
'class' => 'photo avatar',
|
||||
|
@@ -142,8 +142,7 @@ class OStatusSubAction extends Action
|
||||
$ok = true;
|
||||
}
|
||||
|
||||
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
$avatarUrl = $avatar ? $avatar->displayUrl() : false;
|
||||
$avatar = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
|
||||
|
||||
$this->showEntity($profile,
|
||||
$profile->profileurl,
|
||||
@@ -159,10 +158,6 @@ class OStatusSubAction extends Action
|
||||
$homepage = $entity->homepage;
|
||||
$location = $entity->location;
|
||||
|
||||
if (!$avatar) {
|
||||
$avatar = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
|
||||
}
|
||||
|
||||
$this->elementStart('div', 'entity_profile vcard');
|
||||
$this->element('img', array('src' => $avatar,
|
||||
'class' => 'photo avatar entity_depiction',
|
||||
|
@@ -96,7 +96,11 @@ class QnashowanswerAction extends ShownoticeAction
|
||||
throw new ServerException(_m('User without a profile.'));
|
||||
}
|
||||
|
||||
$this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
try {
|
||||
$this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
} catch (Exception $e) {
|
||||
$this->avatar = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -90,7 +90,11 @@ class QnashowquestionAction extends ShownoticeAction
|
||||
throw new ServerException(_m('User without a profile.'));
|
||||
}
|
||||
|
||||
$this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
try {
|
||||
$this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
|
||||
} catch (Exception $e) {
|
||||
$this->avatar = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ class EditMirrorForm extends Form
|
||||
$this->out->hidden('profile', $this->profile->id);
|
||||
|
||||
$this->out->elementStart('div', array('style' => 'float: left; width: 80px;'));
|
||||
$img = $this->getAvatar($this->profile);
|
||||
$img = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
|
||||
$feed = $this->getFeed($this->profile);
|
||||
$this->out->elementStart('a', array('href' => $this->profile->profileurl));
|
||||
$this->out->element('img', array('src' => $img, 'style' => 'float: left'));
|
||||
@@ -130,16 +130,6 @@ class EditMirrorForm extends Form
|
||||
$this->out->elementEnd('fieldset');
|
||||
}
|
||||
|
||||
private function getAvatar($profile)
|
||||
{
|
||||
$avatar = $this->profile->getAvatar(48);
|
||||
if ($avatar) {
|
||||
return $avatar->displayUrl();
|
||||
} else {
|
||||
return Avatar::defaultImage(48);
|
||||
}
|
||||
}
|
||||
|
||||
private function getFeed($profile)
|
||||
{
|
||||
// Ok this is a bit of a hack. ;)
|
||||
|
@@ -341,7 +341,14 @@ class TwitterImport
|
||||
|
||||
$newname = 'Twitter_' . $twitter_user->id . '_' . basename($twitter_user->profile_image_url);
|
||||
|
||||
$oldname = $profile->getAvatar(48)->filename;
|
||||
try {
|
||||
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
|
||||
$oldname = $avatar->filename;
|
||||
unset($avatar);
|
||||
} catch (Exception $e) {
|
||||
$oldname = null;
|
||||
}
|
||||
|
||||
|
||||
if ($newname != $oldname) {
|
||||
common_debug($this->name() . ' - Avatar for Twitter user ' .
|
||||
@@ -351,7 +358,7 @@ class TwitterImport
|
||||
$this->updateAvatars($twitter_user, $profile);
|
||||
}
|
||||
|
||||
if ($this->missingAvatarFile($profile)) {
|
||||
if (Avatar::hasOriginal($profile)) {
|
||||
common_debug($this->name() . ' - Twitter user ' .
|
||||
$profile->nickname .
|
||||
' is missing one or more local avatars.');
|
||||
@@ -382,17 +389,6 @@ class TwitterImport
|
||||
}
|
||||
}
|
||||
|
||||
function missingAvatarFile($profile) {
|
||||
foreach (array(24, 48, 73) as $size) {
|
||||
$filename = $profile->getAvatar($size)->filename;
|
||||
$avatarpath = Avatar::path($filename);
|
||||
if (file_exists($avatarpath) == FALSE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getMediatype($ext)
|
||||
{
|
||||
$mediatype = null;
|
||||
@@ -447,13 +443,7 @@ class TwitterImport
|
||||
return;
|
||||
}
|
||||
|
||||
$sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73);
|
||||
$avatar = $profile->getAvatar($sizes[$size]);
|
||||
|
||||
// Delete the avatar, if present
|
||||
if ($avatar) {
|
||||
$avatar->delete();
|
||||
}
|
||||
Avatar::deleteFromProfile($profile);
|
||||
|
||||
$this->newAvatar($profile->id, $size, $mediatype, $filename);
|
||||
}
|
||||
|
Reference in New Issue
Block a user