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