Display the contact alias if the URL is no HTTP link

This commit is contained in:
Michael 2023-06-18 16:49:38 +00:00
parent 6d911a8f39
commit 4c3f2441f7
16 changed files with 528 additions and 303 deletions

View file

@ -23,7 +23,7 @@ namespace Friendica\Model;
use Friendica\Contact\Avatar;
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
use Friendica\Content\Conversation As ConversationContent;
use Friendica\Content\Conversation as ConversationContent;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
@ -111,12 +111,12 @@ class Contact
* @}
*/
const MIRROR_DEACTIVATED = 0;
const MIRROR_FORWARDED = 1; // Deprecated, now does the same like MIRROR_OWN_POST
const MIRROR_OWN_POST = 2;
const MIRROR_NATIVE_RESHARE = 3;
const MIRROR_DEACTIVATED = 0;
const MIRROR_FORWARDED = 1; // Deprecated, now does the same like MIRROR_OWN_POST
const MIRROR_OWN_POST = 2;
const MIRROR_NATIVE_RESHARE = 3;
/**
/**
* @param array $fields Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
@ -725,8 +725,11 @@ class Contact
*/
public static function createSelfFromUserId(int $uid): bool
{
$user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'pubkey', 'prvkey'],
['uid' => $uid, 'account_expired' => false]);
$user = DBA::selectFirst(
'user',
['uid', 'username', 'nickname', 'pubkey', 'prvkey'],
['uid' => $uid, 'account_expired' => false]
);
if (!DBA::isResult($user)) {
return false;
}
@ -786,9 +789,11 @@ class Contact
*/
public static function updateSelfFromUserID(int $uid, bool $update_avatar = false): bool
{
$fields = ['id', 'uri-id', 'name', 'nick', 'location', 'about', 'keywords', 'avatar', 'prvkey', 'pubkey', 'manually-approve',
$fields = [
'id', 'uri-id', 'name', 'nick', 'location', 'about', 'keywords', 'avatar', 'prvkey', 'pubkey', 'manually-approve',
'xmpp', 'matrix', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
'photo', 'thumb', 'micro', 'header', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco', 'network'];
'photo', 'thumb', 'micro', 'header', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco', 'network'
];
$self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
if (!DBA::isResult($self)) {
return false;
@ -800,8 +805,10 @@ class Contact
return false;
}
$fields = ['name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
'country-name', 'pub_keywords', 'xmpp', 'matrix', 'net-publish'];
$fields = [
'name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
'country-name', 'pub_keywords', 'xmpp', 'matrix', 'net-publish'
];
$profile = DBA::selectFirst('profile', $fields, ['uid' => $uid]);
if (!DBA::isResult($profile)) {
return false;
@ -830,7 +837,7 @@ class Contact
'addr' => $user['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3),
'request' => DI::baseUrl() . '/dfrn_request/' . $user['nickname'],
'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'],
'poll' => DI::baseUrl() . '/dfrn_poll/'. $user['nickname'],
'poll' => DI::baseUrl() . '/dfrn_poll/' . $user['nickname'],
'confirm' => DI::baseUrl() . '/dfrn_confirm/' . $user['nickname'],
];
@ -850,7 +857,7 @@ class Contact
// We are adding a timestamp value so that other systems won't use cached content
$timestamp = strtotime($fields['avatar-date']);
$prefix = DI::baseUrl() . '/photo/' .$avatar['resource-id'] . '-';
$prefix = DI::baseUrl() . '/photo/' . $avatar['resource-id'] . '-';
$suffix = '.' . $file_suffix . '?ts=' . $timestamp;
$fields['photo'] = $prefix . '4' . $suffix;
@ -1188,22 +1195,22 @@ class Contact
*/
if (empty($contact['uid'])) {
$menu = [
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
'profile' => [DI::l10n()->t('View Profile'), $profile_link, true],
'network' => [DI::l10n()->t('Network Posts'), $posts_link, false],
'edit' => [DI::l10n()->t('View Contact'), $contact_url, false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link, true],
'unfollow' => [DI::l10n()->t('Unfollow'), $unfollow_link, true],
];
} else {
$menu = [
'status' => [DI::l10n()->t('View Status') , $status_link , true ],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true ],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
'status' => [DI::l10n()->t('View Status'), $status_link, true],
'profile' => [DI::l10n()->t('View Profile'), $profile_link, true],
'photos' => [DI::l10n()->t('View Photos'), $photos_link, true],
'network' => [DI::l10n()->t('Network Posts'), $posts_link, false],
'edit' => [DI::l10n()->t('View Contact'), $contact_url, false],
'pm' => [DI::l10n()->t('Send PM'), $pm_url, false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link, true],
'unfollow' => [DI::l10n()->t('Unfollow'), $unfollow_link, true],
];
if (!empty($contact['pending'])) {
@ -1310,9 +1317,11 @@ class Contact
if (($uid == 0) && (empty($data['network']) || ($data['network'] == Protocol::PHANTOM))) {
// Fetch data for the public contact via the first found personal contact
/// @todo Check if this case can happen at all (possibly with mail accounts?)
$fields = ['name', 'nick', 'url', 'addr', 'alias', 'avatar', 'header', 'contact-type',
$fields = [
'name', 'nick', 'url', 'addr', 'alias', 'avatar', 'header', 'contact-type',
'keywords', 'location', 'about', 'unsearchable', 'batch', 'notify', 'poll',
'request', 'confirm', 'poco', 'subscribe', 'network', 'baseurl', 'gsid'];
'request', 'confirm', 'poco', 'subscribe', 'network', 'baseurl', 'gsid'
];
$personal_contact = DBA::selectFirst('contact', $fields, ["`addr` = ? AND `uid` != 0", $url]);
if (!DBA::isResult($personal_contact)) {
@ -1458,7 +1467,7 @@ class Contact
if (!empty($contact['batch'])) {
$condition = ['archive' => true, 'uid' => 0, 'network' => Protocol::FEDERATED, 'batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
return DBA::exists('contact', $condition);
}
}
return false;
}
@ -1551,11 +1560,15 @@ class Contact
$contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
if ($thread_mode) {
$condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `protocol` != ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql,
$cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Conversation::PARCEL_DIASPORA, DI::userSession()->getLocalUserId()];
$condition = [
"((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `protocol` != ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql,
$cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Conversation::PARCEL_DIASPORA, DI::userSession()->getLocalUserId()
];
} else {
$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
$cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, DI::userSession()->getLocalUserId()];
$condition = [
"`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
$cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, DI::userSession()->getLocalUserId()
];
}
if (!empty($parent)) {
@ -1568,16 +1581,26 @@ class Contact
}
if ($only_media) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
$condition = DBA::mergeConditions($condition, [
"`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO
]);
}
if (DI::mode()->isMobile()) {
$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
$itemsPerPage = DI::pConfig()->get(
DI::userSession()->getLocalUserId(),
'system',
'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile')
);
} else {
$itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
DI::config()->get('system', 'itemspage_network'));
$itemsPerPage = DI::pConfig()->get(
DI::userSession()->getLocalUserId(),
'system',
'itemspage_network',
DI::config()->get('system', 'itemspage_network')
);
}
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
@ -1611,8 +1634,10 @@ class Contact
if ($pager->getStart() == 0) {
$cdata = self::getPublicAndUserContactID($cid, DI::userSession()->getLocalUserId());
if (!empty($cdata['public'])) {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ? AND `type` = ?)",
$cdata['public'], Post\Collection::FEATURED];
$condition = [
"`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ? AND `type` = ?)",
$cdata['public'], Post\Collection::FEATURED
];
$pinned = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
$items = array_merge($pinned, $items);
}
@ -1719,7 +1744,7 @@ class Contact
} elseif (DI::config()->get('system', 'avatar_cache') && (empty($contact['photo']) || empty($contact['thumb']) || empty($contact['micro']))) {
Logger::info('Adding avatar cache file', ['id' => $cid, 'contact' => $contact]);
self::updateAvatar($cid, $contact['avatar'], true);
return;
return;
}
}
@ -2121,8 +2146,10 @@ class Contact
*/
public static function getAvatarUrlForUrl(string $url, int $uid, string $size = ''): string
{
$condition = ["`nurl` = ? AND ((`uid` = ? AND `network` IN (?, ?)) OR `uid` = ?)",
Strings::normaliseLink($url), $uid, Protocol::FEED, Protocol::MAIL, 0];
$condition = [
"`nurl` = ? AND ((`uid` = ? AND `network` IN (?, ?)) OR `uid` = ?)",
Strings::normaliseLink($url), $uid, Protocol::FEED, Protocol::MAIL, 0
];
$contact = self::selectFirst(['id', 'updated'], $condition, ['order' => ['uid' => true]]);
return self::getAvatarUrlForId($contact['id'] ?? 0, $size, $contact['updated'] ?? '');
}
@ -2193,8 +2220,11 @@ class Contact
*/
public static function updateAvatar(int $cid, string $avatar, bool $force = false, bool $create_cache = false)
{
$contact = DBA::selectFirst('contact', ['uid', 'avatar', 'photo', 'thumb', 'micro', 'blurhash', 'xmpp', 'addr', 'nurl', 'url', 'network', 'uri-id'],
['id' => $cid, 'self' => false]);
$contact = DBA::selectFirst(
'contact',
['uid', 'avatar', 'photo', 'thumb', 'micro', 'blurhash', 'xmpp', 'addr', 'nurl', 'url', 'network', 'uri-id'],
['id' => $cid, 'self' => false]
);
if (!DBA::isResult($contact)) {
return;
}
@ -2268,10 +2298,12 @@ class Contact
}
if ($default_avatar && Proxy::isLocalImage($avatar)) {
$fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(),
$fields = [
'avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(),
'photo' => $avatar,
'thumb' => self::getDefaultAvatar($contact, Proxy::SIZE_THUMB),
'micro' => self::getDefaultAvatar($contact, Proxy::SIZE_MICRO)];
'micro' => self::getDefaultAvatar($contact, Proxy::SIZE_MICRO)
];
Logger::debug('Use default avatar', ['id' => $cid, 'uid' => $uid]);
}
@ -2330,8 +2362,11 @@ class Contact
$uids = [];
if (($uid == 0) && !in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
// Collect all user contacts of the given public contact
$personal_contacts = DBA::select('contact', ['id', 'uid'],
["`nurl` = ? AND `id` != ? AND NOT `self`", $contact['nurl'], $cid]);
$personal_contacts = DBA::select(
'contact',
['id', 'uid'],
["`nurl` = ? AND `id` != ? AND NOT `self`", $contact['nurl'], $cid]
);
while ($personal_contact = DBA::fetch($personal_contacts)) {
$cids[] = $personal_contact['id'];
$uids[] = $personal_contact['uid'];
@ -2650,10 +2685,12 @@ class Contact
// These fields aren't updated by this routine:
// 'sensitive'
$fields = ['uid', 'uri-id', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
$fields = [
'uid', 'uri-id', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item', 'xmpp', 'matrix',
'created', 'last-update'];
'created', 'last-update'
];
$contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
if (!DBA::isResult($contact)) {
return false;
@ -2677,7 +2714,7 @@ class Contact
return true;
}
$has_local_data = self::hasLocalData($id, $contact);
$has_local_data = self::hasLocalData($id, $contact);
$uid = $contact['uid'];
unset($contact['uid']);
@ -2724,7 +2761,8 @@ class Contact
// We must not try to update relay contacts via probe. They are no real contacts.
// We check after the probing to be able to correct falsely detected contact types.
if (($contact['contact-type'] == self::TYPE_RELAY) &&
(!Strings::compareLink($ret['url'], $contact['url']) || in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]))) {
(!Strings::compareLink($ret['url'], $contact['url']) || in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]))
) {
self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
Logger::info('Not updating relais', ['id' => $id, 'url' => $contact['url']]);
return true;
@ -3078,11 +3116,11 @@ class Contact
'protocol' => $protocol,
'pubkey' => $ret['pubkey'],
'rel' => $new_relation,
'priority'=> $ret['priority'],
'writable'=> $writeable,
'priority' => $ret['priority'],
'writable' => $writeable,
'hidden' => $hidden,
'blocked' => 0,
'readonly'=> 0,
'readonly' => 0,
'pending' => $pending,
'subhub' => $subhub
]);
@ -3172,8 +3210,10 @@ class Contact
}
// Contact is blocked at user-level
if (!empty($contact['id']) && !empty($importer['id']) &&
Contact\User::isBlocked($contact['id'], $importer['id'])) {
if (
!empty($contact['id']) && !empty($importer['id']) &&
Contact\User::isBlocked($contact['id'], $importer['id'])
) {
return false;
}
@ -3181,9 +3221,12 @@ class Contact
self::unmarkForArchival($contact);
if (($contact['rel'] == self::SHARING)
|| ($sharing && $contact['rel'] == self::FOLLOWER)) {
self::update(['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
['id' => $contact['id'], 'uid' => $importer['uid']]);
|| ($sharing && $contact['rel'] == self::FOLLOWER)
) {
self::update(
['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
['id' => $contact['id'], 'uid' => $importer['uid']]
);
}
// Ensure to always have the correct network type, independent from the connection request method
@ -3422,7 +3465,7 @@ class Contact
*/
public static function magicLinkById(int $cid, string $url = ''): string
{
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], ['id' => $cid]);
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'alias', 'uid'], ['id' => $cid]);
return self::magicLinkByContact($contact, $url);
}
@ -3439,7 +3482,7 @@ class Contact
*/
public static function magicLinkByContact(array $contact, string $url = ''): string
{
$destination = $url ?: $contact['url'];
$destination = $url ?: (!Network::isValidHttpUrl($contact['url']) && !empty($contact['alias']) && Network::isValidHttpUrl($contact['alias']) ? $contact['alias'] : $contact['url']);
if (!DI::userSession()->isAuthenticated()) {
return $destination;
@ -3568,8 +3611,10 @@ class Contact
$params['limit'] = $limit;
}
$condition = DBA::mergeConditions($condition,
["(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
$condition = DBA::mergeConditions(
$condition,
["(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]
);
return DBA::selectToArray('account-user-view', [], $condition, $params);
}
@ -3619,7 +3664,7 @@ class Contact
*/
public static function getRandomContact(): array
{
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], [
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'alias', 'uid'], [
"`uid` = ? AND `network` = ? AND NOT `failed` AND `last-item` > ?",
0, Protocol::DFRN, DateTimeFormat::utc('now - 1 month'),
], ['order' => ['RAND()']]);