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;
}
/**
- * Check if the given contact url is on the same machine
+ * Check if the given contact url is on the same server
*
* @param string $url The contact link
*
- * @return boolean Is it the same machine?
+ * @return boolean Is it the same server?
*/
public static function isLocal($url)
{
} 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'];
$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']))) {
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'];
'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;
}