From f6522658f6176e3f8d2eed3038f0ca7901970ff2 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 22 Oct 2014 08:30:16 +0200 Subject: [PATCH 1/9] Using "remote self" to synchronize Frandiaca accounts --- include/items.php | 10 +++++++--- mod/crepair.php | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/items.php b/include/items.php index 0d37fa1a6..1107553e8 100644 --- a/include/items.php +++ b/include/items.php @@ -2589,7 +2589,9 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) // Turn this into a wall post. if($contact['remote_self']) { - if ($contact['remote_self'] == 2) { + if ($contact['remote_self'] == 1) + $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); + elseif ($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"]; @@ -2602,14 +2604,16 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $datarray['author-link'] = $datarray['owner-link']; $datarray['author-avatar'] = $datarray['owner-avatar']; } + $notify = true; } if (!isset($datarray["app"]) OR ($datarray["app"] == "")) $datarray["app"] = network_to_name($contact['network']); - $notify = true; - if($contact['network'] === NETWORK_FEED) { + if ($contact['network'] === NETWORK_FEED) $datarray['private'] = 0; + elseif ($contact['network'] === NETWORK_DFRN) { + // To-Do: Neue GUID oder sowas } } else $notify = false; diff --git a/mod/crepair.php b/mod/crepair.php index d7eb14627..23f833c5b 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -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))) $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')); + elseif ($contact['network'] == NETWORK_DFRN) + $remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded 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'], From 332531599e61565eb7918772782344f694a31b4d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 27 Oct 2014 21:13:21 +0100 Subject: [PATCH 2/9] Create a new guid and a separated item if remote self is used on a network that isn't a feed --- include/items.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/include/items.php b/include/items.php index 0a0d7f5dc..2999a535b 100644 --- a/include/items.php +++ b/include/items.php @@ -2599,8 +2599,9 @@ 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'] AND (($contact['network'] === NETWORK_FEED) OR !$datarray['private'])) { if ($contact['remote_self'] == 1) + // Prevent that forwarded posts will be forwarded again $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); elseif ($contact['remote_self'] == 2) { $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); @@ -2618,14 +2619,27 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $notify = true; } - if (!isset($datarray["app"]) OR ($datarray["app"] == "")) - $datarray["app"] = network_to_name($contact['network']); - if ($contact['network'] === NETWORK_FEED) $datarray['private'] = 0; - elseif ($contact['network'] === NETWORK_DFRN) { - // To-Do: Neue GUID oder sowas + elseif ($notify) { + // At first store the original post + $r = item_store($datarray, false, false); + + // Then create a new guid and uri and post it again as a forwarded post + $datarray["guid"] = get_guid(32); + $datarray["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); + $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"]; + } } + + if (!isset($datarray["app"]) OR ($datarray["app"] == "")) + $datarray["app"] = network_to_name($contact['network']); } else $notify = false; From f4860d3fd0d3e4f437a82a1b0c8bb00328c51c66 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 27 Oct 2014 21:44:30 +0100 Subject: [PATCH 3/9] Remote-self: relocated the code (may now work?) --- include/items.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/include/items.php b/include/items.php index 2999a535b..d9b4212f7 100644 --- a/include/items.php +++ b/include/items.php @@ -2619,27 +2619,32 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $notify = true; } + if (!isset($datarray["app"]) OR ($datarray["app"] == "")) + $datarray["app"] = network_to_name($contact['network']); + if ($contact['network'] === NETWORK_FEED) $datarray['private'] = 0; elseif ($notify) { - // At first store the original post - $r = item_store($datarray, false, false); + $datarray2 = $datarray; - // Then create a new guid and uri and post it again as a forwarded post - $datarray["guid"] = get_guid(32); - $datarray["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); + // Create a new guid and uri and post it as a forwarded post + $datarray2["guid"] = get_guid(32); + $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); $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"]; + $datarray2['contact-id'] = $r[0]["id"]; - $datarray['owner-name'] = $r[0]["name"]; - $datarray['owner-link'] = $r[0]["url"]; - $datarray['owner-avatar'] = $r[0]["photo"]; + $datarray2['owner-name'] = $r[0]["name"]; + $datarray2['owner-link'] = $r[0]["url"]; + $datarray2['owner-avatar'] = $r[0]["photo"]; } - } - if (!isset($datarray["app"]) OR ($datarray["app"] == "")) - $datarray["app"] = network_to_name($contact['network']); + // Store the forwarded post + $r = item_store($datarray2, false, true); + + // Let the original item just be a regular item + $notify = false; + } } else $notify = false; From e46f597b006d1d92b5a70a2e2847cf3c3d6e5fb9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 28 Oct 2014 08:30:04 +0100 Subject: [PATCH 4/9] Remote-self functionality added at another place - time for a separated function. (tbd) --- include/items.php | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/include/items.php b/include/items.php index d9b4212f7..896b62eb4 100644 --- a/include/items.php +++ b/include/items.php @@ -2600,6 +2600,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) // Turn this into a wall post. if($contact['remote_self'] AND (($contact['network'] === NETWORK_FEED) OR !$datarray['private'])) { + logger('remote-self start - Contact '.$contact['url'].' - '.$contact['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); if ($contact['remote_self'] == 1) // Prevent that forwarded posts will be forwarded again $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); @@ -2630,6 +2631,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) // Create a new guid and uri and post it as a forwarded post $datarray2["guid"] = get_guid(32); $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); + $datarray2["parent-uri"] = $datarray2["uri"]; $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); if (count($r)) { $datarray2['contact-id'] = $r[0]["id"]; @@ -2641,6 +2643,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) // Store the forwarded post $r = item_store($datarray2, false, true); + logger('remote-self forwarded post - Contact '.$contact['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG); // Let the original item just be a regular item $notify = false; @@ -2649,6 +2652,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $notify = false; $r = item_store($datarray, false, $notify); + logger('Stored - Contact '.$contact['url'].' Notify '.$notify.' return '.$r.' Item '.print_r($datarray, true), LOGGER_DEBUG); continue; } @@ -3738,8 +3742,12 @@ 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) { + if($importer['remote_self'] AND (($importer['network'] === NETWORK_FEED) OR !$datarray['private'])) { + logger('remote-self start - Contact '.$importer['url'].' - '.$importer['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); + if ($importer['remote_self'] == 1) + // Prevent that forwarded posts will be forwarded again + $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); + elseif ($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)) { @@ -3753,9 +3761,36 @@ function local_delivery($importer,$data) { $datarray['author-link'] = $datarray['owner-link']; $datarray['author-avatar'] = $datarray['owner-avatar']; } + $notify = true; } - $notify = true; + if (!isset($datarray["app"]) OR ($datarray["app"] == "")) + $datarray["app"] = network_to_name($importer['network']); + + if ($importer['network'] === NETWORK_FEED) + $datarray['private'] = 0; + elseif ($notify) { + $datarray2 = $datarray; + // Create a new guid and uri and post it as a forwarded post + $datarray2["guid"] = get_guid(32); + $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); + $datarray2["parent-uri"] = $datarray2["uri"]; + $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); + if (count($r)) { + $datarray2['contact-id'] = $r[0]["id"]; + + $datarray2['owner-name'] = $r[0]["name"]; + $datarray2['owner-link'] = $r[0]["url"]; + $datarray2['owner-avatar'] = $r[0]["photo"]; + } + + // Store the forwarded post + $r = item_store($datarray2, false, true); + logger('remote-self forwarded post - Contact '.$importer['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG); + + // Let the original item just be a regular item + $notify = false; + } } else $notify = false; From 01cb340752aee7d18d4c3f4e9ec4aaec0f6c082e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 28 Oct 2014 22:10:58 +0100 Subject: [PATCH 5/9] Let remote-self posts appear as own posts - for test reasons --- include/items.php | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/include/items.php b/include/items.php index 896b62eb4..9c11a1f39 100644 --- a/include/items.php +++ b/include/items.php @@ -2601,17 +2601,19 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) if($contact['remote_self'] AND (($contact['network'] === NETWORK_FEED) OR !$datarray['private'])) { logger('remote-self start - Contact '.$contact['url'].' - '.$contact['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); - if ($contact['remote_self'] == 1) + if ($contact['remote_self'] == 1) { // Prevent that forwarded posts will be forwarded again $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); - elseif ($contact['remote_self'] == 2) { + if ($datarray["app"] == $a->get_hostname()) + $notify = false; + } elseif ($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['owner-avatar'] = $r[0]["avatar"]; $datarray['author-name'] = $datarray['owner-name']; $datarray['author-link'] = $datarray['owner-link']; @@ -2630,15 +2632,23 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) // Create a new guid and uri and post it as a forwarded post $datarray2["guid"] = get_guid(32); + unset($datarray2["plink"]); $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); $datarray2["parent-uri"] = $datarray2["uri"]; + $datarray2["extid"] = NETWORK_DFRN; + $urlpart = parse_url($datarray['author-link']); + $datarray2["app"] = $urlpart["host"]; $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); if (count($r)) { $datarray2['contact-id'] = $r[0]["id"]; $datarray2['owner-name'] = $r[0]["name"]; $datarray2['owner-link'] = $r[0]["url"]; - $datarray2['owner-avatar'] = $r[0]["photo"]; + $datarray2['owner-avatar'] = $r[0]["avatar"]; + + $datarray2['author-name'] = $datarray2['owner-name']; + $datarray2['author-link'] = $datarray2['owner-link']; + $datarray2['author-avatar'] = $datarray2['owner-avatar']; } // Store the forwarded post @@ -2663,7 +2673,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) function local_delivery($importer,$data) { $a = get_app(); - logger(__function__, LOGGER_TRACE); + logger(__function__, LOGGER_TRACE); if($importer['readonly']) { // We aren't receiving stuff from this person. But we will quietly ignore them @@ -3744,10 +3754,12 @@ function local_delivery($importer,$data) { if($importer['remote_self'] AND (($importer['network'] === NETWORK_FEED) OR !$datarray['private'])) { logger('remote-self start - Contact '.$importer['url'].' - '.$importer['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); - if ($importer['remote_self'] == 1) + if ($importer['remote_self'] == 1) { // Prevent that forwarded posts will be forwarded again $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); - elseif ($importer['remote_self'] == 2) { + if ($datarray["app"] == $a->get_hostname()) + $notify = false; + } elseif ($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)) { @@ -3755,7 +3767,7 @@ function local_delivery($importer,$data) { $datarray['owner-name'] = $r[0]["name"]; $datarray['owner-link'] = $r[0]["url"]; - $datarray['owner-avatar'] = $r[0]["photo"]; + $datarray['owner-avatar'] = $r[0]["avatar"]; $datarray['author-name'] = $datarray['owner-name']; $datarray['author-link'] = $datarray['owner-link']; @@ -3764,8 +3776,8 @@ function local_delivery($importer,$data) { $notify = true; } - if (!isset($datarray["app"]) OR ($datarray["app"] == "")) - $datarray["app"] = network_to_name($importer['network']); + //if (!isset($datarray["app"]) OR ($datarray["app"] == "")) + // $datarray["app"] = network_to_name($importer['network']); if ($importer['network'] === NETWORK_FEED) $datarray['private'] = 0; @@ -3773,15 +3785,23 @@ function local_delivery($importer,$data) { $datarray2 = $datarray; // Create a new guid and uri and post it as a forwarded post $datarray2["guid"] = get_guid(32); + unset($datarray2["plink"]); $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); $datarray2["parent-uri"] = $datarray2["uri"]; + $datarray2["extid"] = NETWORK_DFRN; + $urlpart = parse_url($datarray['author-link']); + $datarray2["app"] = $urlpart["host"]; $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); if (count($r)) { $datarray2['contact-id'] = $r[0]["id"]; $datarray2['owner-name'] = $r[0]["name"]; $datarray2['owner-link'] = $r[0]["url"]; - $datarray2['owner-avatar'] = $r[0]["photo"]; + $datarray2['owner-avatar'] = $r[0]["avatar"]; + + $datarray2['author-name'] = $datarray2['owner-name']; + $datarray2['author-link'] = $datarray2['owner-link']; + $datarray2['author-avatar'] = $datarray2['owner-avatar']; } // Store the forwarded post From 3e579548074a8df5037030376af3624291496e8d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 29 Oct 2014 01:05:09 +0100 Subject: [PATCH 6/9] remote-self: Moved the code in a single function and cleaned it up. --- include/items.php | 181 +++++++++++++++------------------------------- mod/crepair.php | 4 +- 2 files changed, 59 insertions(+), 126 deletions(-) diff --git a/include/items.php b/include/items.php index 9c11a1f39..c4555e82d 100644 --- a/include/items.php +++ b/include/items.php @@ -2598,68 +2598,7 @@ 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'] AND (($contact['network'] === NETWORK_FEED) OR !$datarray['private'])) { - logger('remote-self start - Contact '.$contact['url'].' - '.$contact['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); - if ($contact['remote_self'] == 1) { - // Prevent that forwarded posts will be forwarded again - $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); - if ($datarray["app"] == $a->get_hostname()) - $notify = false; - } elseif ($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]["avatar"]; - - $datarray['author-name'] = $datarray['owner-name']; - $datarray['author-link'] = $datarray['owner-link']; - $datarray['author-avatar'] = $datarray['owner-avatar']; - } - $notify = true; - } - - if (!isset($datarray["app"]) OR ($datarray["app"] == "")) - $datarray["app"] = network_to_name($contact['network']); - - if ($contact['network'] === NETWORK_FEED) - $datarray['private'] = 0; - elseif ($notify) { - $datarray2 = $datarray; - - // Create a new guid and uri and post it as a forwarded post - $datarray2["guid"] = get_guid(32); - unset($datarray2["plink"]); - $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); - $datarray2["parent-uri"] = $datarray2["uri"]; - $datarray2["extid"] = NETWORK_DFRN; - $urlpart = parse_url($datarray['author-link']); - $datarray2["app"] = $urlpart["host"]; - $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); - if (count($r)) { - $datarray2['contact-id'] = $r[0]["id"]; - - $datarray2['owner-name'] = $r[0]["name"]; - $datarray2['owner-link'] = $r[0]["url"]; - $datarray2['owner-avatar'] = $r[0]["avatar"]; - - $datarray2['author-name'] = $datarray2['owner-name']; - $datarray2['author-link'] = $datarray2['owner-link']; - $datarray2['author-avatar'] = $datarray2['owner-avatar']; - } - - // Store the forwarded post - $r = item_store($datarray2, false, true); - logger('remote-self forwarded post - Contact '.$contact['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG); - - // Let the original item just be a regular item - $notify = false; - } - } 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); @@ -2670,6 +2609,61 @@ 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 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(); @@ -3751,68 +3745,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'] AND (($importer['network'] === NETWORK_FEED) OR !$datarray['private'])) { - logger('remote-self start - Contact '.$importer['url'].' - '.$importer['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); - if ($importer['remote_self'] == 1) { - // Prevent that forwarded posts will be forwarded again - $notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); - if ($datarray["app"] == $a->get_hostname()) - $notify = false; - } elseif ($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]["avatar"]; - - $datarray['author-name'] = $datarray['owner-name']; - $datarray['author-link'] = $datarray['owner-link']; - $datarray['author-avatar'] = $datarray['owner-avatar']; - } - $notify = true; - } - - //if (!isset($datarray["app"]) OR ($datarray["app"] == "")) - // $datarray["app"] = network_to_name($importer['network']); - - if ($importer['network'] === NETWORK_FEED) - $datarray['private'] = 0; - elseif ($notify) { - $datarray2 = $datarray; - // Create a new guid and uri and post it as a forwarded post - $datarray2["guid"] = get_guid(32); - unset($datarray2["plink"]); - $datarray2["uri"] = item_new_uri($a->get_hostname(),$importer['uid']); - $datarray2["parent-uri"] = $datarray2["uri"]; - $datarray2["extid"] = NETWORK_DFRN; - $urlpart = parse_url($datarray['author-link']); - $datarray2["app"] = $urlpart["host"]; - $r = q("SELECT `id`,`url`,`name`,`photo`,`network` FROM `contact` WHERE `uid` = %d AND `self`", intval($importer['uid'])); - if (count($r)) { - $datarray2['contact-id'] = $r[0]["id"]; - - $datarray2['owner-name'] = $r[0]["name"]; - $datarray2['owner-link'] = $r[0]["url"]; - $datarray2['owner-avatar'] = $r[0]["avatar"]; - - $datarray2['author-name'] = $datarray2['owner-name']; - $datarray2['author-link'] = $datarray2['owner-link']; - $datarray2['author-avatar'] = $datarray2['owner-avatar']; - } - - // Store the forwarded post - $r = item_store($datarray2, false, true); - logger('remote-self forwarded post - Contact '.$importer['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG); - - // Let the original item just be a regular item - $notify = false; - } - } else - $notify = false; + $notify = item_is_remote_self($importer, $datarray); $posted_id = item_store($datarray, false, $notify); diff --git a/mod/crepair.php b/mod/crepair.php index 23f833c5b..aba71232c 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -157,8 +157,8 @@ function crepair_content(&$a) { 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')); - elseif ($contact['network'] == NETWORK_DFRN) - $remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting')); + elseif ($contact['network'] == NETWORK_DFRN) + $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( From 338ad1d85f864f2303c2f9185b24fee48fb48771 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 29 Oct 2014 01:31:29 +0100 Subject: [PATCH 7/9] Additional check for repeated posts --- include/items.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/items.php b/include/items.php index c4555e82d..3171e4f93 100644 --- a/include/items.php +++ b/include/items.php @@ -2615,6 +2615,10 @@ function item_is_remote_self($contact, &$datarray) { 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; From 59517f6e58fdb49e5d42784bbdb8563864510b1a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 29 Oct 2014 01:42:43 +0100 Subject: [PATCH 8/9] Remote self is now working for diaspora contacts as well. --- include/items.php | 2 +- mod/crepair.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/items.php b/include/items.php index 3171e4f93..ac7e34286 100644 --- a/include/items.php +++ b/include/items.php @@ -2616,7 +2616,7 @@ function item_is_remote_self($contact, &$datarray) { return false; // Prevent the forwarding of posts that are forwarded - if ($datarray["extid"] == NETWORK_DFRN) + if (in_array($datarray["extid"], array(NETWORK_DFRN, NETWORK_DIASPORA))) return false; // Prevent to forward already forwarded posts diff --git a/mod/crepair.php b/mod/crepair.php index aba71232c..400817d6f 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -152,12 +152,12 @@ 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 (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN))) + 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')); - elseif ($contact['network'] == NETWORK_DFRN) + else $remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting')); $tpl = get_markup_template('crepair.tpl'); From 17f87ef9b213e0e49fa40bbe4a7a93e708d47f73 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 29 Oct 2014 08:24:05 +0100 Subject: [PATCH 9/9] Remote-self: It does only make sense to check for duplicates from friendica --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index ac7e34286..3171e4f93 100644 --- a/include/items.php +++ b/include/items.php @@ -2616,7 +2616,7 @@ function item_is_remote_self($contact, &$datarray) { return false; // Prevent the forwarding of posts that are forwarded - if (in_array($datarray["extid"], array(NETWORK_DFRN, NETWORK_DIASPORA))) + if ($datarray["extid"] == NETWORK_DFRN) return false; // Prevent to forward already forwarded posts