use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
+use Friendica\Core\Session;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Network\Probe;
use Friendica\Object\Image;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora;
* @param string $url The contact link
*
* @return string basepath
+ * @return boolean $dont_update Don't update the contact
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function getBasepath($url)
+ public static function getBasepath($url, $dont_update = false)
{
$contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
if (!empty($contact['baseurl'])) {
return $contact['baseurl'];
+ } elseif ($dont_update) {
+ return '';
}
self::updateFromProbeByURL($url, true);
return '';
}
+ /**
+ * Check if the given contact url is on the same server
+ *
+ * @param string $url The contact link
+ *
+ * @return boolean Is it the same server?
+ */
+ public static function isLocal($url)
+ {
+ return Strings::compareLink(self::getBasepath($url, true), System::baseUrl());
+ }
+
/**
* Returns the public contact id of the given user id
*
public static function updateSelfFromUserID($uid, $update_avatar = false)
{
$fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'gender', 'avatar',
- 'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl',
+ 'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
'photo', 'thumb', 'micro', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco'];
$self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
if (!DBA::isResult($self)) {
return;
}
- $fields = ['nickname', 'page-flags', 'account-type'];
+ $fields = ['nickname', 'page-flags', 'account-type', 'hidewall'];
$user = DBA::selectFirst('user', $fields, ['uid' => $uid]);
if (!DBA::isResult($user)) {
return;
}
$fields = ['name', 'photo', 'thumb', 'about', 'address', 'locality', 'region',
- 'country-name', 'gender', 'pub_keywords', 'xmpp'];
+ 'country-name', 'gender', 'pub_keywords', 'xmpp', 'net-publish'];
$profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]);
if (!DBA::isResult($profile)) {
return;
$fields['avatar'] = System::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix;
$fields['forum'] = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
$fields['prv'] = $user['page-flags'] == User::PAGE_FLAGS_PRVGROUP;
+ $fields['unsearchable'] = $user['hidewall'] || !$profile['net-publish'];
// it seems as if ported accounts can have wrong values, so we make sure that now everything is fine.
$fields['url'] = System::baseUrl() . '/profile/' . $user['nickname'];
} elseif (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create an unfollow slap
$item = [];
- $item['verb'] = NAMESPACE_OSTATUS . "/unfollow";
+ $item['verb'] = Activity\Namespaces::OSTATUS . "/unfollow";
$item['follow'] = $contact["url"];
$item['body'] = '';
$item['title'] = '';
$profile["micro"] = $profile["thumb"];
}
- if ((empty($profile["addr"]) || empty($profile["name"])) && (defaults($profile, "gid", 0) != 0)
+ if ((empty($profile["addr"]) || empty($profile["name"])) && !empty($profile["gid"])
&& in_array($profile["network"], Protocol::FEDERATED)
) {
Worker::add(PRIORITY_LOW, "UpdateGContact", $url);
}
// Show contact details of Diaspora contacts only if connected
- if ((defaults($profile, "cid", 0) == 0) && (defaults($profile, "network", "") == Protocol::DIASPORA)) {
+ if (empty($profile["cid"]) && ($profile["network"] ?? "") == Protocol::DIASPORA) {
$profile["location"] = "";
$profile["about"] = "";
$profile["gender"] = "";
$sparkle = false;
if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
$sparkle = true;
- $profile_link = System::baseUrl() . '/redir/' . $contact['id'] . '?url=' . $contact['url'];
+ $profile_link = System::baseUrl() . '/redir/' . $contact['id'];
} else {
$profile_link = $contact['url'];
}
}
if (($contact['network'] == Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
- $poke_link = System::baseUrl() . '/poke/?f=&c=' . $contact['id'];
+ $poke_link = System::baseUrl() . '/poke/?c=' . $contact['id'];
}
$contact_url = System::baseUrl() . '/contact/' . $contact['id'];
if (empty($data)) {
$data = Probe::uri($url, "", $uid);
-
// Ensure that there is a gserver entry
if (!empty($data['baseurl']) && ($data['network'] != Protocol::PHANTOM)) {
- PortableContact::checkServer($data['baseurl']);
+ GServer::check($data['baseurl']);
}
}
'created' => DateTimeFormat::utcNow(),
'url' => $data['url'],
'nurl' => Strings::normaliseLink($data['url']),
- 'addr' => defaults($data, 'addr', ''),
- 'alias' => defaults($data, 'alias', ''),
- 'notify' => defaults($data, 'notify', ''),
- 'poll' => defaults($data, 'poll', ''),
- 'name' => defaults($data, 'name', ''),
- 'nick' => defaults($data, 'nick', ''),
- 'photo' => defaults($data, 'photo', ''),
- 'keywords' => defaults($data, 'keywords', ''),
- 'location' => defaults($data, 'location', ''),
- 'about' => defaults($data, 'about', ''),
+ 'addr' => $data['addr'] ?? '',
+ 'alias' => $data['alias'] ?? '',
+ 'notify' => $data['notify'] ?? '',
+ 'poll' => $data['poll'] ?? '',
+ 'name' => $data['name'] ?? '',
+ 'nick' => $data['nick'] ?? '',
+ 'photo' => $data['photo'] ?? '',
+ 'keywords' => $data['keywords'] ?? '',
+ 'location' => $data['location'] ?? '',
+ 'about' => $data['about'] ?? '',
'network' => $data['network'],
- 'pubkey' => defaults($data, 'pubkey', ''),
+ 'pubkey' => $data['pubkey'] ?? '',
'rel' => self::SHARING,
- 'priority' => defaults($data, 'priority', 0),
- 'batch' => defaults($data, 'batch', ''),
- 'request' => defaults($data, 'request', ''),
- 'confirm' => defaults($data, 'confirm', ''),
- 'poco' => defaults($data, 'poco', ''),
- 'baseurl' => defaults($data, 'baseurl', ''),
+ 'priority' => $data['priority'] ?? 0,
+ 'batch' => $data['batch'] ?? '',
+ 'request' => $data['request'] ?? '',
+ 'confirm' => $data['confirm'] ?? '',
+ 'poco' => $data['poco'] ?? '',
+ 'baseurl' => $data['baseurl'] ?? '',
'name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(),
'avatar-date' => DateTimeFormat::utcNow(),
$fields = ['addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'baseurl'];
foreach ($fields as $field) {
- $updated[$field] = defaults($data, $field, $contact[$field]);
+ $updated[$field] = ($data[$field] ?? '') ?: $contact[$field];
}
if (($updated['addr'] != $contact['addr']) || (!empty($data['alias']) && ($data['alias'] != $contact['alias']))) {
return true;
}
- // If Probe::uri fails the network code will be different (mostly "feed" or "unkn")
- if (!in_array($ret['network'], Protocol::NATIVE_SUPPORT) ||
- (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network']))) {
+ // If Probe::uri fails the network code will be different ("feed" or "unkn")
+ if (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network'])) {
if ($force && ($uid == 0)) {
self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'failure_update' => $updated]);
}
}
}
- if ($ret['network'] != Protocol::FEED) {
+ if (!empty($ret['photo']) && ($ret['network'] != Protocol::FEED)) {
self::updateAvatar($ret['photo'], $uid, $id, $update || $force);
}
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create a follow slap
$item = [];
- $item['verb'] = ACTIVITY_FOLLOW;
+ $item['verb'] = Activity::FOLLOW;
$item['follow'] = $contact["url"];
$item['body'] = '';
$item['title'] = '';
return false;
}
- $url = defaults($datarray, 'author-link', $pub_contact['url']);
+ $url = ($datarray['author-link'] ?? '') ?: $pub_contact['url'];
$name = $pub_contact['name'];
- $photo = defaults($pub_contact, 'avatar', $pub_contact["photo"]);
+ $photo = ($pub_contact['avatar'] ?? '') ?: $pub_contact["photo"];
$nick = $pub_contact['nick'];
$network = $pub_contact['network'];
['id' => $contact['id'], 'uid' => $importer['uid']]);
}
+ // Ensure to always have the correct network type, independent from the connection request method
+ self::updateFromProbe($contact['id'], '', true);
+
return true;
} else {
// send email notification to owner?
'writable' => 1,
]);
- $contact_record = [
- 'id' => DBA::lastInsertId(),
- 'network' => $network,
- 'name' => $name,
- 'url' => $url,
- 'photo' => $photo
- ];
+ $contact_id = DBA::lastInsertId();
+
+ // Ensure to always have the correct network type, independent from the connection request method
+ self::updateFromProbe($contact_id, '', true);
+
+ Contact::updateAvatar($photo, $importer["uid"], $contact_id, true);
- Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
+ $contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);
/// @TODO Encapsulate this into a function/method
$fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
'source_name' => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : L10n::t('[Name Withheld]')),
'source_link' => $contact_record['url'],
'source_photo' => $contact_record['photo'],
- 'verb' => ($sharing ? ACTIVITY_FRIEND : ACTIVITY_FOLLOW),
+ 'verb' => ($sharing ? Activity::FRIEND : Activity::FOLLOW),
'otype' => 'intro'
]);
}
*/
public static function magicLink($contact_url, $url = '')
{
- if (!local_user() && !remote_user()) {
+ if (!Session::isAuthenticated()) {
return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
}
{
$destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
- if ((!local_user() && !remote_user()) || ($contact['network'] != Protocol::DFRN)) {
+ if (!Session::isAuthenticated() || ($contact['network'] != Protocol::DFRN)) {
return $destination;
}
$redirect = 'redir/' . $contact['id'];
- if ($url != '') {
+ if (($url != '') && !Strings::compareLink($contact['url'], $url)) {
$redirect .= '?url=' . $url;
}