diff --git a/boot.php b/boot.php index b07ad8483..512238b52 100644 --- a/boot.php +++ b/boot.php @@ -253,10 +253,10 @@ function public_contact() if (!$public_contact_id && !empty($_SESSION['authenticated'])) { if (!empty($_SESSION['my_address'])) { // Local user - $public_contact_id = intval(Contact::getIdForURL($_SESSION['my_address'], 0, true)); + $public_contact_id = intval(Contact::getIdForURL($_SESSION['my_address'], 0, false)); } elseif (!empty($_SESSION['visitor_home'])) { // Remote user - $public_contact_id = intval(Contact::getIdForURL($_SESSION['visitor_home'], 0, true)); + $public_contact_id = intval(Contact::getIdForURL($_SESSION['visitor_home'], 0, false)); } } elseif (empty($_SESSION['authenticated'])) { $public_contact_id = false; diff --git a/include/api.php b/include/api.php index 53d00b27d..86cda0b1b 100644 --- a/include/api.php +++ b/include/api.php @@ -654,8 +654,8 @@ function api_get_user(App $a, $contact_id = null) 'notifications' => false, 'statusnet_profile_url' => $contact["url"], 'uid' => 0, - 'cid' => Contact::getIdForURL($contact["url"], api_user(), true), - 'pid' => Contact::getIdForURL($contact["url"], 0, true), + 'cid' => Contact::getIdForURL($contact["url"], api_user(), false), + 'pid' => Contact::getIdForURL($contact["url"], 0, false), 'self' => 0, 'network' => $contact["network"], ]; @@ -679,7 +679,7 @@ function api_get_user(App $a, $contact_id = null) $countfollowers = 0; $starred = 0; - $pcontact_id = Contact::getIdForURL($uinfo[0]['url'], 0, true); + $pcontact_id = Contact::getIdForURL($uinfo[0]['url'], 0, false); if (!empty($profile['about'])) { $description = $profile['about']; @@ -731,7 +731,7 @@ function api_get_user(App $a, $contact_id = null) 'statusnet_profile_url' => $uinfo[0]['url'], 'uid' => intval($uinfo[0]['uid']), 'cid' => intval($uinfo[0]['cid']), - 'pid' => Contact::getIdForURL($uinfo[0]["url"], 0, true), + 'pid' => Contact::getIdForURL($uinfo[0]["url"], 0, false), 'self' => $uinfo[0]['self'], 'network' => $uinfo[0]['network'], ]; @@ -5052,7 +5052,7 @@ function api_share_as_retweet(&$item) $reshared_item["share-pre-body"] = $reshared['comment']; $reshared_item["body"] = $reshared['shared']; - $reshared_item["author-id"] = Contact::getIdForURL($reshared['profile'], 0, true); + $reshared_item["author-id"] = Contact::getIdForURL($reshared['profile'], 0, false); $reshared_item["author-name"] = $reshared['author']; $reshared_item["author-link"] = $reshared['profile']; $reshared_item["author-avatar"] = $reshared['avatar']; diff --git a/include/conversation.php b/include/conversation.php index 6e024fe20..8507c5ba9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -325,7 +325,7 @@ function conv_get_blocklist() foreach (explode(',', $str_blocked) as $entry) { // The 4th parameter guarantees that there always will be a public contact entry - $cid = Contact::getIdForURL(trim($entry), 0, true, ['url' => trim($entry)]); + $cid = Contact::getIdForURL(trim($entry), 0, false, ['url' => trim($entry)]); if (!empty($cid)) { $blocklist[] = $cid; } @@ -837,7 +837,7 @@ function item_photo_menu($item) { $sparkle = (strpos($profile_link, 'redir/') === 0); $cid = 0; - $pcid = Contact::getIdForURL($item['author-link'], 0, true); + $pcid = Contact::getIdForURL($item['author-link'], 0, false); $network = ''; $rel = 0; $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])]; diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index f5716e8ff..f8e4c9023 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -294,7 +294,7 @@ function dfrn_request_post(App $a) $hcard = ''; // Detect the network - $data = Probe::uri($url); + $data = Contact::getByURL($url); $network = $data["network"]; // Canonicalize email-style profile locator diff --git a/mod/display.php b/mod/display.php index 61e1529e4..1a429948a 100644 --- a/mod/display.php +++ b/mod/display.php @@ -164,7 +164,7 @@ function display_fetchauthor($a, $item) $profiledata["about"] = ""; } - $profiledata = array_merge($profiledata, Contact::getByURLForUser($profiledata["url"], local_user())); + $profiledata = Contact::getByURLForUser($profiledata["url"], local_user()) ?: $profiledata; if (!empty($profiledata["photo"])) { $profiledata["photo"] = DI::baseUrl()->remove($profiledata["photo"]); diff --git a/mod/match.php b/mod/match.php index b54be0134..747e0b2f0 100644 --- a/mod/match.php +++ b/mod/match.php @@ -89,7 +89,7 @@ function match_content(App $a) $profile = $msearch->results[$i]; // Already known contact - if (!$profile || Contact::getIdForURL($profile->url, local_user(), true)) { + if (!$profile || Contact::getIdForURL($profile->url, local_user(), false)) { continue; } diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 64774eead..751afcc73 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Core\Protocol; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Network\Probe; use Friendica\Util\Network; function ostatus_subscribe_content(App $a) @@ -47,7 +46,7 @@ function ostatus_subscribe_content(App $a) return $o . DI::l10n()->t('No contact provided.'); } - $contact = Probe::uri($_REQUEST['url']); + $contact = Contact::getByURL($_REQUEST['url']); if (!$contact) { DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact'); return $o . DI::l10n()->t('Couldn\'t fetch information for contact.'); @@ -88,7 +87,7 @@ function ostatus_subscribe_content(App $a) $o .= '
' . $counter . '/' . $total . ': ' . $url; - $probed = Probe::uri($url); + $probed = Contact::getByURL($url); if ($probed['network'] == Protocol::OSTATUS) { $result = Contact::createFromProbe($a->user, $probed['url'], true, Protocol::OSTATUS); if ($result['success']) { diff --git a/mod/suggest.php b/mod/suggest.php index 068b9e366..9cd2fb1cd 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -104,7 +104,7 @@ function suggest_content(App $a) 'hide' => [DI::l10n()->t('Ignore/Hide'), $ignlnk] ]; - $contact_details = array_merge($rr, Contact::getByURLForUser($rr["url"], local_user())); + $contact_details = Contact::getByURLForUser($rr["url"], local_user()) ?: $rr; $entry = [ 'url' => Contact::magicLink($rr['url']), diff --git a/src/Content/Widget.php b/src/Content/Widget.php index ffc5debb3..fad863fbe 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -471,7 +471,7 @@ class Widget } if (Feature::isEnabled($uid, 'tagadelic')) { - $owner_id = Contact::getIdForURL($a->profile['url'], 0, true); + $owner_id = Contact::getIdForURL($a->profile['url'], 0, false); if (!$owner_id) { return ''; diff --git a/src/Core/Search.php b/src/Core/Search.php index d6ed9b6bf..60137e66f 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -202,7 +202,7 @@ class Search return $resultList; } - $data = DBA::select('gcontact', ['nurl'], [ + $data = DBA::select('gcontact', ['nurl', 'name', 'addr', 'url', 'photo', 'network', 'keywords'], [ 'NOT `hide` AND `network` IN (?, ?, ?, ?) AND ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) @@ -232,7 +232,7 @@ class Search continue; } - $contact = Contact::getByURLForUser($row["nurl"], local_user()); + $contact = Contact::getByURLForUser($row["nurl"], local_user()) ?: $row; if ($contact["name"] == "") { $contact["name"] = end(explode("/", $urlParts["path"])); @@ -245,8 +245,8 @@ class Search $contact["url"], $contact["photo"], $contact["network"], - $contact["cid"], - $contact["zid"], + $contact["cid"] ?? 0, + $contact["zid"] ?? 0, $contact["keywords"] ); diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 0ceae07f7..6d8b197db 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -245,14 +245,14 @@ class PostUpdate $default = ['url' => $item['author-link'], 'name' => $item['author-name'], 'photo' => $item['author-avatar'], 'network' => $item['network']]; - $item['author-id'] = Contact::getIdForURL($item["author-link"], 0, false, $default); + $item['author-id'] = Contact::getIdForURL($item["author-link"], 0, null, $default); } if (empty($item['owner-id'])) { $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'], 'photo' => $item['owner-avatar'], 'network' => $item['network']]; - $item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, false, $default); + $item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, null, $default); } if (empty($item['psid'])) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 15e4e5703..646da57ca 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -194,21 +194,32 @@ class Contact * Fetches a contact by a given url * * @param string $url profile url - * @param integer $uid User ID of the contact - * @param array $fields Field list * @param boolean $update true = always update, false = never update, null = update when not found or outdated + * @param array $fields Field list + * @param integer $uid User ID of the contact * @return array contact array */ public static function getByURL(string $url, $update = null, array $fields = [], int $uid = 0) { if ($update || is_null($update)) { - $cid = self::getIdForURL($url, $uid, !($update ?? false)); + $cid = self::getIdForURL($url, $uid, $update); if (empty($cid)) { return []; } return self::getById($cid, $fields); } + // Add internal fields + $removal = []; + if (!empty($fields)) { + foreach (['id', 'updated', 'network'] as $internal) { + if (!in_array($internal, $fields)) { + $fields[] = $internal; + $removal[] = $internal; + } + } + } + // We first try the nurl (http://server.tld/nick), most common case $options = ['order' => ['id']]; $contact = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false], $options); @@ -225,6 +236,18 @@ class Contact $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid]; $contact = DBA::selectFirst('contact', $fields, $condition, $options); } + + // Update the contact in the background if needed + if ((($contact['updated'] < DateTimeFormat::utc('now -7 days')) || empty($contact['avatar'])) && + in_array($contact['network'], Protocol::FEDERATED)) { + Worker::add(PRIORITY_LOW, "UpdateContact", $contact['id'], ($uid == 0 ? 'force' : '')); + } + + // Remove the internal fields + foreach ($removal as $internal) { + unset($contact[$internal]); + } + return $contact; } @@ -234,8 +257,8 @@ class Contact * * @param string $url profile url * @param integer $uid User ID of the contact - * @param array $fields Field list * @param boolean $update true = always update, false = never update, null = update when not found or outdated + * @param array $fields Field list * @return array contact array */ public static function getByURLForUser(string $url, int $uid = 0, $update = false, array $fields = []) @@ -296,7 +319,7 @@ class Contact */ public static function isFollowerByURL($url, $uid) { - $cid = self::getIdForURL($url, $uid, true); + $cid = self::getIdForURL($url, $uid, false); if (empty($cid)) { return false; @@ -342,7 +365,7 @@ class Contact */ public static function isSharingByURL($url, $uid) { - $cid = self::getIdForURL($url, $uid, true); + $cid = self::getIdForURL($url, $uid, false); if (empty($cid)) { return false; @@ -437,7 +460,7 @@ class Contact if (!DBA::isResult($self)) { return false; } - return self::getIdForURL($self['url'], 0, true); + return self::getIdForURL($self['url'], 0, false); } /** @@ -467,14 +490,14 @@ class Contact } if ($contact['uid'] != 0) { - $pcid = Contact::getIdForURL($contact['url'], 0, true, ['url' => $contact['url']]); + $pcid = Contact::getIdForURL($contact['url'], 0, false, ['url' => $contact['url']]); if (empty($pcid)) { return []; } $ucid = $contact['id']; } else { $pcid = $contact['id']; - $ucid = Contact::getIdForURL($contact['url'], $uid, true); + $ucid = Contact::getIdForURL($contact['url'], $uid, false); } return ['public' => $pcid, 'user' => $ucid]; @@ -1300,7 +1323,7 @@ class Contact * * @param string $url Contact URL * @param integer $uid The user id for the contact (0 = public contact) - * @param boolean $no_update Don't update the contact + * @param boolean $update true = always update, false = never update, null = update when not found or outdated * @param array $default Default value for creating the contact when every else fails * @param boolean $in_loop Internally used variable to prevent an endless loop * @@ -1308,7 +1331,7 @@ class Contact * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function getIdForURL($url, $uid = 0, $no_update = false, $default = [], $in_loop = false) + public static function getIdForURL($url, $uid = 0, $update = null, $default = [], $in_loop = false) { Logger::info('Get contact data', ['url' => $url, 'user' => $uid]); @@ -1322,17 +1345,8 @@ class Contact if (!empty($contact)) { $contact_id = $contact["id"]; - $update_contact = false; - // Update the contact every 7 days (Don't update mail or feed contacts) - if (in_array($contact['network'], Protocol::FEDERATED)) { - $update_contact = ($contact['updated'] < DateTimeFormat::utc('now -7 days')); - - // We force the update if the avatar is empty - if (empty($contact['avatar'])) { - $update_contact = true; - } - } elseif (empty($default) && in_array($contact['network'], [Protocol::MAIL, Protocol::PHANTOM]) && ($uid == 0)) { + if (empty($default) && in_array($contact['network'], [Protocol::MAIL, Protocol::PHANTOM]) && ($uid == 0)) { // Update public mail accounts via their user's accounts $fields = ['network', 'addr', 'name', 'nick', 'avatar', 'photo', 'thumb', 'micro']; $mailcontact = DBA::selectFirst('contact', $fields, ["`addr` = ? AND `network` = ? AND `uid` != 0", $url, Protocol::MAIL]); @@ -1345,12 +1359,7 @@ class Contact } } - // Update the contact in the background if needed but it is called by the frontend - if ($update_contact && $no_update && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { - Worker::add(PRIORITY_LOW, "UpdateContact", $contact_id, ($uid == 0 ? 'force' : '')); - } - - if (!$update_contact || $no_update) { + if (empty($update)) { return $contact_id; } } elseif ($uid != 0) { @@ -1358,11 +1367,11 @@ class Contact return 0; } - if ($no_update && empty($default)) { + if (!$update && empty($default)) { // When we don't want to update, we look if we know this contact in any way $data = self::getProbeDataFromDatabase($url, $contact_id); $background_update = true; - } elseif ($no_update && !empty($default['network'])) { + } elseif (!$update && !empty($default['network'])) { // If there are default values, take these $data = $default; $background_update = false; @@ -1371,7 +1380,7 @@ class Contact $background_update = false; } - if (empty($data)) { + if ((empty($data) && is_null($update)) || $update) { $data = Probe::uri($url, "", $uid); } @@ -1394,7 +1403,7 @@ class Contact } if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $data['url']) && !$in_loop) { - $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true); + $contact_id = self::getIdForURL($data["alias"], $uid, false, $default, true); } if (!$contact_id) { diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 704d091a6..fdbc77509 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -37,7 +37,6 @@ use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Protocol\PortableContact; use Friendica\Protocol\Diaspora; -use Friendica\Network\Probe; /** * This class handles GServer related functions @@ -980,8 +979,8 @@ class GServer } foreach ($contacts as $contact) { - $probed = Probe::uri($contact); - if (in_array($probed['network'], Protocol::FEDERATED)) { + $probed = Contact::getByURL($contact); + if (!empty($probed) && in_array($probed['network'], Protocol::FEDERATED)) { $serverdata['network'] = $probed['network']; break; } diff --git a/src/Model/Item.php b/src/Model/Item.php index 4fff36556..332c734fa 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1680,11 +1680,11 @@ class Item $default = ['url' => $item['author-link'], 'name' => $item['author-name'], 'photo' => $item['author-avatar'], 'network' => $item['network']]; - $item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, false, $default); + $item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default); $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'], 'photo' => $item['owner-avatar'], 'network' => $item['network']]; - $item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, false, $default); + $item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default); // The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes $item["contact-id"] = self::contactId($item); @@ -2976,7 +2976,7 @@ class Item if (local_user() == $uid) { $item_contact_id = $owner_self_contact['id']; } else { - $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid, true); + $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid, false); $item_contact = DBA::selectFirst('contact', [], ['id' => $item_contact_id]); if (!DBA::isResult($item_contact)) { Logger::log('like: unknown item contact ' . $item_contact_id); diff --git a/src/Model/Mail.php b/src/Model/Mail.php index 405635215..67d5d1ddc 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -27,7 +27,6 @@ use Friendica\Core\Worker; use Friendica\DI; use Friendica\Database\DBA; use Friendica\Model\Notify\Type; -use Friendica\Network\Probe; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; use Friendica\Worker\Delivery; @@ -267,7 +266,7 @@ class Mail $guid = System::createUUID(); $uri = Item::newURI(local_user(), $guid); - $me = Probe::uri($replyto); + $me = Contact::getByURL($replyto); if (!$me['name']) { return -2; } diff --git a/src/Model/Tag.php b/src/Model/Tag.php index d8c252ca2..3424a2377 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -111,7 +111,7 @@ class Tag } } } else { - $cid = Contact::getIdForURL($url, 0, true); + $cid = Contact::getIdForURL($url, 0, false); Logger::info('Got id by probing', ['cid' => $cid, 'url' => $url]); } diff --git a/src/Module/Acctlink.php b/src/Module/Acctlink.php index f80ea4c73..bdcc3cf6f 100644 --- a/src/Module/Acctlink.php +++ b/src/Module/Acctlink.php @@ -22,8 +22,8 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Network\Probe; use Friendica\Core\System; +use Friendica\Model\Contact; /** * Redirects to another URL based on the parameter 'addr' @@ -35,9 +35,9 @@ class Acctlink extends BaseModule $addr = trim($_GET['addr'] ?? ''); if ($addr) { - $url = Probe::uri($addr)['url'] ?? ''; + $url = Contact::getByURL($addr)['url'] ?? ''; if ($url) { - System::externalRedirect($url); + System::externalRedirect($url['url']); exit(); } } diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 293293062..0a9525617 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -79,7 +79,7 @@ class AllFriends extends BaseModule $entries = []; foreach ($friends as $friend) { //get further details of the contact - $contactDetails = array_merge($friend, Model\Contact::getByURLForUser($friend['url'], $uid)); + $contactDetails = Model\Contact::getByURLForUser($friend['url'], $uid) ?: $friend; $connlnk = ''; // $friend[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photoMenu diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index 4f17b70e6..e969de9cc 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -47,8 +47,7 @@ class Feed extends BaseModule if (!empty($_REQUEST['url'])) { $url = $_REQUEST['url']; - $contact_id = Model\Contact::getIdForURL($url, local_user(), true); - $contact = Model\Contact::getById($contact_id); + $contact = Model\Contact::getByURLForUser($url, local_user(), false); $xml = Network::fetchUrl($contact['poll']); diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index 508fe3762..3d55c57f4 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -103,7 +103,7 @@ class Contacts extends BaseProfile continue; } - $contact_details = array_merge($contact, Contact::getByURLForUser($contact['url'], $a->profile['uid'])); + $contact_details = Contact::getByURLForUser($contact['url'], $a->profile['uid']) ?: $contact; $contacts[] = [ 'id' => $contact['id'], diff --git a/src/Module/RemoteFollow.php b/src/Module/RemoteFollow.php index bf71b077f..274ed3d06 100644 --- a/src/Module/RemoteFollow.php +++ b/src/Module/RemoteFollow.php @@ -28,6 +28,7 @@ use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\Search; use Friendica\Core\System; +use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Network\Probe; @@ -61,8 +62,8 @@ class RemoteFollow extends BaseModule } // Detect the network, make sure the provided URL is valid - $data = Probe::uri($url); - if ($data['network'] == Protocol::PHANTOM) { + $data = Contact::getByURL($url); + if (!$data) { notice(DI::l10n()->t("The provided profile link doesn't seem to be valid")); return; } diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 34085e339..23f12d263 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -239,7 +239,7 @@ class Index extends BaseSearch if ($isAddr) { $contact = Contact::selectFirst(['id'], ['addr' => $search, 'uid' => 0]); } else { - $contact = array_merge(['id' => 0], Contact::getByURL($search, null, ['id'])); + $contact = Contact::getByURL($search, null, ['id']) ?: ['id' => 0]; } if (DBA::isResult($contact)) { diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 0e4aca4a5..745a56c2a 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -445,9 +445,9 @@ class Processor $item['network'] = Protocol::ACTIVITYPUB; $item['author-link'] = $activity['author']; - $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); + $item['author-id'] = Contact::getIdForURL($activity['author'], 0, false); $item['owner-link'] = $activity['actor']; - $item['owner-id'] = Contact::getIdForURL($activity['actor'], 0, true); + $item['owner-id'] = Contact::getIdForURL($activity['actor'], 0, false); if (in_array(0, $activity['receiver']) && !empty($activity['unlisted'])) { $item['private'] = Item::UNLISTED; @@ -511,13 +511,13 @@ class Processor $item['uid'] = $receiver; if ($isForum) { - $item['contact-id'] = Contact::getIdForURL($activity['actor'], $receiver, true); + $item['contact-id'] = Contact::getIdForURL($activity['actor'], $receiver, false); } else { - $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true); + $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, false); } if (($receiver != 0) && empty($item['contact-id'])) { - $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true); + $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, false); } if (!empty($activity['directmessage'])) { diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index bd6f67128..6bf507ed8 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -150,7 +150,7 @@ class Transmitter */ public static function getOutbox($owner, $page = null) { - $public_contact = Contact::getIdForURL($owner['url'], 0, true); + $public_contact = Contact::getIdForURL($owner['url'], 0, false); $condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact, 'private' => [Item::PUBLIC, Item::UNLISTED], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index dc9182009..1ab8f9b80 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -221,7 +221,7 @@ class OStatus } // Ensure that we are having this contact (with uid=0) - $cid = Contact::getIdForURL($aliaslink, 0, true); + $cid = Contact::getIdForURL($aliaslink, 0, false); if ($cid) { $fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location']; @@ -2220,7 +2220,7 @@ class OStatus } $check_date = $feed_mode ? '' : DateTimeFormat::utc($last_update); - $authorid = Contact::getIdForURL($owner["url"], 0, true); + $authorid = Contact::getIdForURL($owner["url"], 0, false); $condition = ["`uid` = ? AND `received` > ? AND NOT `deleted` AND `private` != ? AND `visible` AND `wall` AND `parent-network` IN (?, ?)", diff --git a/src/Util/Profiler.php b/src/Util/Profiler.php index 1a5cd9992..240273bde 100644 --- a/src/Util/Profiler.php +++ b/src/Util/Profiler.php @@ -177,7 +177,7 @@ class Profiler implements ContainerInterface $output .= "\nDatabase Read:\n"; foreach ($this->callstack["database"] as $func => $time) { $time = round($time, 3); - if ($time > 0.001) { + if ($time > 0) { $output .= $func . ": " . $time . "\n"; } } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index c7b61dacc..99b97adc8 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -354,23 +354,23 @@ class Notifier // Send a salmon to the parent author $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]); if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) { - Logger::log('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]); + Logger::notice('Notify parent author', ['url' => $probed_contact["url"], 'notify' => $probed_contact["notify"]]); $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; } // Send a salmon to the parent owner $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]); if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) { - Logger::log('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]); + Logger::notice('Notify parent owner', ['url' => $probed_contact["url"], 'notify' => $probed_contact["notify"]]); $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; } // Send a salmon notification to every person we mentioned in the post foreach (Tag::getByURIId($target_item['uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]) as $tag) { - $probed_contact = Probe::uri($tag['url']); - if ($probed_contact["notify"] != "") { - Logger::log('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]); - $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; + $probed_contact = Contact::getByURL($tag['url']); + if (!empty($probed_contact['notify'])) { + Logger::notice('Notify mentioned user', ['url' => $probed_contact["url"], 'notify' => $probed_contact["notify"]]); + $url_recipients[$probed_contact['notify']] = $probed_contact['notify']; } } diff --git a/update.php b/update.php index 83011108b..82c34f9dd 100644 --- a/update.php +++ b/update.php @@ -203,7 +203,7 @@ function update_1260() while ($item = DBA::fetch($items)) { $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'], 'photo' => $item['owner-avatar'], 'network' => $item['network']]; - $cid = Contact::getIdForURL($item['owner-link'], 0, false, $contact); + $cid = Contact::getIdForURL($item['owner-link'], 0, null, $contact); if (empty($cid)) { continue; } @@ -219,7 +219,7 @@ function update_1260() while ($item = DBA::fetch($items)) { $contact = ['url' => $item['author-link'], 'name' => $item['author-name'], 'photo' => $item['author-avatar'], 'network' => $item['network']]; - $cid = Contact::getIdForURL($item['author-link'], 0, false, $contact); + $cid = Contact::getIdForURL($item['author-link'], 0, null, $contact); if (empty($cid)) { continue; }