X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDFRN.php;h=1ab4d8f9e4959592cf887e9f09f651989de53455;hb=3dfb0c2e7cc84dc7e43a975f44e8854b98d043bc;hp=31c12405f65aecd9c0bd9b3bf682663ab2aeff9c;hpb=7f3fb34c24e30b79d8c25f63dbb2c3c3da79e599;p=friendica.git diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 31c12405f6..1ab4d8f9e4 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -52,6 +52,46 @@ class DFRN const REPLY = 1; // Regular reply that is stored locally const REPLY_RC = 2; // Reply that will be relayed + /** + * @brief Generates an array of contact and user for DFRN imports + * + * This array contains not only the receiver but also the sender of the message. + * + * @param integer $cid Contact id + * @param integer $uid User id + * + * @return array importer + */ + public static function getImporter($cid, $uid = 0) + { + $condition = ['id' => $cid, 'blocked' => false, 'pending' => false]; + $contact = DBA::selectFirst('contact', [], $condition); + if (!DBA::isResult($contact)) { + return []; + } + + $contact['cpubkey'] = $contact['pubkey']; + $contact['cprvkey'] = $contact['prvkey']; + $contact['senderName'] = $contact['name']; + + if ($uid != 0) { + $condition = ['uid' => $uid, 'account_expired' => false, 'account_removed' => false]; + $user = DBA::selectFirst('user', [], $condition); + if (!DBA::isResult($user)) { + return []; + } + + $user['importer_uid'] = $user['uid']; + $user['uprvkey'] = $user['prvkey']; + } else { + $user = ['importer_uid' => 0, 'uprvkey' => '', 'timezone' => 'UTC', + 'nickname' => '', 'sprvkey' => '', 'spubkey' => '', + 'page-flags' => 0, 'account-type' => 0, 'prvnets' => 0]; + } + + return array_merge($contact, $user); + } + /** * @brief Generates the atom entries for delivery.php * @@ -1124,15 +1164,17 @@ class DFRN * @return int Deliver status. Negative values mean an error. * @todo Add array type-hint for $owner, $contact */ - public static function deliver($owner, $contact, $atom, $dissolve = false) + public static function deliver($owner, $contact, $atom, $dissolve = false, $legacy_transport = false) { $a = get_app(); // At first try the Diaspora transport layer - $ret = self::transmit($owner, $contact, $atom); - if ($ret >= 200) { - logger('Delivery via Diaspora transport layer was successful with status ' . $ret); - return $ret; + if (!$dissolve && !$legacy_transport) { + $ret = self::transmit($owner, $contact, $atom); + if ($ret >= 200) { + logger('Delivery via Diaspora transport layer was successful with status ' . $ret); + return $ret; + } } $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); @@ -1291,6 +1333,7 @@ class DFRN $key = openssl_random_pseudo_bytes(16); $data = self::aesEncrypt($postvars['data'], $key); break; + default: logger("rino: invalid requested version '$rino_remote_version'"); Contact::markForArchival($contact); @@ -1578,6 +1621,10 @@ class DFRN } } + if (empty($author['avatar'])) { + logger('Empty author: ' . $xml); + } + if (DBA::isResult($contact_old) && !$onlyfetch) { logger("Check if contact details for contact " . $contact_old["id"] . " (" . $contact_old["nick"] . ") have to be updated.", LOGGER_DEBUG); @@ -1707,6 +1754,10 @@ class DFRN // Update check for this field has to be done differently $datefields = ["name-date", "uri-date"]; foreach ($datefields as $field) { + // The date fields arrives as '2018-07-17T10:44:45Z' - the database return '2018-07-17 10:44:45' + // The fields have to be in the same format to be comparable, since strtotime does add timezones. + $contact[$field] = DateTimeFormat::utc($contact[$field]); + if (strtotime($contact[$field]) > strtotime($contact_old[$field])) { logger("Difference for contact " . $contact["id"] . " in field '" . $field . "'. New value: '" . $contact[$field] . "', old value '" . $contact_old[$field] . "'", LOGGER_DEBUG); $update = true; @@ -2204,6 +2255,11 @@ class DFRN if ($Blink && link_compare($Blink, System::baseUrl() . "/profile/" . $importer["nickname"])) { $author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]); + $item['id'] = $posted_id; + + $parent = Item::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => $importer["importer_uid"]]); + $item["parent"] = $parent['id']; + // send a notification notification( [ @@ -2354,8 +2410,11 @@ class DFRN break; case "enclosure": $enclosure = $href; - if (strlen($item["attach"])) { + + if (!empty($item["attach"])) { $item["attach"] .= ","; + } else { + $item["attach"] = ""; } $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '" title="' . $title . '"[/attach]'; @@ -2401,7 +2460,7 @@ class DFRN } // Fetch the owner - $owner = self::fetchauthor($xpath, $entry, $importer, "dfrn:owner", true); + $owner = self::fetchauthor($xpath, $entry, $importer, "dfrn:owner", true, $xml); $owner_unknown = (isset($owner["contact-unknown"]) && $owner["contact-unknown"]); @@ -2411,7 +2470,7 @@ class DFRN $item["owner-id"] = Contact::getIdForURL($owner["link"], 0); // fetch the author - $author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true); + $author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true, $xml); $item["author-name"] = $author["name"]; $item["author-link"] = $author["link"];