]> git.mxchange.org Git - friendica.git/commitdiff
DFRN payload is receivable via the Diaspora transport layer
authorMichael <heluecht@pirati.ca>
Fri, 23 Mar 2018 05:08:47 +0000 (05:08 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 23 Mar 2018 05:08:47 +0000 (05:08 +0000)
mod/dfrn_notify.php
mod/salmon.php

index db967290660a7e300bb4ae53516c701887fe1556..0743b214358df3dc560e69cd8d8b10cde5dcb001 100644 (file)
@@ -12,6 +12,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Protocol\DFRN;
+use Friendica\Protocol\Diaspora;
 
 require_once 'include/items.php';
 require_once 'include/event.php';
@@ -19,9 +20,52 @@ require_once 'include/event.php';
 function dfrn_notify_post(App $a) {
        logger(__function__, LOGGER_TRACE);
 
-       if (empty($_POST)) {
-               require_once 'mod/salmon.php';
-               salmon_post($a);
+       $postdata = file_get_contents('php://input');
+
+       if (empty($_POST) || !empty($postdata)) {
+               $data = json_decode($postdata);
+               if (is_object($data)) {
+                       $nick = defaults($a->argv, 1, '');
+                       $user = dba::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]);
+                       if (!DBM::is_result($user)) {
+                               System::httpExit(500);
+                       }
+                       $msg = Diaspora::decodeRaw($user, $postdata);
+
+                       // Check if the user has got this contact
+                       $cid = getIdForURL($msg['author'], $user['uid']);
+                       if (!$cid) {
+                               // Otherwise there should be a public contact
+                               $cid = getIdForURL($msg['author']);
+                               if (!$cid) {
+                                       logger('Contact not found for address ' . $msg['author']);
+                                       System::xmlExit(3, 'Contact not found');
+                               }
+                       }
+
+                       // We now have some contact, so we fetch it
+                       $importer = dba::fetch_first("SELECT *, `name` as `senderName`
+                                                       FROM `contact`
+                                                       WHERE NOT `blocked` AND `id` = ? LIMIT 1",
+                                                       $cid);
+
+                       // This should never fail
+                       if (!DBM::is_result($importer)) {
+                               logger('Contact not found for address ' . $msg['author']);
+                               System::xmlExit(3, 'Contact not found');
+                       }
+
+                       // Set the user id. This is important if this is a public contact
+                       $importer['uid']  = $user['uid'];
+                       $importer['importer_uid']  = $user['uid'];
+
+                       // Now we should be able to import it
+                       $ret = DFRN::import($msg['message'], $importer);
+                       System::xmlExit($ret, 'Processed');
+               } else {
+                       require_once 'mod/salmon.php';
+                       salmon_post($a, $postdata);
+               }
        }
 
        $dfrn_id      = ((x($_POST,'dfrn_id'))      ? notags(trim($_POST['dfrn_id']))   : '');
index 2b6014adf590b36d832130c53951396156dadb02..22da151cf8e1c93f44d3478fee2c1b0e23c6e129 100644 (file)
@@ -13,9 +13,11 @@ use Friendica\Util\Crypto;
 
 require_once 'include/items.php';
 
-function salmon_post(App $a) {
+function salmon_post(App $a, $xml = '') {
 
-       $xml = file_get_contents('php://input');
+       if (empty($xml)) {
+               $xml = file_get_contents('php://input');
+       }
 
        logger('new salmon ' . $xml, LOGGER_DATA);