]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_request.php
Use new Model methods for groups
[friendica.git] / mod / dfrn_request.php
1 <?php
2 /**
3  * @file mod/dfrn_request.php
4  * @brief Module: dfrn_request
5  *
6  * Purpose: Handles communication associated with the issuance of
7  * friend requests.
8  *
9  * @see PDF with dfrn specs: https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
10  *    You also find a graphic which describes the confirmation process at
11  *    https://github.com/friendica/friendica/blob/master/spec/dfrn2_contact_request.png
12  */
13 use Friendica\App;
14 use Friendica\Core\Config;
15 use Friendica\Core\PConfig;
16 use Friendica\Core\System;
17 use Friendica\Database\DBM;
18 use Friendica\Model\Contact;
19 use Friendica\Model\Group;
20 use Friendica\Model\User;
21 use Friendica\Network\Probe;
22
23 require_once 'include/enotify.php';
24 require_once 'include/group.php';
25
26 function dfrn_request_init(App $a)
27 {
28         if ($a->argc > 1)
29                 $which = $a->argv[1];
30
31         profile_load($a, $which);
32         return;
33 }
34
35
36 /**
37  * Function: dfrn_request_post
38  *
39  * Purpose:
40  * Handles multiple scenarios.
41  *
42  * Scenario 1:
43  * Clicking 'submit' on a friend request page.
44  *
45  * Scenario 2:
46  * Following Scenario 1, we are brought back to our home site
47  * in order to link our friend request with our own server cell.
48  * After logging in, we click 'submit' to approve the linkage.
49  *
50  */
51 function dfrn_request_post(App $a) {
52
53         if(($a->argc != 2) || (! count($a->profile))) {
54                 logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile));
55                 return;
56         }
57
58
59         if(x($_POST, 'cancel')) {
60                 goaway(System::baseUrl());
61         }
62
63
64         /*
65          *
66          * Scenario 2: We've introduced ourself to another cell, then have been returned to our own cell
67          * to confirm the request, and then we've clicked submit (perhaps after logging in).
68          * That brings us here:
69          *
70          */
71
72         if((x($_POST,'localconfirm')) && ($_POST['localconfirm'] == 1)) {
73
74                 /*
75                  * Ensure this is a valid request
76                  */
77
78                 if(local_user() && ($a->user['nickname'] == $a->argv[1]) && (x($_POST,'dfrn_url'))) {
79
80
81                         $dfrn_url    = notags(trim($_POST['dfrn_url']));
82                         $aes_allow   = (((x($_POST,'aes_allow')) && ($_POST['aes_allow'] == 1)) ? 1 : 0);
83                         $confirm_key = ((x($_POST,'confirm_key')) ? $_POST['confirm_key'] : "");
84                         $hidden = ((x($_POST,'hidden-contact')) ? intval($_POST['hidden-contact']) : 0);
85                         $contact_record = null;
86                         $blocked = 1;
87                         $pending = 1;
88
89                         if(x($dfrn_url)) {
90
91                                 /*
92                                  * Lookup the contact based on their URL (which is the only unique thing we have at the moment)
93                                  */
94
95                                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1",
96                                         intval(local_user()),
97                                         dbesc(normalise_link($dfrn_url))
98                                 );
99
100                                 if (DBM::is_result($r)) {
101                                         if(strlen($r[0]['dfrn-id'])) {
102
103                                                 /*
104                                                  * We don't need to be here. It has already happened.
105                                                  */
106
107                                                 notice( t("This introduction has already been accepted.") . EOL );
108                                                 return;
109                                         }
110                                         else
111                                                 $contact_record = $r[0];
112                                 }
113
114                                 if(is_array($contact_record)) {
115                                         $r = q("UPDATE `contact` SET `ret-aes` = %d, hidden = %d WHERE `id` = %d",
116                                                 intval($aes_allow),
117                                                 intval($hidden),
118                                                 intval($contact_record['id'])
119                                         );
120                                 }
121                                 else {
122
123                                         /*
124                                          * Scrape the other site's profile page to pick up the dfrn links, key, fn, and photo
125                                          */
126
127                                         $parms = Probe::profile($dfrn_url);
128
129                                         if (! count($parms)) {
130                                                 notice( t('Profile location is not valid or does not contain profile information.') . EOL );
131                                                 return;
132                                         }
133                                         else {
134                                                 if (! x($parms,'fn')) {
135                                                         notice( t('Warning: profile location has no identifiable owner name.') . EOL );
136                                                 }
137                                                 if (! x($parms,'photo')) {
138                                                         notice( t('Warning: profile location has no profile photo.') . EOL );
139                                                 }
140                                                 $invalid = Probe::validDfrn($parms);
141                                                 if ($invalid) {
142                                                         notice( sprintf( tt("%d required parameter was not found at the given location",
143                                                                                                 "%d required parameters were not found at the given location",
144                                                                                                 $invalid), $invalid) . EOL );
145                                                         return;
146                                                 }
147                                         }
148
149                                         $dfrn_request = $parms['dfrn-request'];
150
151                                         $photo = $parms["photo"];
152
153                                         // Escape the entire array
154                                         DBM::esc_array($parms);
155
156                                         /*
157                                          * Create a contact record on our site for the other person
158                                          */
159
160                                         $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `nurl`, `addr`, `name`, `nick`, `photo`, `site-pubkey`,
161                                                 `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`, `hidden`, `blocked`, `pending`)
162                                                 VALUES ( %d, '%s', '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d)",
163                                                 intval(local_user()),
164                                                 datetime_convert(),
165                                                 dbesc($dfrn_url),
166                                                 dbesc(normalise_link($dfrn_url)),
167                                                 $parms['addr'],
168                                                 $parms['fn'],
169                                                 $parms['nick'],
170                                                 $parms['photo'],
171                                                 $parms['key'],
172                                                 $parms['dfrn-request'],
173                                                 $parms['dfrn-confirm'],
174                                                 $parms['dfrn-notify'],
175                                                 $parms['dfrn-poll'],
176                                                 $parms['dfrn-poco'],
177                                                 dbesc(NETWORK_DFRN),
178                                                 intval($aes_allow),
179                                                 intval($hidden),
180                                                 intval($blocked),
181                                                 intval($pending)
182                                         );
183                                 }
184
185                                 if ($r) {
186                                         info( t("Introduction complete.") . EOL);
187                                 }
188
189                                 $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `site-pubkey` = '%s' LIMIT 1",
190                                         intval(local_user()),
191                                         dbesc($dfrn_url),
192                                         $parms['key'] // this was already escaped
193                                 );
194                                 if (DBM::is_result($r)) {
195                                         Group::addMember(User::getDefaultGroup($uid, $r[0]["network"]), $r[0]['id']);
196
197                                         if (isset($photo)) {
198                                                 Contact::updateAvatar($photo, local_user(), $r[0]["id"], true);
199                                         }
200
201                                         $forwardurl = System::baseUrl()."/contacts/".$r[0]['id'];
202                                 } else {
203                                         $forwardurl = System::baseUrl()."/contacts";
204                                 }
205
206                                 /*
207                                  * Allow the blocked remote notification to complete
208                                  */
209
210                                 if (is_array($contact_record)) {
211                                         $dfrn_request = $contact_record['request'];
212                                 }
213
214                                 if (strlen($dfrn_request) && strlen($confirm_key)) {
215                                         $s = fetch_url($dfrn_request . '?confirm_key=' . $confirm_key);
216                                 }
217
218                                 // (ignore reply, nothing we can do it failed)
219
220                                 // Old: goaway(zrl($dfrn_url));
221                                 goaway($forwardurl);
222                                 return; // NOTREACHED
223
224                         }
225
226                 }
227
228                 // invalid/bogus request
229
230                 notice( t('Unrecoverable protocol error.') . EOL );
231                 goaway(System::baseUrl());
232                 return; // NOTREACHED
233         }
234
235         /*
236          * Otherwise:
237          *
238          * Scenario 1:
239          * We are the requestee. A person from a remote cell has made an introduction
240          * on our profile web page and clicked submit. We will use their DFRN-URL to
241          * figure out how to contact their cell.
242          *
243          * Scrape the originating DFRN-URL for everything we need. Create a contact record
244          * and an introduction to show our user next time he/she logs in.
245          * Finally redirect back to the requestor so that their site can record the request.
246          * If our user (the requestee) later confirms this request, a record of it will need
247          * to exist on the requestor's cell in order for the confirmation process to complete..
248          *
249          * It's possible that neither the requestor or the requestee are logged in at the moment,
250          * and the requestor does not yet have any credentials to the requestee profile.
251          *
252          * Who is the requestee? We've already loaded their profile which means their nickname should be
253          * in $a->argv[1] and we should have their complete info in $a->profile.
254          *
255          */
256
257         if(! (is_array($a->profile) && count($a->profile))) {
258                 notice( t('Profile unavailable.') . EOL);
259                 return;
260         }
261
262         $nickname       = $a->profile['nickname'];
263         $notify_flags   = $a->profile['notify-flags'];
264         $uid            = $a->profile['uid'];
265         $maxreq         = intval($a->profile['maxreq']);
266         $contact_record = null;
267         $failed         = false;
268         $parms          = null;
269         $blocked = 1;
270         $pending = 1;
271
272
273         if( x($_POST,'dfrn_url')) {
274
275                 /*
276                  * Block friend request spam
277                  */
278
279                 if($maxreq) {
280                         $r = q("SELECT * FROM `intro` WHERE `datetime` > '%s' AND `uid` = %d",
281                                 dbesc(datetime_convert('UTC','UTC','now - 24 hours')),
282                                 intval($uid)
283                         );
284                         if (DBM::is_result($r) && count($r) > $maxreq) {
285                                 notice( sprintf( t('%s has received too many connection requests today.'),  $a->profile['name']) . EOL);
286                                 notice( t('Spam protection measures have been invoked.') . EOL);
287                                 notice( t('Friends are advised to please try again in 24 hours.') . EOL);
288                                 return;
289                         }
290                 }
291
292                 /*
293                  *
294                  * Cleanup old introductions that remain blocked.
295                  * Also remove the contact record, but only if there is no existing relationship
296                  */
297
298                 $r = q("SELECT `intro`.*, `intro`.`id` AS `iid`, `contact`.`id` AS `cid`, `contact`.`rel`
299                         FROM `intro` LEFT JOIN `contact` on `intro`.`contact-id` = `contact`.`id`
300                         WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0
301                         AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE "
302                 );
303                 if (DBM::is_result($r)) {
304                         foreach ($r as $rr) {
305                                 if(! $rr['rel']) {
306                                         q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`",
307                                                 intval($rr['cid'])
308                                         );
309                                 }
310                                 q("DELETE FROM `intro` WHERE `id` = %d",
311                                         intval($rr['iid'])
312                                 );
313                         }
314                 }
315
316                 $real_name = (x($_POST,'realname') ? notags(trim($_POST['realname'])) : '');
317
318                 $url = trim($_POST['dfrn_url']);
319                 if(! strlen($url)) {
320                         notice( t("Invalid locator") . EOL );
321                         return;
322                 }
323
324                 $hcard = '';
325
326                 // Detect the network
327                 $data = Probe::uri($url);
328                 $network = $data["network"];
329
330                 // Canonicalise email-style profile locator
331                 $url = Probe::webfingerDfrn($url,$hcard);
332
333                 if (substr($url,0,5) === 'stat:') {
334
335                         // Every time we detect the remote subscription we define this as OStatus.
336                         // We do this even if it is not OStatus.
337                         // we only need to pass this through another section of the code.
338                         if ($network != NETWORK_DIASPORA) {
339                                 $network = NETWORK_OSTATUS;
340                         }
341
342                         $url = substr($url,5);
343                 } else {
344                         $network = NETWORK_DFRN;
345                 }
346
347                 logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG);
348
349                 if($network === NETWORK_DFRN) {
350                         $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1",
351                                 intval($uid),
352                                 dbesc($url)
353                         );
354
355                         if (DBM::is_result($ret)) {
356                                 if(strlen($ret[0]['issued-id'])) {
357                                         notice( t('You have already introduced yourself here.') . EOL );
358                                         return;
359                                 }
360                                 elseif($ret[0]['rel'] == CONTACT_IS_FRIEND) {
361                                         notice( sprintf( t('Apparently you are already friends with %s.'), $a->profile['name']) . EOL);
362                                         return;
363                                 }
364                                 else {
365                                         $contact_record = $ret[0];
366                                         $parms = array('dfrn-request' => $ret[0]['request']);
367                                 }
368                         }
369
370                         $issued_id = random_string();
371
372                         if(is_array($contact_record)) {
373                                 // There is a contact record but no issued-id, so this
374                                 // is a reciprocal introduction from a known contact
375                                 $r = q("UPDATE `contact` SET `issued-id` = '%s' WHERE `id` = %d",
376                                         dbesc($issued_id),
377                                         intval($contact_record['id'])
378                                 );
379                         }
380                         else {
381                                 if (! validate_url($url)) {
382                                         notice( t('Invalid profile URL.') . EOL);
383                                         goaway(System::baseUrl() . '/' . $a->cmd);
384                                         return; // NOTREACHED
385                                 }
386
387                                 if (! allowed_url($url)) {
388                                         notice( t('Disallowed profile URL.') . EOL);
389                                         goaway(System::baseUrl() . '/' . $a->cmd);
390                                         return; // NOTREACHED
391                                 }
392
393                                 if (blocked_url($url)) {
394                                         notice( t('Blocked domain') . EOL);
395                                         goaway(System::baseUrl() . '/' . $a->cmd);
396                                         return; // NOTREACHED
397                                 }
398
399                                 $parms = Probe::profile(($hcard) ? $hcard : $url);
400
401                                 if (! count($parms)) {
402                                         notice( t('Profile location is not valid or does not contain profile information.') . EOL );
403                                         goaway(System::baseUrl() . '/' . $a->cmd);
404                                 }
405                                 else {
406                                         if (! x($parms,'fn')) {
407                                                 notice( t('Warning: profile location has no identifiable owner name.') . EOL );
408                                         }
409                                         if (! x($parms,'photo')) {
410                                                 notice( t('Warning: profile location has no profile photo.') . EOL );
411                                         }
412                                         $invalid = Probe::validDfrn($parms);
413                                         if ($invalid) {
414                                                 notice( sprintf( tt("%d required parameter was not found at the given location",
415                                                                                         "%d required parameters were not found at the given location",
416                                                                                         $invalid), $invalid) . EOL );
417
418                                                 return;
419                                         }
420                                 }
421
422
423                                 $parms['url'] = $url;
424                                 $parms['issued-id'] = $issued_id;
425                                 $photo = $parms["photo"];
426
427                                 DBM::esc_array($parms);
428                                 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`,
429                                         `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `blocked`, `pending` )
430                                         VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
431                                         intval($uid),
432                                         dbesc(datetime_convert()),
433                                         $parms['url'],
434                                         dbesc(normalise_link($url)),
435                                         $parms['addr'],
436                                         $parms['fn'],
437                                         $parms['nick'],
438                                         $parms['issued-id'],
439                                         $parms['photo'],
440                                         $parms['key'],
441                                         $parms['dfrn-request'],
442                                         $parms['dfrn-confirm'],
443                                         $parms['dfrn-notify'],
444                                         $parms['dfrn-poll'],
445                                         $parms['dfrn-poco'],
446                                         dbesc(NETWORK_DFRN),
447                                         intval($blocked),
448                                         intval($pending)
449                                 );
450
451                                 // find the contact record we just created
452                                 if ($r) {
453                                         $r = q("SELECT `id` FROM `contact`
454                                                 WHERE `uid` = %d AND `url` = '%s' AND `issued-id` = '%s' LIMIT 1",
455                                                 intval($uid),
456                                                 $parms['url'],
457                                                 $parms['issued-id']
458                                         );
459                                         if (DBM::is_result($r)) {
460                                                 $contact_record = $r[0];
461                                                 Contact::updateAvatar($photo, $uid, $contact_record["id"], true);
462                                         }
463                                 }
464
465                         }
466                         if ($r === false) {
467                                 notice( t('Failed to update contact record.') . EOL );
468                                 return;
469                         }
470
471                         $hash = random_string() . (string) time();   // Generate a confirm_key
472
473                         if (is_array($contact_record)) {
474                                 $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
475                                         VALUES ( %d, %d, 1, %d, '%s', '%s', '%s' )",
476                                         intval($uid),
477                                         intval($contact_record['id']),
478                                         ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0),
479                                         dbesc(notags(trim($_POST['dfrn-request-message']))),
480                                         dbesc($hash),
481                                         dbesc(datetime_convert())
482                                 );
483                         }
484
485                         // This notice will only be seen by the requestor if the requestor and requestee are on the same server.
486
487                         if (! $failed) {
488                                 info( t('Your introduction has been sent.') . EOL );
489                         }
490
491                         // "Homecoming" - send the requestor back to their site to record the introduction.
492
493                         $dfrn_url = bin2hex(System::baseUrl() . '/profile/' . $nickname);
494                         $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0);
495
496                         goaway($parms['dfrn-request'] . "?dfrn_url=$dfrn_url"
497                                 . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
498                                 . '&confirm_key='  . $hash
499                                 . (($aes_allow) ? "&aes_allow=1" : "")
500                         );
501                         // NOTREACHED
502                         // END $network === NETWORK_DFRN
503                 } elseif (($network != NETWORK_PHANTOM) && ($url != "")) {
504
505                         /*
506                          *
507                          * Substitute our user's feed URL into $url template
508                          * Send the subscriber home to subscribe
509                          *
510                          */
511
512                         // Diaspora needs the uri in the format user@domain.tld
513                         // Diaspora will support the remote subscription in a future version
514                         if ($network == NETWORK_DIASPORA) {
515                                 $uri = $nickname.'@'.$a->get_hostname();
516
517                                 if ($a->get_path())
518                                         $uri .= '/'.$a->get_path();
519
520                                 $uri = urlencode($uri);
521                         } else {
522                                 $uri = System::baseUrl().'/profile/'.$nickname;
523                         }
524
525                         $url = str_replace('{uri}', $uri, $url);
526                         goaway($url);
527                         // NOTREACHED
528                         // END $network != NETWORK_PHANTOM
529                 } else {
530                         notice(t("Remote subscription can't be done for your network. Please subscribe directly on your system.").EOL);
531                         return;
532                 }
533
534         }       return;
535 }
536
537
538 function dfrn_request_content(App $a) {
539
540         if (($a->argc != 2) || (! count($a->profile))) {
541                 return "";
542         }
543
544
545         // "Homecoming". Make sure we're logged in to this site as the correct user. Then offer a confirm button
546         // to send us to the post section to record the introduction.
547
548         if (x($_GET,'dfrn_url')) {
549
550                 if (! local_user()) {
551                         info( t("Please login to confirm introduction.") . EOL );
552                         /* setup the return URL to come back to this page if they use openid */
553                         $_SESSION['return_url'] = $a->query_string;
554                         return login();
555                 }
556
557                 // Edge case, but can easily happen in the wild. This person is authenticated,
558                 // but not as the person who needs to deal with this request.
559
560                 if ($a->user['nickname'] != $a->argv[1]) {
561                         notice( t("Incorrect identity currently logged in. Please login to <strong>this</strong> profile.") . EOL);
562                         return login();
563                 }
564
565                 $dfrn_url = notags(trim(hex2bin($_GET['dfrn_url'])));
566                 $aes_allow = (((x($_GET,'aes_allow')) && ($_GET['aes_allow'] == 1)) ? 1 : 0);
567                 $confirm_key = (x($_GET,'confirm_key') ? $_GET['confirm_key'] : "");
568
569                 // Checking fastlane for validity
570                 if (x($_SESSION, "fastlane") && (normalise_link($_SESSION["fastlane"]) == normalise_link($dfrn_url))) {
571                         $_POST["dfrn_url"] = $dfrn_url;
572                         $_POST["confirm_key"] = $confirm_key;
573                         $_POST["localconfirm"] = 1;
574                         $_POST["hidden-contact"] = 0;
575                         $_POST["submit"] = t('Confirm');
576
577                         dfrn_request_post($a);
578
579                         killme();
580                         return; // NOTREACHED
581                 }
582
583                 $tpl = get_markup_template("dfrn_req_confirm.tpl");
584                 $o  = replace_macros($tpl,array(
585                         '$dfrn_url' => $dfrn_url,
586                         '$aes_allow' => (($aes_allow) ? '<input type="hidden" name="aes_allow" value="1" />' : "" ),
587                         '$hidethem' => t('Hide this contact'),
588                         '$hidechecked' => '',
589                         '$confirm_key' => $confirm_key,
590                         '$welcome' => sprintf( t('Welcome home %s.'), $a->user['username']),
591                         '$please' => sprintf( t('Please confirm your introduction/connection request to %s.'), $dfrn_url),
592                         '$submit' => t('Confirm'),
593                         '$uid' => $_SESSION['uid'],
594                         '$nickname' => $a->user['nickname'],
595                         'dfrn_rawurl' => $_GET['dfrn_url']
596                         ));
597                 return $o;
598
599         }
600         elseif((x($_GET,'confirm_key')) && strlen($_GET['confirm_key'])) {
601
602                 // we are the requestee and it is now safe to send our user their introduction,
603                 // We could just unblock it, but first we have to jump through a few hoops to
604                 // send an email, or even to find out if we need to send an email.
605
606                 $intro = q("SELECT * FROM `intro` WHERE `hash` = '%s' LIMIT 1",
607                         dbesc($_GET['confirm_key'])
608                 );
609
610                 if (DBM::is_result($intro)) {
611
612                         $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
613                                 WHERE `contact`.`id` = %d LIMIT 1",
614                                 intval($intro[0]['contact-id'])
615                         );
616
617                         $auto_confirm = false;
618
619                         if (DBM::is_result($r)) {
620                                 if(($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP))
621                                         $auto_confirm = true;
622
623                                 if(! $auto_confirm) {
624
625                                         notification(array(
626                                                 'type'         => NOTIFY_INTRO,
627                                                 'notify_flags' => $r[0]['notify-flags'],
628                                                 'language'     => $r[0]['language'],
629                                                 'to_name'      => $r[0]['username'],
630                                                 'to_email'     => $r[0]['email'],
631                                                 'uid'          => $r[0]['uid'],
632                                                 'link'         => System::baseUrl() . '/notifications/intros',
633                                                 'source_name'  => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : t('[Name Withheld]')),
634                                                 'source_link'  => $r[0]['url'],
635                                                 'source_photo' => $r[0]['photo'],
636                                                 'verb'         => ACTIVITY_REQ_FRIEND,
637                                                 'otype'        => 'intro'
638                                         ));
639                                 }
640
641                                 if($auto_confirm) {
642                                         require_once 'mod/dfrn_confirm.php';
643                                         $handsfree = array(
644                                                 'uid'      => $r[0]['uid'],
645                                                 'node'     => $r[0]['nickname'],
646                                                 'dfrn_id'  => $r[0]['issued-id'],
647                                                 'intro_id' => $intro[0]['id'],
648                                                 'duplex'   => (($r[0]['page-flags'] == PAGE_FREELOVE) ? 1 : 0),
649                                                 'activity' => intval(PConfig::get($r[0]['uid'],'system','post_newfriend'))
650                                         );
651                                         dfrn_confirm_post($a,$handsfree);
652                                 }
653
654                         }
655
656                         if(! $auto_confirm) {
657
658                                 // If we are auto_confirming, this record will have already been nuked
659                                 // in dfrn_confirm_post()
660
661                                 $r = q("UPDATE `intro` SET `blocked` = 0 WHERE `hash` = '%s'",
662                                         dbesc($_GET['confirm_key'])
663                                 );
664                         }
665                 }
666
667                 killme();
668                 return; // NOTREACHED
669         }
670         else {
671
672                 /*
673                  * Normal web request. Display our user's introduction form.
674                  */
675
676                 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
677                         if(! Config::get('system','local_block')) {
678                                 notice( t('Public access denied.') . EOL);
679                                 return;
680                         }
681                 }
682
683
684                 /*
685                  * Try to auto-fill the profile address
686                  */
687
688                 // At first look if an address was provided
689                 // Otherwise take the local address
690                 if (x($_GET,'addr') && ($_GET['addr'] != "")) {
691                         $myaddr = hex2bin($_GET['addr']);
692                 } elseif (x($_GET,'address') && ($_GET['address'] != "")) {
693                         $myaddr = $_GET['address'];
694                 } elseif (local_user()) {
695                         if (strlen($a->path)) {
696                                 $myaddr = System::baseUrl() . '/profile/' . $a->user['nickname'];
697                         } else {
698                                 $myaddr = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(),'://') + 3 );
699                         }
700                 } else {
701                         // last, try a zrl
702                         $myaddr = get_my_url();
703                 }
704
705                 $target_addr = $a->profile['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(),'://') + 3 );
706
707
708                 /*
709                  *
710                  * The auto_request form only has the profile address
711                  * because nobody is going to read the comments and
712                  * it doesn't matter if they know you or not.
713                  *
714                  */
715
716                 if ($a->profile['page-flags'] == PAGE_NORMAL) {
717                         $tpl = get_markup_template('dfrn_request.tpl');
718                 } else {
719                         $tpl = get_markup_template('auto_request.tpl');
720                 }
721
722                 $page_desc = t("Please enter your 'Identity Address' from one of the following supported communications networks:");
723
724                 $invite_desc = sprintf(
725                         t('If you are not yet a member of the free social web, <a href="%s/siteinfo">follow this link to find a public Friendica site and join us today</a>.'),
726                         get_server()
727                 );
728
729                 $o = replace_macros($tpl,array(
730                         '$header' => t('Friend/Connection Request'),
731                         '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@gnusocial.de'),
732                         '$pls_answer' => t('Please answer the following:'),
733                         '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$a->profile['name']), false, '', array(t('No'), t('Yes'))),
734                         /*'$does_know' => sprintf( t('Does %s know you?'),$a->profile['name']),
735                         '$yes' => t('Yes'),
736                         '$no' => t('No'), */
737                         '$add_note' => t('Add a personal note:'),
738                         '$page_desc' => $page_desc,
739                         '$friendica' => t('Friendica'),
740                         '$statusnet' => t('GNU Social (Pleroma, Mastodon)'),
741                         '$diaspora' => t('Diaspora (Socialhome, Hubzilla)'),
742                         '$diasnote' => sprintf (t(' - please do not use this form.  Instead, enter %s into your Diaspora search bar.'),$target_addr),
743                         '$your_address' => t('Your Identity Address:'),
744                         '$invite_desc' => $invite_desc,
745                         '$submit' => t('Submit Request'),
746                         '$cancel' => t('Cancel'),
747                         '$nickname' => $a->argv[1],
748                         '$name' => $a->profile['name'],
749                         '$myaddr' => $myaddr
750                 ));
751                 return $o;
752         }
753
754         return; // Somebody is fishing.
755 }