mirror of
https://github.com/friendica/friendica
synced 2024-12-23 07:20:15 +00:00
Merge pull request #8815 from annando/forum-notice
Fix for "PHP Notice: Undefined index: forum in /src/Protocol/OStatus.php on line 2091"
This commit is contained in:
commit
abd5b2a881
2 changed files with 42 additions and 22 deletions
|
@ -190,6 +190,44 @@ class Contact
|
|||
return DBA::selectFirst('contact', $fields, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return array contact array
|
||||
*/
|
||||
public static function getByURL(string $url, int $uid = 0, array $fields = [], $update = null)
|
||||
{
|
||||
if ($update || is_null($update)) {
|
||||
$cid = self::getIdForURL($url, $uid, !($update ?? false));
|
||||
if (empty($cid)) {
|
||||
return [];
|
||||
}
|
||||
return self::getById($cid, $fields);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Then the addr (nick@server.tld)
|
||||
if (!DBA::isResult($contact)) {
|
||||
$contact = DBA::selectFirst('contact', $fields, ['addr' => str_replace('acct:', '', $url), 'uid' => $uid, 'deleted' => false], $options);
|
||||
}
|
||||
|
||||
// Then the alias (which could be anything)
|
||||
if (!DBA::isResult($contact)) {
|
||||
// The link could be provided as http although we stored it as https
|
||||
$ssl_url = str_replace('http://', 'https://', $url);
|
||||
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition, $options);
|
||||
}
|
||||
return $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the given contact is a follower
|
||||
*
|
||||
|
@ -1459,26 +1497,9 @@ class Contact
|
|||
return 0;
|
||||
}
|
||||
|
||||
/// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following
|
||||
// We first try the nurl (http://server.tld/nick), most common case
|
||||
$fields = ['id', 'avatar', 'updated', 'network'];
|
||||
$options = ['order' => ['id']];
|
||||
$contact = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false], $options);
|
||||
$contact = self::getByURL($url, $uid, ['id', 'avatar', 'updated', 'network'], false);
|
||||
|
||||
// Then the addr (nick@server.tld)
|
||||
if (!DBA::isResult($contact)) {
|
||||
$contact = DBA::selectFirst('contact', $fields, ['addr' => str_replace('acct:', '', $url), 'uid' => $uid, 'deleted' => false], $options);
|
||||
}
|
||||
|
||||
// Then the alias (which could be anything)
|
||||
if (!DBA::isResult($contact)) {
|
||||
// The link could be provided as http although we stored it as https
|
||||
$ssl_url = str_replace('http://', 'https://', $url);
|
||||
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition, $options);
|
||||
}
|
||||
|
||||
if (DBA::isResult($contact)) {
|
||||
if (!empty($contact)) {
|
||||
$contact_id = $contact["id"];
|
||||
$update_contact = false;
|
||||
|
||||
|
|
|
@ -2087,9 +2087,8 @@ class OStatus
|
|||
$mentioned = $newmentions;
|
||||
|
||||
foreach ($mentioned as $mention) {
|
||||
$contact = Contact::getDetailsByURL($mention, $owner['uid']);
|
||||
if (!empty($contact) && ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::TYPE_COMMUNITY) ||
|
||||
($contact['self'] && ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY)))) {
|
||||
$contact = Contact::getByURL($mention, 0, ['contact-type']);
|
||||
if (!empty($contact) && ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
|
||||
XML::addElement($doc, $entry, "link", "",
|
||||
[
|
||||
"rel" => "mentioned",
|
||||
|
|
Loading…
Reference in a new issue