From: Michael Date: Wed, 25 Mar 2020 16:42:53 +0000 (+0000) Subject: Issue 7892: Improve "plink" generation for Diaspora posts X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6249b674dc3d36a0cbd58a48ced399f46611e41c;p=friendica.git Issue 7892: Improve "plink" generation for Diaspora posts --- diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 9ae27994c7..2b739278a7 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1142,7 +1142,7 @@ class Contact // Fetch contact data from the contact table for the given user $r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, - `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending` + `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`, `rel`, `pending`,`baseurl` FROM `contact` WHERE `addr` = '%s' AND `uid` = %d AND NOT `deleted`", DBA::escape($addr), intval($uid) @@ -1150,7 +1150,7 @@ class Contact // Fetch the data from the contact table with "uid=0" (which is filled automatically) if (!DBA::isResult($r)) { $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, - `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending` + `keywords`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`, `rel`, `pending`, `baseurl` FROM `contact` WHERE `addr` = '%s' AND `uid` = 0 AND NOT `deleted`", DBA::escape($addr) ); @@ -1159,7 +1159,7 @@ class Contact // Fetch the data from the gcontact table if (!DBA::isResult($r)) { $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`, - `keywords`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending` + `keywords`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`, 2 AS `rel`, 0 AS `pending`, `server_url` AS `baseurl` FROM `gcontact` WHERE `addr` = '%s'", DBA::escape($addr) ); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 5c90f88f7a..08a4c7bddb 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1581,9 +1581,9 @@ class Diaspora * * @return bool is it a hubzilla server? */ - public static function isRedmatrix($url) + private static function isHubzilla($url) { - return(strstr($url, "/channel/")); + return(strstr($url, '/channel/')); } /** @@ -1600,28 +1600,55 @@ class Diaspora private static function plink($addr, $guid, $parent_guid = '') { $contact = Contact::getDetailsByAddr($addr); + if (empty($contact)) { + Logger::info('No contact data for address', ['addr' => $addr]); + return ''; + } - // Fallback - if (!$contact) { - if ($parent_guid != '') { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $parent_guid . "#" . $guid; - } else { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $guid; + if (empty($contact['baseurl'])) { + $contact['baseurl'] = 'https://' . substr($addr, strpos($addr, '@') + 1); + Logger::info('Create baseurl from address', ['baseurl' => $contact['baseurl'], 'url' => $contact['url']]); + } + + $platform = ''; + $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => Strings::normaliseLink($contact['baseurl'])]); + if (!empty($gserver['platform'])) { + $platform = strtolower($gserver['platform']); + Logger::info('Detected platform', ['platform' => $platform, 'url' => $contact['url']]); + } + if ($platform == 'socialhome') { + // Socialhome doesn't offer an item endpoint that we could use + Logger::info('Ignoring Socialhome', ['platform' => $platform, 'url' => $contact['url']]); + return ''; + } + + if (!in_array($platform, ['diaspora', 'friendica', 'hubzilla'])) { + if (self::isHubzilla($contact['url'])) { + Logger::info('Detected unknown platform as Hubzilla', ['platform' => $platform, 'url' => $contact['url']]); + $platform = 'hubzilla'; + } elseif ($contact['network'] == Protocol::DFRN) { + Logger::info('Detected unknown platform as Friendica', ['platform' => $platform, 'url' => $contact['url']]); + $platform = 'friendica'; } } - if ($contact["network"] == Protocol::DFRN) { - return str_replace("/profile/" . $contact["nick"] . "/", "/display/" . $guid, $contact["url"] . "/"); + if ($platform == 'friendica') { + return str_replace('/profile/' . $contact['nick'] . '/', '/display/' . $guid, $contact['url'] . '/'); } - if (self::isRedmatrix($contact["url"])) { - return $contact["url"] . "/?mid=" . $guid; + if ($platform == 'hubzilla') { + return $contact['baseurl'] . '/item/' . $guid; + } + + if ($platform != 'diaspora') { + Logger::info('Unknown platform', ['platform' => $platform, 'url' => $contact['url']]); + return ''; } if ($parent_guid != '') { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $parent_guid . "#" . $guid; + return $contact['baseurl'] . '/posts/' . $parent_guid . '#' . $guid; } else { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $guid; + return $contact['baseurl'] . '/posts/' . $guid; } } @@ -1869,7 +1896,6 @@ class Diaspora $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; $datarray["plink"] = self::plink($author, $guid, $parent_item['guid']); - $body = Markdown::toBBCode($text); $datarray["body"] = self::replacePeopleGuid($body, $person["url"]); @@ -2907,7 +2933,7 @@ class Diaspora $datarray["object-type"] = Activity\ObjectType::NOTE; // Add OEmbed and other information to the body - if (!self::isRedmatrix($contact["url"])) { + if (!self::isHubzilla($contact["url"])) { $body = add_page_info_to_body($body, false, true); } }