From cb8581b29ae34da3816fabb977d01777525af25f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Sep 2017 04:55:36 +0000 Subject: [PATCH] Support for server independant Diaspora style links --- include/bbcode.php | 4 ++++ include/diaspora.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index aabf26161..be4667a29 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -985,6 +985,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa // Handle Diaspora posts $Text = preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", 'bb_DiasporaLinks', $Text); + // Server independent link to posts and comments + // See issue: https://github.com/diaspora/diaspora_federation/issues/75 + $Text = preg_replace("=diaspora://(.*?)/([^\s\]]*)=ism", System::baseUrl()."/display/$2", $Text); + // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text // if ($simplehtml != 7) { if (!$forplaintext) { diff --git a/include/diaspora.php b/include/diaspora.php index 4cc177a15..1907c0d5a 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1013,10 +1013,15 @@ class Diaspora { * @param array $item The item array */ private static function fetch_guid($item) { + preg_replace_callback("=diaspora://.*?/([^\s\]]*)=ism", + function ($match) use ($item) { + return self::fetch_guid_sub($match, $item); + }, $item["body"]); + preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", - function ($match) use ($item){ - return(self::fetch_guid_sub($match, $item)); - },$item["body"]); + function ($match) use ($item) { + return self::fetch_guid_sub($match, $item); + }, $item["body"]); } /**