DFRN import seems to work. Improvements are possible :-)

This commit is contained in:
Michael Vogel 2016-01-30 02:57:40 +01:00
parent cd1f3cde00
commit 69457a4a5b
3 changed files with 43 additions and 16 deletions

View File

@ -69,7 +69,7 @@ class dfrn2 {
* *
* @return Returns an array with relevant data of the author * @return Returns an array with relevant data of the author
*/ */
private function fetchauthor($xpath, $context, $importer, $element, &$contact, $onlyfetch) { private function fetchauthor($xpath, $context, $importer, $element, $contact, $onlyfetch) {
$author = array(); $author = array();
$author["name"] = $xpath->evaluate($element.'/atom:name/text()', $context)->item(0)->nodeValue; $author["name"] = $xpath->evaluate($element.'/atom:name/text()', $context)->item(0)->nodeValue;
@ -77,9 +77,8 @@ class dfrn2 {
$r = q("SELECT `id`, `uid`, `network`, `avatar-date`, `name-date`, `uri-date`, `addr`, $r = q("SELECT `id`, `uid`, `network`, `avatar-date`, `name-date`, `uri-date`, `addr`,
`name`, `nick`, `about`, `location`, `keywords`, `bdyear`, `bd` `name`, `nick`, `about`, `location`, `keywords`, `bdyear`, `bd`
FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
intval($importer["uid"]), dbesc(normalise_link($author["author-link"])), intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET));
dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET));
if ($r) { if ($r) {
$contact = $r[0]; $contact = $r[0];
$author["contact-id"] = $r[0]["id"]; $author["contact-id"] = $r[0]["id"];
@ -87,6 +86,7 @@ class dfrn2 {
} else { } else {
$author["contact-id"] = $contact["id"]; $author["contact-id"] = $contact["id"];
$author["network"] = $contact["network"]; $author["network"] = $contact["network"];
$onlyfetch = true;
} }
// Until now we aren't serving different sizes - but maybe later // Until now we aren't serving different sizes - but maybe later
@ -268,6 +268,8 @@ class dfrn2 {
private function process_mail($xpath, $mail, $importer) { private function process_mail($xpath, $mail, $importer) {
logger("Processing mails");
$msg = array(); $msg = array();
$msg["uid"] = $importer['importer_uid']; $msg["uid"] = $importer['importer_uid'];
$msg["from-name"] = $xpath->query('dfrn:sender/dfrn:name/text()', $mail)->item(0)->nodeValue; $msg["from-name"] = $xpath->query('dfrn:sender/dfrn:name/text()', $mail)->item(0)->nodeValue;
@ -308,6 +310,8 @@ class dfrn2 {
private function process_suggestion($xpath, $suggestion, $importer) { private function process_suggestion($xpath, $suggestion, $importer) {
logger("Processing suggestions");
$suggest = array(); $suggest = array();
$suggest["uid"] = $importer["importer_uid"]; $suggest["uid"] = $importer["importer_uid"];
$suggest["cid"] = $importer["id"]; $suggest["cid"] = $importer["id"];
@ -400,6 +404,8 @@ class dfrn2 {
private function process_relocation($xpath, $relocation, $importer) { private function process_relocation($xpath, $relocation, $importer) {
logger("Processing relocations");
$relocate = array(); $relocate = array();
$relocate["uid"] = $importer["importer_uid"]; $relocate["uid"] = $importer["importer_uid"];
$relocate["cid"] = $importer["id"]; $relocate["cid"] = $importer["id"];
@ -478,6 +484,9 @@ class dfrn2 {
} }
private function process_entry($header, $xpath, $entry, $importer, $contact) { private function process_entry($header, $xpath, $entry, $importer, $contact) {
logger("Processing entries");
$item = $header; $item = $header;
// Fetch the owner // Fetch the owner
@ -600,7 +609,7 @@ class dfrn2 {
if(strlen($item["tag"])) if(strlen($item["tag"]))
$item["tag"] .= ','; $item["tag"] .= ',';
$item["tag"] .= "#[url=".$a->get_baseurl()."/search?tag=".$term."]".$term."[/url]"; $item["tag"] .= "#[url=".App::get_baseurl()."/search?tag=".$term."]".$term."[/url]";
} }
} }
} }
@ -646,8 +655,6 @@ class dfrn2 {
//print_r($item); //print_r($item);
$item_id = item_store($item); $item_id = item_store($item);
return;
if (!$item_id) { if (!$item_id) {
logger("Error storing item", LOGGER_DEBUG); logger("Error storing item", LOGGER_DEBUG);
return false; return false;
@ -672,7 +679,10 @@ class dfrn2 {
return $item_id; return $item_id;
} }
private function process_deletion($header, $xpath, $deletion, $importer, $contact) { private function process_deletion($header, $xpath, $deletion, $importer, $contact_id) {
logger("Processing deletions");
foreach($deletion->attributes AS $attributes) { foreach($deletion->attributes AS $attributes) {
if ($attributes->name == "ref") if ($attributes->name == "ref")
$uri = $attributes->textContent; $uri = $attributes->textContent;
@ -684,14 +694,14 @@ class dfrn2 {
else else
$when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s'); $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
if (!$uri OR !is_array($contact)) if (!$uri OR !$contact)
return false; return false;
$r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id`
WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1",
dbesc($uri), dbesc($uri),
intval($importer["uid"]), intval($importer["uid"]),
intval($contact["id"]) intval($contact_id)
); );
if(count($r)) { if(count($r)) {
$item = $r[0]; $item = $r[0];
@ -788,10 +798,6 @@ class dfrn2 {
function import($xml,$importer, &$contact) { function import($xml,$importer, &$contact) {
$a = get_app();
logger("Import DFRN message", LOGGER_DEBUG);
if ($xml == "") if ($xml == "")
return; return;
@ -828,6 +834,13 @@ class dfrn2 {
// Only the "dfrn:owner" in the head section contains all data // Only the "dfrn:owner" in the head section contains all data
$dfrn_owner = self::fetchauthor($xpath, $doc->firstChild, $importer, "dfrn:owner", $contact, false); $dfrn_owner = self::fetchauthor($xpath, $doc->firstChild, $importer, "dfrn:owner", $contact, false);
logger("Import DFRN message for user ".$importer["uid"]." from contact ".$contact["id"]." ".print_r($dfrn_owner, true)." - ".print_r($contact, true), LOGGER_DEBUG);
//if (!$dfrn_owner["found"]) {
// logger("Author doesn't seem to be known by us. UID: ".$importer["uid"]." Contact: ".$dfrn_owner["contact-id"]." - ".print_r($dfrn_owner, true));
// return;
//}
// is it a public forum? Private forums aren't supported by now with this method // is it a public forum? Private forums aren't supported by now with this method
$forum = intval($xpath->evaluate('/atom:feed/dfrn:community/text()', $context)->item(0)->nodeValue); $forum = intval($xpath->evaluate('/atom:feed/dfrn:community/text()', $context)->item(0)->nodeValue);
@ -851,7 +864,7 @@ class dfrn2 {
$deletions = $xpath->query('/atom:feed/at:deleted-entry'); $deletions = $xpath->query('/atom:feed/at:deleted-entry');
foreach ($deletions AS $deletion) foreach ($deletions AS $deletion)
self::process_deletion($header, $xpath, $deletion, $importer, $contact); self::process_deletion($header, $xpath, $deletion, $importer, $dfrn_owner["contact-id"]);
$entries = $xpath->query('/atom:feed/atom:entry'); $entries = $xpath->query('/atom:feed/atom:entry');
foreach ($entries AS $entry) foreach ($entries AS $entry)

View File

@ -17,6 +17,7 @@ require_once('include/feed.php');
require_once('include/Contact.php'); require_once('include/Contact.php');
require_once('mod/share.php'); require_once('mod/share.php');
require_once('include/enotify.php'); require_once('include/enotify.php');
require_once('include/import-dfrn.php');
require_once('library/defuse/php-encryption-1.2.1/Crypto.php'); require_once('library/defuse/php-encryption-1.2.1/Crypto.php');
@ -1693,6 +1694,13 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
} }
return; return;
} }
// dfrn-test
// if ($contact['network'] === NETWORK_DFRN) {
// logger("Consume DFRN messages", LOGGER_DEBUG);
// logger("dfrn-test");
// dfrn2::import($xml,$importer, $contact);
// return;
// }
// Test - remove before flight // Test - remove before flight
//if ($pass < 2) { //if ($pass < 2) {
@ -2398,6 +2406,8 @@ function item_is_remote_self($contact, &$datarray) {
} }
function local_delivery($importer,$data) { function local_delivery($importer,$data) {
// dfrn-Test
return dfrn2::import($data, $importer, $contact);
require_once('library/simplepie/simplepie.inc'); require_once('library/simplepie/simplepie.inc');

View File

@ -389,7 +389,11 @@ function ping_get_notifications($uid) {
// Replace the name with {0} but ensure to make that only once // Replace the name with {0} but ensure to make that only once
// The {0} is used later and prints the name in bold. // The {0} is used later and prints the name in bold.
$pos = strpos($notification["message"],$notification['name']); if ($notification['name'] != "")
$pos = strpos($notification["message"],$notification['name']);
else
$pos = false;
if ($pos !== false) if ($pos !== false)
$notification["message"] = substr_replace($notification["message"],"{0}",$pos,strlen($notification["name"])); $notification["message"] = substr_replace($notification["message"],"{0}",$pos,strlen($notification["name"]));