Don't store the default header in the contact table
This commit is contained in:
parent
618903fef7
commit
bbda69a736
2 changed files with 57 additions and 38 deletions
|
@ -1660,6 +1660,59 @@ class Contact
|
|||
return $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the default header for the given contact
|
||||
*
|
||||
* @param array $contact contact array
|
||||
* @return string avatar URL
|
||||
*/
|
||||
public static function getDefaultHeader(array $contact): string
|
||||
{
|
||||
if (!empty($contact['header']) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
return DI::baseUrl() . '/images/blank.png';
|
||||
}
|
||||
|
||||
if (!empty($contact['gsid'])) {
|
||||
// Use default banners for certain platforms
|
||||
$gserver = DBA::selectFirst('gserver', ['platform'], ['id' => $contact['gsid']]);
|
||||
$platform = strtolower($gserver['platform'] ?? '');
|
||||
} else {
|
||||
$platform = '';
|
||||
}
|
||||
|
||||
switch ($platform) {
|
||||
case 'friendica':
|
||||
case 'friendika':
|
||||
/**
|
||||
* Picture credits
|
||||
* @author Lostinlight <https://mastodon.xyz/@lightone>
|
||||
* @license CC0 https://creativecommons.org/share-your-work/public-domain/cc0/
|
||||
* @link https://gitlab.com/lostinlight/per_aspera_ad_astra/-/blob/master/friendica-404/friendica-promo-bubbles.jpg
|
||||
*/
|
||||
$header = DI::baseUrl() . '/images/friendica-banner.jpg';
|
||||
break;
|
||||
case 'diaspora':
|
||||
/**
|
||||
* Picture credits
|
||||
* @author John Liu <https://www.flickr.com/photos/8047705@N02/>
|
||||
* @license CC BY 2.0 https://creativecommons.org/licenses/by/2.0/
|
||||
* @link https://www.flickr.com/photos/8047705@N02/5572197407
|
||||
*/
|
||||
$header = DI::baseUrl() . '/images/diaspora-banner.jpg';
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* Use random pictures for networks that don't provide banners.
|
||||
* The service provides random pictures from Unsplash.
|
||||
* @license https://unsplash.com/license
|
||||
*/
|
||||
$header = 'https://picsum.photos/seed/' . hash('ripemd128', $contact['url']) . '/960/300';
|
||||
break;
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the default avatar for the given contact and size
|
||||
*
|
||||
|
@ -2202,41 +2255,6 @@ class Contact
|
|||
$update = false;
|
||||
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
|
||||
|
||||
if (empty($ret['header']) && !empty($gsid)) {
|
||||
// Use default banners for certain platforms
|
||||
$gserver = DBA::selectFirst('gserver', ['platform'], ['id' => $gsid]);
|
||||
switch (strtolower($gserver['platform'] ?? '')) {
|
||||
case 'friendica':
|
||||
case 'friendika':
|
||||
/**
|
||||
* Picture credits
|
||||
* @author Lostinlight <https://mastodon.xyz/@lightone>
|
||||
* @license CC0 https://creativecommons.org/share-your-work/public-domain/cc0/
|
||||
* @link https://gitlab.com/lostinlight/per_aspera_ad_astra/-/blob/master/friendica-404/friendica-promo-bubbles.jpg
|
||||
*/
|
||||
$ret['header'] = DI::baseUrl() . '/images/friendica-banner.jpg';
|
||||
break;
|
||||
case 'diaspora':
|
||||
/**
|
||||
* Picture credits
|
||||
* @author John Liu <https://www.flickr.com/photos/8047705@N02/>
|
||||
* @license CC BY 2.0 https://creativecommons.org/licenses/by/2.0/
|
||||
* @link https://www.flickr.com/photos/8047705@N02/5572197407
|
||||
*/
|
||||
$ret['header'] = DI::baseUrl() . '/images/diaspora-banner.jpg';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($ret['header']) && !in_array($ret['network'], [Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
/**
|
||||
* Use random pictures for networks that don't provide banners.
|
||||
* The service provides random pictures from Unsplash.
|
||||
* @license https://unsplash.com/license
|
||||
*/
|
||||
$ret['header'] = 'https://picsum.photos/seed/' . hash('ripemd128', $ret['url']) . '/960/300';
|
||||
}
|
||||
|
||||
// make sure to not overwrite existing values with blank entries except some technical fields
|
||||
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
|
||||
foreach ($ret as $key => $val) {
|
||||
|
|
|
@ -310,17 +310,18 @@ class Photo extends BaseModule
|
|||
}
|
||||
return MPhoto::createPhotoForExternalResource($url, 0, $mimetext);
|
||||
case "header":
|
||||
$contact = Contact::getById($id, ['uid', 'url', 'header']);
|
||||
$fields = ['uid', 'url', 'header', 'network', 'gsid'];
|
||||
$contact = Contact::getById($id, $fields);
|
||||
if (empty($contact)) {
|
||||
return false;
|
||||
}
|
||||
If (($contact['uid'] != 0) && empty($contact['header'])) {
|
||||
$contact = Contact::getByURL($contact['url'], false, ['header']);
|
||||
$contact = Contact::getByURL($contact['url'], false, $fields);
|
||||
}
|
||||
if (!empty($contact['header'])) {
|
||||
$url = $contact['header'];
|
||||
} else {
|
||||
$url = DI::baseUrl() . '/images/blank.png';
|
||||
$url = Contact::getDefaultHeader($contact);
|
||||
}
|
||||
return MPhoto::createPhotoForExternalResource($url);
|
||||
case "banner":
|
||||
|
|
Loading…
Reference in a new issue