]> git.mxchange.org Git - friendica.git/blobdiff - mod/dfrn_confirm.php
Renamed System::redirect() to $a->redirect()
[friendica.git] / mod / dfrn_confirm.php
index 41b5e0ef54f16587dae6e2935ad40916b801e519..3345bca61193e713c1f999bc33b5b49f017a9056 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Model\Group;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
+use Friendica\Protocol\ActivityPub;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -220,7 +221,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                         *
                         */
 
-                       $res = Network::post($dfrn_confirm, $params, null, $redirects, 120);
+                       $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
 
                        logger(' Confirm: received data: ' . $res, LOGGER_DATA);
 
@@ -335,10 +336,17 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                                intval($contact_id)
                        );
                } else {
+                       if ($network == Protocol::ACTIVITYPUB) {
+                               ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
+                               $pending = true;
+                       } else {
+                               $pending = false;
+                       }
+
                        // $network !== Protocol::DFRN
                        $network = defaults($contact, 'network', Protocol::OSTATUS);
 
-                       $arr = Probe::uri($contact['url']);
+                       $arr = Probe::uri($contact['url'], $network);
 
                        $notify  = defaults($contact, 'notify' , $arr['notify']);
                        $poll    = defaults($contact, 'poll'   , $arr['poll']);
@@ -348,7 +356,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                        $new_relation = $contact['rel'];
                        $writable = $contact['writable'];
 
-                       if ($network === Protocol::DIASPORA) {
+                       if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
                                if ($duplex) {
                                        $new_relation = Contact::FRIEND;
                                } else {
@@ -362,30 +370,12 @@ function dfrn_confirm_post(App $a, $handsfree = null)
 
                        DBA::delete('intro', ['id' => $intro_id]);
 
-                       $r = q("UPDATE `contact` SET `name-date` = '%s',
-                               `uri-date` = '%s',
-                               `addr` = '%s',
-                               `notify` = '%s',
-                               `poll` = '%s',
-                               `blocked` = 0,
-                               `pending` = 0,
-                               `network` = '%s',
-                               `writable` = %d,
-                               `hidden` = %d,
-                               `rel` = %d
-                               WHERE `id` = %d
-                       ",
-                               DBA::escape(DateTimeFormat::utcNow()),
-                               DBA::escape(DateTimeFormat::utcNow()),
-                               DBA::escape($addr),
-                               DBA::escape($notify),
-                               DBA::escape($poll),
-                               DBA::escape($network),
-                               intval($writable),
-                               intval($hidden),
-                               intval($new_relation),
-                               intval($contact_id)
-                       );
+                       $fields = ['name-date' => DateTimeFormat::utcNow(),
+                               'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
+                               'notify' => $notify, 'poll' => $poll, 'blocked' => false,
+                               'pending' => $pending, 'network' => $network,
+                               'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
+                       DBA::update('contact', $fields, ['id' => $contact_id]);
                }
 
                if (!DBA::isResult($r)) {
@@ -403,10 +393,14 @@ function dfrn_confirm_post(App $a, $handsfree = null)
 
                Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
 
+               if ($network == Protocol::ACTIVITYPUB && $duplex) {
+                       ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
+               }
+
                // Let's send our user to the contact editor in case they want to
                // do anything special with this new friend.
                if ($handsfree === null) {
-                       goaway(System::baseUrl() . '/contacts/' . intval($contact_id));
+                       $a->redirect('contact/' . intval($contact_id));
                } else {
                        return;
                }
@@ -610,7 +604,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                                        'to_name'      => $combined['username'],
                                        'to_email'     => $combined['email'],
                                        'uid'          => $combined['uid'],
-                                       'link'         => System::baseUrl() . '/contacts/' . $dfrn_record,
+                                       'link'         => System::baseUrl() . '/contact/' . $dfrn_record,
                                        'source_name'  => ((strlen(stripslashes($combined['name']))) ? stripslashes($combined['name']) : L10n::t('[Name Withheld]')),
                                        'source_link'  => $combined['url'],
                                        'source_photo' => $combined['photo'],
@@ -626,6 +620,6 @@ function dfrn_confirm_post(App $a, $handsfree = null)
        }
 
        // somebody arrived here by mistake or they are fishing. Send them to the homepage.
-       goaway(System::baseUrl());
+       $a->redirect();
        // NOTREACHED
 }