remote-self: Moved the code in a single function and cleaned it up.

This commit is contained in:
Michael Vogel 2014-10-29 01:05:09 +01:00
parent 01cb340752
commit 3e57954807
2 changed files with 59 additions and 126 deletions

View file

@ -2598,16 +2598,35 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
// This is my contact on another system, but it's really me. // This is my contact on another system, but it's really me.
// Turn this into a wall post. // Turn this into a wall post.
$notify = item_is_remote_self($contact, $datarray);
if($contact['remote_self'] AND (($contact['network'] === NETWORK_FEED) OR !$datarray['private'])) { $r = item_store($datarray, false, $notify);
logger('remote-self start - Contact '.$contact['url'].' - '.$contact['remote_self'].' Item '.print_r($datarray, true), LOGGER_DEBUG); logger('Stored - Contact '.$contact['url'].' Notify '.$notify.' return '.$r.' Item '.print_r($datarray, true), LOGGER_DEBUG);
if ($contact['remote_self'] == 1) { continue;
// Prevent that forwarded posts will be forwarded again
$notify = (normalise_link($datarray['author-link']) == normalise_link($datarray['owner-link'])); }
}
}
}
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()) if ($datarray["app"] == $a->get_hostname())
$notify = false; return 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 (($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)) { if (count($r)) {
$datarray['contact-id'] = $r[0]["id"]; $datarray['contact-id'] = $r[0]["id"];
@ -2619,55 +2638,30 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$datarray['author-link'] = $datarray['owner-link']; $datarray['author-link'] = $datarray['owner-link'];
$datarray['author-avatar'] = $datarray['owner-avatar']; $datarray['author-avatar'] = $datarray['owner-avatar'];
} }
$notify = true;
}
if (!isset($datarray["app"]) OR ($datarray["app"] == "")) if ($contact['network'] != NETWORK_FEED) {
$datarray["app"] = network_to_name($contact['network']); $datarray["guid"] = get_guid(32);
unset($datarray["plink"]);
if ($contact['network'] === NETWORK_FEED) $datarray["uri"] = item_new_uri($a->get_hostname(),$contact['uid']);
$datarray['private'] = 0; $datarray["parent-uri"] = $datarray["uri"];
elseif ($notify) { $datarray["extid"] = $contact['network'];
$datarray2 = $datarray; $urlpart = parse_url($datarray2['author-link']);
$datarray["app"] = $urlpart["host"];
// 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 } else
$notify = false; $datarray['private'] = 0;
}
$r = item_store($datarray, false, $notify); //if (!isset($datarray["app"]) OR ($datarray["app"] == ""))
logger('Stored - Contact '.$contact['url'].' Notify '.$notify.' return '.$r.' Item '.print_r($datarray, true), LOGGER_DEBUG); // $datarray["app"] = network_to_name($contact['network']);
continue;
} 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) { function local_delivery($importer,$data) {
@ -3751,68 +3745,7 @@ function local_delivery($importer,$data) {
// This is my contact on another system, but it's really me. // This is my contact on another system, but it's really me.
// Turn this into a wall post. // Turn this into a wall post.
$notify = item_is_remote_self($importer, $datarray);
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;
$posted_id = item_store($datarray, false, $notify); $posted_id = item_store($datarray, false, $notify);

View file

@ -158,7 +158,7 @@ function crepair_content(&$a) {
if ($contact['network'] == NETWORK_FEED) 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')); $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) elseif ($contact['network'] == NETWORK_DFRN)
$remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting')); $remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
$tpl = get_markup_template('crepair.tpl'); $tpl = get_markup_template('crepair.tpl');
$o .= replace_macros($tpl, array( $o .= replace_macros($tpl, array(