From 4768c6c6b666ab5483e715afb1cf6951c8f5fd97 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 6 Apr 2015 12:26:31 +0200 Subject: [PATCH] Diaspora: Central "plink" function --- include/diaspora.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 2dfa67e108..6b42e3c555 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -779,6 +779,18 @@ function diaspora_post_allow($importer,$contact) { return false; } +function diaspora_plink($addr, $guid) { + $r = q("SELECT `url`, `nick` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", $addr); + + // Fallback + if (!$r) + return 'https://'.substr($addr,strpos($addr,'@')+1).'/posts/'.$guid; + + if (strstr($r[0]["url"], "/channel/")) + return $r[0]["url"]."/?f=&mid=".$guid; + + return 'https://'.substr($addr,strpos($addr,'@')+1).'/posts/'.$guid; +} function diaspora_post($importer,$xml,$msg) { @@ -844,7 +856,7 @@ function diaspora_post($importer,$xml,$msg) { } } - $plink = 'https://'.substr($diaspora_handle,strpos($diaspora_handle,'@')+1).'/posts/'.$guid; + $plink = diaspora_plink($diaspora_handle, $guid); $datarray['uid'] = $importer['uid']; $datarray['contact-id'] = $contact['id']; @@ -937,7 +949,7 @@ function diaspora_store_by_guid($guid, $server) { $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); $datarray['private'] = $private; $datarray['parent'] = 0; - $datarray['plink'] = 'https://'.substr($author,strpos($author,'@')+1).'/posts/'.$guid; + $datarray['plink'] = diaspora_plink($author, $guid); $datarray['author-name'] = $person['name']; $datarray['author-link'] = $person['url']; $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); @@ -1150,7 +1162,7 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray = array(); - $plink = 'https://'.substr($diaspora_handle,strpos($diaspora_handle,'@')+1).'/posts/'.$guid; + $plink = diaspora_plink($diaspora_handle, $guid); $datarray['uid'] = $importer['uid']; $datarray['contact-id'] = $contact['id']; @@ -1197,7 +1209,7 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray2['guid'] = $orig_guid; $datarray2['uri'] = $datarray2['parent-uri'] = $orig_author.':'.$orig_guid; $datarray2['changed'] = $datarray2['created'] = $datarray2['edited'] = $datarray2['commented'] = $datarray2['received'] = datetime_convert('UTC','UTC',$orig_created); - $datarray2['plink'] = 'https://'.substr($orig_author,strpos($orig_author,'@')+1).'/posts/'.$orig_guid; + $datarray2['plink'] = diaspora_plink($orig_author, $orig_guid); $datarray2['author-name'] = $person['name']; $datarray2['author-link'] = $person['url']; @@ -1281,7 +1293,7 @@ function diaspora_asphoto($importer,$xml,$msg) { return; } - $plink = 'https://'.substr($diaspora_handle,strpos($diaspora_handle,'@')+1).'/posts/'.$guid; + $plink = diaspora_plink($diaspora_handle, $guid); $datarray = array();