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