From e8a2c68647947e0892acc9ba5a07f4dd3af152e8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Sep 2017 08:52:06 +0000 Subject: [PATCH] The plink in Diaspora posts now links to the correct place --- include/diaspora.php | 32 ++++++++++++++++------- view/theme/frio/templates/wall_thread.tpl | 2 +- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 63958f30bf..79e4ac51bf 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1183,7 +1183,7 @@ class Diaspora { * @return array the item record */ private static function parent_item($uid, $guid, $author, $contact) { - $r = q("SELECT `id`, `parent`, `body`, `wall`, `uri`, `private`, `origin`, + $r = q("SELECT `id`, `parent`, `body`, `wall`, `uri`, `guid`, `private`, `origin`, `author-name`, `author-link`, `author-avatar`, `owner-name`, `owner-link`, `owner-avatar` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", @@ -1266,26 +1266,38 @@ class Diaspora { * * @return string the post link */ - private static function plink($addr, $guid) { + private static function plink($addr, $guid, $parent_guid = '') { $r = q("SELECT `url`, `nick`, `network` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", dbesc($addr)); // Fallback - if (!$r) - return "https://".substr($addr,strpos($addr,"@")+1)."/posts/".$guid; + if (!dbm::is_result($r)) { + if ($parent_guid != '') { + return "https://".substr($addr,strpos($addr,"@") + 1)."/posts/".$parent_guid."#".$guid; + } else { + return "https://".substr($addr,strpos($addr,"@") + 1)."/posts/".$guid; + } + } // Friendica contacts are often detected as Diaspora contacts in the "fcontact" table // So we try another way as well. $s = q("SELECT `network` FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($r[0]["url"]))); - if ($s) + if (dbm::is_result($s)) { $r[0]["network"] = $s[0]["network"]; + } - if ($r[0]["network"] == NETWORK_DFRN) - return(str_replace("/profile/".$r[0]["nick"]."/", "/display/".$guid, $r[0]["url"]."/")); + if ($r[0]["network"] == NETWORK_DFRN) { + return str_replace("/profile/".$r[0]["nick"]."/", "/display/".$guid, $r[0]["url"]."/"); + } - if (self::is_redmatrix($r[0]["url"])) + if (self::is_redmatrix($r[0]["url"])) { return $r[0]["url"]."/?f=&mid=".$guid; + } - return "https://".substr($addr,strpos($addr,"@")+1)."/posts/".$guid; + if ($parent_guid != '') { + return "https://".substr($addr,strpos($addr,"@")+1)."/posts/".$parent_guid."#".$guid; + } else { + return "https://".substr($addr,strpos($addr,"@")+1)."/posts/".$guid; + } } /** @@ -1459,6 +1471,8 @@ class Diaspora { $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; + $datarray["plink"] = self::plink($author, $guid, $parent_item['guid']); + $body = diaspora2bb($text); $datarray["body"] = self::replace_people_guid($body, $person["url"]); diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 55681f53dd..dc339c83d0 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -233,7 +233,7 @@ as the value of $top_child_total (this is done at the end of this file)
{{$item.name}} - {{$item.ago}} {{if $item.location}} — ({{$item.location}}){{/if}} + {{$item.ago}} {{if $item.location}} — ({{$item.location}}){{/if}}