]> git.mxchange.org Git - friendica.git/commitdiff
Diaspora: Central "plink" function
authorMichael Vogel <icarus@dabo.de>
Mon, 6 Apr 2015 10:26:31 +0000 (12:26 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 6 Apr 2015 10:26:31 +0000 (12:26 +0200)
include/diaspora.php

index 2dfa67e108dedfababdacde6ce90d46d56d0af67..6b42e3c555dbdc6f2b51ec217ee3b15f923bcd4b 100755 (executable)
@@ -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();