Merge pull request #1212 from annando/1410-remote-self
Remote-Self is now working for Friendica and Diaspora contacts as well
This commit is contained in:
commit
ec4e3d76bc
2 changed files with 70 additions and 50 deletions
|
@ -2598,34 +2598,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
|
|||
|
||||
// This is my contact on another system, but it's really me.
|
||||
// Turn this into a wall post.
|
||||
|
||||
if($contact['remote_self']) {
|
||||
if ($contact['remote_self'] == 2) {
|
||||
$r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid']));
|
||||
if (count($r)) {
|
||||
$datarray['contact-id'] = $r[0]["id"];
|
||||
|
||||
$datarray['owner-name'] = $r[0]["name"];
|
||||
$datarray['owner-link'] = $r[0]["url"];
|
||||
$datarray['owner-avatar'] = $r[0]["photo"];
|
||||
|
||||
$datarray['author-name'] = $datarray['owner-name'];
|
||||
$datarray['author-link'] = $datarray['owner-link'];
|
||||
$datarray['author-avatar'] = $datarray['owner-avatar'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($datarray["app"]) OR ($datarray["app"] == ""))
|
||||
$datarray["app"] = network_to_name($contact['network']);
|
||||
|
||||
$notify = true;
|
||||
if($contact['network'] === NETWORK_FEED) {
|
||||
$datarray['private'] = 0;
|
||||
}
|
||||
} else
|
||||
$notify = false;
|
||||
$notify = item_is_remote_self($contact, $datarray);
|
||||
|
||||
$r = item_store($datarray, false, $notify);
|
||||
logger('Stored - Contact '.$contact['url'].' Notify '.$notify.' return '.$r.' Item '.print_r($datarray, true), LOGGER_DEBUG);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
@ -2633,6 +2609,65 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
|
|||
}
|
||||
}
|
||||
|
||||
function item_is_remote_self($contact, &$datarray) {
|
||||
$a = get_app();
|
||||
|
||||
if (!$contact['remote_self'])
|
||||
return false;
|
||||
|
||||
// Prevent the forwarding of posts that are forwarded
|
||||
if ($datarray["extid"] == NETWORK_DFRN)
|
||||
return false;
|
||||
|
||||
// Prevent to forward already forwarded posts
|
||||
if ($datarray["app"] == $a->get_hostname())
|
||||
return false;
|
||||
|
||||
if (($contact['network'] != NETWORK_FEED) AND $datarray['private'])
|
||||
return false;
|
||||
|
||||
$datarray2 = $datarray;
|
||||
logger('remote-self start - Contact '.$contact['url'].' - '.$contact['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG);
|
||||
if ($contact['remote_self'] == 2) {
|
||||
$r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`",
|
||||
intval($contact['uid']));
|
||||
if (count($r)) {
|
||||
$datarray['contact-id'] = $r[0]["id"];
|
||||
|
||||
$datarray['owner-name'] = $r[0]["name"];
|
||||
$datarray['owner-link'] = $r[0]["url"];
|
||||
$datarray['owner-avatar'] = $r[0]["avatar"];
|
||||
|
||||
$datarray['author-name'] = $datarray['owner-name'];
|
||||
$datarray['author-link'] = $datarray['owner-link'];
|
||||
$datarray['author-avatar'] = $datarray['owner-avatar'];
|
||||
}
|
||||
|
||||
if ($contact['network'] != NETWORK_FEED) {
|
||||
$datarray["guid"] = get_guid(32);
|
||||
unset($datarray["plink"]);
|
||||
$datarray["uri"] = item_new_uri($a->get_hostname(),$contact['uid']);
|
||||
$datarray["parent-uri"] = $datarray["uri"];
|
||||
$datarray["extid"] = $contact['network'];
|
||||
$urlpart = parse_url($datarray2['author-link']);
|
||||
$datarray["app"] = $urlpart["host"];
|
||||
} else
|
||||
$datarray['private'] = 0;
|
||||
}
|
||||
|
||||
//if (!isset($datarray["app"]) OR ($datarray["app"] == ""))
|
||||
// $datarray["app"] = network_to_name($contact['network']);
|
||||
|
||||
if ($contact['network'] != NETWORK_FEED) {
|
||||
// Store the original post
|
||||
$r = item_store($datarray2, false, false);
|
||||
logger('remote-self post original item - Contact '.$contact['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG);
|
||||
} else
|
||||
$datarray["app"] = "Feed";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function local_delivery($importer,$data) {
|
||||
$a = get_app();
|
||||
|
||||
|
@ -3714,27 +3749,7 @@ function local_delivery($importer,$data) {
|
|||
|
||||
// This is my contact on another system, but it's really me.
|
||||
// Turn this into a wall post.
|
||||
|
||||
if($importer['remote_self']) {
|
||||
if ($importer['remote_self'] == 2) {
|
||||
$r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`",
|
||||
intval($importer['importer_uid']));
|
||||
if (count($r)) {
|
||||
$datarray['contact-id'] = $r[0]["id"];
|
||||
|
||||
$datarray['owner-name'] = $r[0]["name"];
|
||||
$datarray['owner-link'] = $r[0]["url"];
|
||||
$datarray['owner-avatar'] = $r[0]["photo"];
|
||||
|
||||
$datarray['author-name'] = $datarray['owner-name'];
|
||||
$datarray['author-link'] = $datarray['owner-link'];
|
||||
$datarray['author-avatar'] = $datarray['owner-avatar'];
|
||||
}
|
||||
}
|
||||
|
||||
$notify = true;
|
||||
} else
|
||||
$notify = false;
|
||||
$notify = item_is_remote_self($importer, $datarray);
|
||||
|
||||
$posted_id = item_store($datarray, false, $notify);
|
||||
|
||||
|
|
|
@ -152,9 +152,14 @@ function crepair_content(&$a) {
|
|||
// Disable remote self for everything except feeds.
|
||||
// There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
|
||||
// Problem is, you couldn't reply to both networks.
|
||||
if ($contact['network'] != NETWORK_FEED)
|
||||
if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA)))
|
||||
$allow_remote_self = false;
|
||||
|
||||
if ($contact['network'] == NETWORK_FEED)
|
||||
$remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting'), '2'=>t('Mirror as my own posting'));
|
||||
else
|
||||
$remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
|
||||
|
||||
$tpl = get_markup_template('crepair.tpl');
|
||||
$o .= replace_macros($tpl, array(
|
||||
'$label_name' => t('Name'),
|
||||
|
@ -168,7 +173,7 @@ function crepair_content(&$a) {
|
|||
'$label_photo' => t('New photo from this URL'),
|
||||
'$label_remote_self' => t('Remote Self'),
|
||||
'$allow_remote_self' => $allow_remote_self,
|
||||
'$remote_self' => array('remote_self', t('Mirror postings from this contact'), $contact['remote_self'], t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'), array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting'), '2'=>t('Mirror as my own posting'))),
|
||||
'$remote_self' => array('remote_self', t('Mirror postings from this contact'), $contact['remote_self'], t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'), $remote_self_options),
|
||||
'$contact_name' => $contact['name'],
|
||||
'$contact_nick' => $contact['nick'],
|
||||
'$contact_id' => $contact['id'],
|
||||
|
|
Loading…
Reference in a new issue