Merge pull request #1485 from annando/1504-diaspora-plink

Diaspora: Central "plink" function
This commit is contained in:
Tobias Diekershoff 2015-04-06 12:55:38 +02:00
commit 95c58e59d3

View File

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