Issue 7892: Improve "plink" generation for Diaspora posts

This commit is contained in:
Michael 2020-03-25 16:42:53 +00:00
parent 37f0cb0697
commit 6249b674dc
2 changed files with 45 additions and 19 deletions

View file

@ -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)
);

View file

@ -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);
}
}