DFRN: Contact-id is now stored depending on the author/Some more bugfixes

This commit is contained in:
Michael Vogel 2016-02-04 12:51:34 +01:00
parent 5f6ba00408
commit 3a649047df
2 changed files with 41 additions and 38 deletions

View file

@ -1,16 +1,4 @@
<?php <?php
/*
require_once("include/Contact.php");
require_once("include/html2bbcode.php");
require_once("include/bbcode.php");
require_once("mod/share.php");
require_once("include/Photo.php");
require_once("include/Scrape.php");
require_once("include/follow.php");
require_once("include/api.php");
require_once("mod/proxy.php");
*/
require_once("include/enotify.php"); require_once("include/enotify.php");
require_once("include/threads.php"); require_once("include/threads.php");
require_once("include/socgraph.php"); require_once("include/socgraph.php");
@ -196,25 +184,37 @@ class dfrn2 {
unset($fields["id"]); unset($fields["id"]);
unset($fields["uid"]); unset($fields["uid"]);
unset($fields["avatar-date"]);
unset($fields["name-date"]);
unset($fields["uri-date"]);
// Update check for this field has to be done differently
$datefields = array("name-date", "uri-date");
foreach ($datefields AS $field)
if (strtotime($contact[$field]) > strtotime($r[0][$field]))
$update = true;
foreach ($fields AS $field => $data) foreach ($fields AS $field => $data)
if ($contact[$field] != $r[0][$field]) if ($contact[$field] != $r[0][$field]) {
logger("Difference for contact ".$contact["id"]." in field '".$field."'. Old value: '".$contact[$field]."', new value '".$r[0][$field]."'", LOGGER_DEBUG);
$update = true; $update = true;
}
if ($update) { if ($update) {
logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG); logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s',
`addr` = '%s', `keywords` = '%s', `bdyear` = '%s', `bd` = '%s' `addr` = '%s', `keywords` = '%s', `bdyear` = '%s', `bd` = '%s',
`avatar-date` = '%s', `name-date` = '%s', `uri-date` = '%s' `name-date` = '%s', `uri-date` = '%s'
WHERE `id` = %d AND `network` = '%s'", WHERE `id` = %d AND `network` = '%s'",
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]),
dbesc($contact["addr"]), dbesc($contact["keywords"]), dbesc($contact["bdyear"]), dbesc($contact["addr"]), dbesc($contact["keywords"]), dbesc($contact["bdyear"]),
dbesc($contact["bd"]), dbesc($contact["avatar-date"]), dbesc($contact["name-date"]), dbesc($contact["uri-date"]), dbesc($contact["bd"]), dbesc($contact["name-date"]), dbesc($contact["uri-date"]),
intval($contact["id"]), dbesc($contact["network"])); intval($contact["id"]), dbesc($contact["network"]));
} }
update_contact_avatar($author["avatar"], $importer["uid"], $contact["id"], ($contact["avatar-date"] != $r[0]["avatar-date"])); update_contact_avatar($author["avatar"], $importer["uid"], $contact["id"],
(strtotime($contact["avatar-date"]) > strtotime($r[0]["avatar-date"])));
$contact["generation"] = 2; $contact["generation"] = 2;
$contact["photo"] = $author["avatar"]; $contact["photo"] = $author["avatar"];
@ -301,6 +301,8 @@ class dfrn2 {
); );
notification($notif_params); notification($notif_params);
logger("Mail is processed, notification was sent.");
} }
private function process_suggestion($xpath, $suggestion, $importer) { private function process_suggestion($xpath, $suggestion, $importer) {
@ -638,13 +640,6 @@ class dfrn2 {
$item["owner-link"] = $owner["link"]; $item["owner-link"] = $owner["link"];
$item["owner-avatar"] = $owner["avatar"]; $item["owner-avatar"] = $owner["avatar"];
// At the moment we trust the importer array
//if ($header["contact-id"] != $owner["contact-id"])
// $item["contact-id"] = $owner["contact-id"];
if (($header["network"] != $owner["network"]) AND ($owner["network"] != ""))
$item["network"] = $owner["network"];
// fetch the author // fetch the author
$author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true); $author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true);
@ -652,13 +647,6 @@ class dfrn2 {
$item["author-link"] = $author["link"]; $item["author-link"] = $author["link"];
$item["author-avatar"] = $author["avatar"]; $item["author-avatar"] = $author["avatar"];
// At the moment we trust the importer array
//if ($header["contact-id"] != $author["contact-id"])
// $item["contact-id"] = $author["contact-id"];
if (($header["network"] != $author["network"]) AND ($author["network"] != ""))
$item["network"] = $author["network"];
$item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue; $item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue;
$item["created"] = $xpath->query("atom:published/text()", $entry)->item(0)->nodeValue; $item["created"] = $xpath->query("atom:published/text()", $entry)->item(0)->nodeValue;
@ -779,16 +767,31 @@ class dfrn2 {
$entrytype = self::get_entry_type($importer, $item); $entrytype = self::get_entry_type($importer, $item);
// Now assign the rest of the values that depend on the type of the message // Now assign the rest of the values that depend on the type of the message
if ($entrytype == DFRN_REPLY_RC) { if (in_array($entrytype, array(DFRN_REPLY, DFRN_REPLY_RC))) {
if (!isset($item["object-type"])) if (!isset($item["object-type"]))
$item["object-type"] = ACTIVITY_OBJ_COMMENT; $item["object-type"] = ACTIVITY_OBJ_COMMENT;
if ($item["contact-id"] != $owner["contact-id"])
$item["contact-id"] = $owner["contact-id"];
if (($item["network"] != $owner["network"]) AND ($owner["network"] != ""))
$item["network"] = $owner["network"];
if ($item["contact-id"] != $author["contact-id"])
$item["contact-id"] = $author["contact-id"];
if (($item["network"] != $author["network"]) AND ($author["network"] != ""))
$item["network"] = $author["network"];
}
if ($entrytype == DFRN_REPLY_RC) {
$item["type"] = "remote-comment"; $item["type"] = "remote-comment";
$item["wall"] = 1; $item["wall"] = 1;
} elseif ($entrytype == DFRN_REPLY) {
if (!isset($item["object-type"]))
$item["object-type"] = ACTIVITY_OBJ_COMMENT;
} else { } else {
// The Diaspora signature is only stored in replies
// Since this isn't a field in the item table this would create a bug when inserting this in the item table
unset($item["dsprsig"]);
if (!isset($item["object-type"])) if (!isset($item["object-type"]))
$item["object-type"] = ACTIVITY_OBJ_NOTE; $item["object-type"] = ACTIVITY_OBJ_NOTE;
@ -892,7 +895,7 @@ class dfrn2 {
if($posted_id) { if($posted_id) {
logger("Reply was stored with id ".$posted_id, LOGGER_DEBUG); logger("Reply from contact ".$item["contact-id"]." was stored with id ".$posted_id, LOGGER_DEBUG);
$item["id"] = $posted_id; $item["id"] = $posted_id;

View file

@ -17,7 +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('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');
@ -2424,7 +2424,7 @@ function item_is_remote_self($contact, &$datarray) {
function local_delivery($importer,$data) { function local_delivery($importer,$data) {
// dfrn-Test // dfrn-Test
//return dfrn2::import($data, $importer); return dfrn2::import($data, $importer);
require_once('library/simplepie/simplepie.inc'); require_once('library/simplepie/simplepie.inc');