Browse Source

Merge pull request #9030 from annando/avatar-constant

Using a constant value for the default avatar
pull/9031/head
Hypolite Petovan 2 years ago committed by GitHub
parent
commit
4a1cf0e00a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mod/dfrn_confirm.php
  2. 3
      src/Content/Nav.php
  3. 2
      src/Factory/Notification/Introduction.php
  4. 22
      src/Model/Contact.php
  5. 6
      src/Model/Photo.php
  6. 8
      src/Module/Photo.php
  7. 3
      src/Network/Probe.php
  8. 3
      src/Util/Network.php

2
mod/dfrn_confirm.php

@ -481,7 +481,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if (DBA::isResult($contact)) {
$photo = $contact['photo'];
} else {
$photo = DI::baseUrl() . '/images/person-300.jpg';
$photo = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
}
Contact::updateAvatar($dfrn_record, $photo);

3
src/Content/Nav.php

@ -27,6 +27,7 @@ use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\User;
@ -183,7 +184,7 @@ class Nav
// user info
$contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
$userinfo = [
'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : 'images/person-48.jpg'),
'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : Contact::DEFAULT_AVATAR_MICRO),
'name' => $a->user['username'],
];
} else {

2
src/Factory/Notification/Introduction.php

@ -132,7 +132,7 @@ class Introduction extends BaseFactory
'madeby_zrl' => Contact::magicLink($notification['url']),
'madeby_addr' => $notification['addr'],
'contact_id' => $notification['contact-id'],
'photo' => (!empty($notification['fphoto']) ? Proxy::proxifyUrl($notification['fphoto'], false, Proxy::SIZE_SMALL) : "images/person-300.jpg"),
'photo' => (!empty($notification['fphoto']) ? Proxy::proxifyUrl($notification['fphoto'], false, Proxy::SIZE_SMALL) : Contact::DEFAULT_AVATAR_PHOTO),
'name' => $notification['fname'],
'url' => $notification['furl'],
'zrl' => Contact::magicLink($notification['furl']),

22
src/Model/Contact.php

@ -51,6 +51,10 @@ use Friendica\Util\Strings;
*/
class Contact
{
const DEFAULT_AVATAR_PHOTO = '/images/person-300.jpg';
const DEFAULT_AVATAR_THUMB = '/images/person-80.jpg';
const DEFAULT_AVATAR_MICRO = '/images/person-48.jpg';
/**
* @deprecated since version 2019.03
* @see User::PAGE_FLAGS_NORMAL
@ -644,9 +648,9 @@ class Contact
$fields['micro'] = $prefix . '6' . $suffix;
} else {
// We hadn't found a photo entry, so we use the default avatar
$fields['photo'] = DI::baseUrl() . '/images/person-300.jpg';
$fields['thumb'] = DI::baseUrl() . '/images/person-80.jpg';
$fields['micro'] = DI::baseUrl() . '/images/person-48.jpg';
$fields['photo'] = DI::baseUrl() . self::DEFAULT_AVATAR_PHOTO;
$fields['thumb'] = DI::baseUrl() . self::DEFAULT_AVATAR_THUMB;
$fields['micro'] = DI::baseUrl() . self::DEFAULT_AVATAR_MICRO;
}
$fields['avatar'] = DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix;
@ -1467,7 +1471,7 @@ class Contact
*/
public static function getPhoto(array $contact, string $avatar = '')
{
return self::getAvatarPath($contact, 'photo', DI::baseUrl() . '/images/person-300.jpg', Proxy::SIZE_SMALL, $avatar);
return self::getAvatarPath($contact, 'photo', DI::baseUrl() . self::DEFAULT_AVATAR_PHOTO, Proxy::SIZE_SMALL, $avatar);
}
/**
@ -1479,7 +1483,7 @@ class Contact
*/
public static function getThumb(array $contact, string $avatar = '')
{
return self::getAvatarPath($contact, 'thumb', DI::baseUrl() . '/images/person-80.jpg', Proxy::SIZE_THUMB, $avatar);
return self::getAvatarPath($contact, 'thumb', DI::baseUrl() . self::DEFAULT_AVATAR_THUMB, Proxy::SIZE_THUMB, $avatar);
}
/**
@ -1491,7 +1495,7 @@ class Contact
*/
public static function getMicro(array $contact, string $avatar = '')
{
return self::getAvatarPath($contact, 'micro', DI::baseUrl() . '/images/person-48.jpg', Proxy::SIZE_MICRO, $avatar);
return self::getAvatarPath($contact, 'micro', DI::baseUrl() . self::DEFAULT_AVATAR_MICRO, Proxy::SIZE_MICRO, $avatar);
}
/**
@ -1530,13 +1534,13 @@ class Contact
/// add the default avatars if the fields aren't filled
if (isset($contact['photo']) && empty($contact['photo'])) {
$contact['photo'] = DI::baseUrl() . '/images/person-300.jpg';
$contact['photo'] = DI::baseUrl() . self::DEFAULT_AVATAR_PHOTO;
}
if (isset($contact['thumb']) && empty($contact['thumb'])) {
$contact['thumb'] = DI::baseUrl() . '/images/person-80.jpg';
$contact['thumb'] = DI::baseUrl() . self::DEFAULT_AVATAR_THUMB;
}
if (isset($contact['micro']) && empty($contact['micro'])) {
$contact['micro'] = DI::baseUrl() . '/images/person-48.jpg';
$contact['micro'] = DI::baseUrl() . self::DEFAULT_AVATAR_MICRO;
}
return $contact;

6
src/Model/Photo.php

@ -492,9 +492,9 @@ class Photo
}
if ($photo_failure) {
$image_url = DI::baseUrl() . "/images/person-300.jpg";
$thumb = DI::baseUrl() . "/images/person-80.jpg";
$micro = DI::baseUrl() . "/images/person-48.jpg";
$image_url = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
$thumb = DI::baseUrl() . Contact::DEFAULT_AVATAR_THUMB;
$micro = DI::baseUrl() . Contact::DEFAULT_AVATAR_MICRO;
}
return [$image_url, $thumb, $micro];

8
src/Module/Photo.php

@ -23,8 +23,8 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Photo as MPhoto;
/**
@ -139,16 +139,16 @@ class Photo extends BaseModule
case "profile":
case "custom":
$scale = 4;
$default = "images/person-300.jpg";
$default = Contact::DEFAULT_AVATAR_PHOTO;
break;
case "micro":
$scale = 6;
$default = "images/person-48.jpg";
$default = Contact::DEFAULT_AVATAR_MICRO;
break;
case "avatar":
default:
$scale = 5;
$default = "images/person-80.jpg";
$default = Contact::DEFAULT_AVATAR_THUMB;
}
$photo = MPhoto::selectFirst([], ["scale" => $scale, "uid" => $uid, "profile" => 1]);

3
src/Network/Probe.php

@ -29,6 +29,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\GServer;
use Friendica\Model\Profile;
use Friendica\Model\User;
@ -369,7 +370,7 @@ class Probe
}
if (empty($data['photo'])) {
$data['photo'] = DI::baseUrl() . '/images/person-300.jpg';
$data['photo'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
}
if (empty($data['name'])) {

3
src/Util/Network.php

@ -24,6 +24,7 @@ namespace Friendica\Util;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Contact;
class Network
{
@ -235,7 +236,7 @@ class Network
Hook::callAll('avatar_lookup', $avatar);
if (! $avatar['success']) {
$avatar['url'] = DI::baseUrl() . '/images/person-300.jpg';
$avatar['url'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
}
Logger::log('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], Logger::DEBUG);

Loading…
Cancel
Save