]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_request.php
Move Composer autoload require out of boot.php
[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
15 use Friendica\App;
16 use Friendica\Core\Config;
17 use Friendica\Core\L10n;
18 use Friendica\Core\Logger;
19 use Friendica\Core\Protocol;
20 use Friendica\Core\Renderer;
21 use Friendica\Core\System;
22 use Friendica\Database\DBA;
23 use Friendica\Model\Contact;
24 use Friendica\Model\Group;
25 use Friendica\Model\Profile;
26 use Friendica\Model\User;
27 use Friendica\Module\Login;
28 use Friendica\Network\Probe;
29 use Friendica\Util\DateTimeFormat;
30 use Friendica\Util\Network;
31 use Friendica\Util\Strings;
32
33 function dfrn_request_init(App $a)
34 {
35         if ($a->argc > 1) {
36                 $which = $a->argv[1];
37         }
38
39         Profile::load($a, $which);
40         return;
41 }
42
43 /**
44  * Function: dfrn_request_post
45  *
46  * Purpose:
47  * Handles multiple scenarios.
48  *
49  * Scenario 1:
50  * Clicking 'submit' on a friend request page.
51  *
52  * Scenario 2:
53  * Following Scenario 1, we are brought back to our home site
54  * in order to link our friend request with our own server cell.
55  * After logging in, we click 'submit' to approve the linkage.
56  *
57  */
58 function dfrn_request_post(App $a)
59 {
60         if (($a->argc != 2) || (!count($a->profile))) {
61                 Logger::log('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile));
62                 return;
63         }
64
65         if (!empty($_POST['cancel'])) {
66                 $a->internalRedirect();
67         }
68
69         /*
70          * Scenario 2: We've introduced ourself to another cell, then have been returned to our own cell
71          * to confirm the request, and then we've clicked submit (perhaps after logging in).
72          * That brings us here:
73          */
74         if (!empty($_POST['localconfirm']) && ($_POST['localconfirm'] == 1)) {
75                 // Ensure this is a valid request
76                 if (local_user() && ($a->user['nickname'] == $a->argv[1]) && !empty($_POST['dfrn_url'])) {
77                         $dfrn_url    = Strings::escapeTags(trim($_POST['dfrn_url']));
78                         $aes_allow   = !empty($_POST['aes_allow']);
79                         $confirm_key = defaults($_POST, 'confirm_key', "");
80                         $hidden      = (!empty($_POST['hidden-contact']) ? intval($_POST['hidden-contact']) : 0);
81                         $contact_record = null;
82                         $blocked     = 1;
83                         $pending     = 1;
84
85                         if (!empty($dfrn_url)) {
86                                 // Lookup the contact based on their URL (which is the only unique thing we have at the moment)
87                                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1",
88                                         intval(local_user()),
89                                         DBA::escape(Strings::normaliseLink($dfrn_url))
90                                 );
91
92                                 if (DBA::isResult($r)) {
93                                         if (strlen($r[0]['dfrn-id'])) {
94                                                 // We don't need to be here. It has already happened.
95                                                 notice(L10n::t("This introduction has already been accepted.") . EOL);
96                                                 return;
97                                         } else {
98                                                 $contact_record = $r[0];
99                                         }
100                                 }
101
102                                 if (is_array($contact_record)) {
103                                         $r = q("UPDATE `contact` SET `ret-aes` = %d, hidden = %d WHERE `id` = %d",
104                                                 intval($aes_allow),
105                                                 intval($hidden),
106                                                 intval($contact_record['id'])
107                                         );
108                                 } else {
109                                         // Scrape the other site's profile page to pick up the dfrn links, key, fn, and photo
110                                         $parms = Probe::profile($dfrn_url);
111
112                                         if (!count($parms)) {
113                                                 notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL);
114                                                 return;
115                                         } else {
116                                                 if (empty($parms['fn'])) {
117                                                         notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL);
118                                                 }
119                                                 if (empty($parms['photo'])) {
120                                                         notice(L10n::t('Warning: profile location has no profile photo.') . EOL);
121                                                 }
122                                                 $invalid = Probe::validDfrn($parms);
123                                                 if ($invalid) {
124                                                         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);
125                                                         return;
126                                                 }
127                                         }
128
129                                         $dfrn_request = $parms['dfrn-request'];
130
131                                         $photo = $parms["photo"];
132
133                                         // Escape the entire array
134                                         DBA::escapeArray($parms);
135
136                                         // Create a contact record on our site for the other person
137                                         $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `nurl`, `addr`, `name`, `nick`, `photo`, `site-pubkey`,
138                                                 `request`, `confirm`, `notify`, `poll`, `network`, `aes_allow`, `hidden`, `blocked`, `pending`)
139                                                 VALUES ( %d, '%s', '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d)",
140                                                 intval(local_user()),
141                                                 DateTimeFormat::utcNow(),
142                                                 DBA::escape($dfrn_url),
143                                                 DBA::escape(Strings::normaliseLink($dfrn_url)),
144                                                 $parms['addr'],
145                                                 $parms['fn'],
146                                                 $parms['nick'],
147                                                 $parms['photo'],
148                                                 $parms['key'],
149                                                 $parms['dfrn-request'],
150                                                 $parms['dfrn-confirm'],
151                                                 $parms['dfrn-notify'],
152                                                 $parms['dfrn-poll'],
153                                                 DBA::escape(Protocol::DFRN),
154                                                 intval($aes_allow),
155                                                 intval($hidden),
156                                                 intval($blocked),
157                                                 intval($pending)
158                                         );
159                                 }
160
161                                 if ($r) {
162                                         info(L10n::t("Introduction complete.") . EOL);
163                                 }
164
165                                 $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `site-pubkey` = '%s' LIMIT 1",
166                                         intval(local_user()),
167                                         DBA::escape($dfrn_url),
168                                         $parms['key'] // this was already escaped
169                                 );
170                                 if (DBA::isResult($r)) {
171                                         Group::addMember(User::getDefaultGroup(local_user(), $r[0]["network"]), $r[0]['id']);
172
173                                         if (isset($photo)) {
174                                                 Contact::updateAvatar($photo, local_user(), $r[0]["id"], true);
175                                         }
176
177                                         $forward_path = "contact/" . $r[0]['id'];
178                                 } else {
179                                         $forward_path = "contact";
180                                 }
181
182                                 // Allow the blocked remote notification to complete
183                                 if (is_array($contact_record)) {
184                                         $dfrn_request = $contact_record['request'];
185                                 }
186
187                                 if (strlen($dfrn_request) && strlen($confirm_key)) {
188                                         $s = Network::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key);
189                                 }
190
191                                 // (ignore reply, nothing we can do it failed)
192                                 $a->internalRedirect($forward_path);
193                                 return; // NOTREACHED
194                         }
195                 }
196
197                 // invalid/bogus request
198                 notice(L10n::t('Unrecoverable protocol error.') . EOL);
199                 $a->internalRedirect();
200                 return; // NOTREACHED
201         }
202
203         /*
204          * Otherwise:
205          *
206          * Scenario 1:
207          * We are the requestee. A person from a remote cell has made an introduction
208          * on our profile web page and clicked submit. We will use their DFRN-URL to
209          * figure out how to contact their cell.
210          *
211          * Scrape the originating DFRN-URL for everything we need. Create a contact record
212          * and an introduction to show our user next time he/she logs in.
213          * Finally redirect back to the requestor so that their site can record the request.
214          * If our user (the requestee) later confirms this request, a record of it will need
215          * to exist on the requestor's cell in order for the confirmation process to complete..
216          *
217          * It's possible that neither the requestor or the requestee are logged in at the moment,
218          * and the requestor does not yet have any credentials to the requestee profile.
219          *
220          * Who is the requestee? We've already loaded their profile which means their nickname should be
221          * in $a->argv[1] and we should have their complete info in $a->profile.
222          *
223          */
224         if (!(is_array($a->profile) && count($a->profile))) {
225                 notice(L10n::t('Profile unavailable.') . EOL);
226                 return;
227         }
228
229         $nickname       = $a->profile['nickname'];
230         $notify_flags   = $a->profile['notify-flags'];
231         $uid            = $a->profile['uid'];
232         $maxreq         = intval($a->profile['maxreq']);
233         $contact_record = null;
234         $failed         = false;
235         $parms          = null;
236         $blocked = 1;
237         $pending = 1;
238
239         if (!empty($_POST['dfrn_url'])) {
240                 // Block friend request spam
241                 if ($maxreq) {
242                         $r = q("SELECT * FROM `intro` WHERE `datetime` > '%s' AND `uid` = %d",
243                                 DBA::escape(DateTimeFormat::utc('now - 24 hours')),
244                                 intval($uid)
245                         );
246                         if (DBA::isResult($r) && count($r) > $maxreq) {
247                                 notice(L10n::t('%s has received too many connection requests today.', $a->profile['name']) . EOL);
248                                 notice(L10n::t('Spam protection measures have been invoked.') . EOL);
249                                 notice(L10n::t('Friends are advised to please try again in 24 hours.') . EOL);
250                                 return;
251                         }
252                 }
253
254                 /* Cleanup old introductions that remain blocked.
255                  * Also remove the contact record, but only if there is no existing relationship
256                  */
257                 $r = q("SELECT `intro`.*, `intro`.`id` AS `iid`, `contact`.`id` AS `cid`, `contact`.`rel`
258                         FROM `intro` LEFT JOIN `contact` on `intro`.`contact-id` = `contact`.`id`
259                         WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0
260                         AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE "
261                 );
262                 if (DBA::isResult($r)) {
263                         foreach ($r as $rr) {
264                                 if (!$rr['rel']) {
265                                         DBA::delete('contact', ['id' => $rr['cid'], 'self' => false]);
266                                 }
267                                 DBA::delete('intro', ['id' => $rr['iid']]);
268                         }
269                 }
270
271                 $real_name = !empty($_POST['realname']) ? Strings::escapeTags(trim($_POST['realname'])) : '';
272
273                 $url = trim($_POST['dfrn_url']);
274                 if (!strlen($url)) {
275                         notice(L10n::t("Invalid locator") . EOL);
276                         return;
277                 }
278
279                 $hcard = '';
280
281                 // Detect the network
282                 $data = Probe::uri($url);
283                 $network = $data["network"];
284
285                 // Canonicalise email-style profile locator
286                 $url = Probe::webfingerDfrn($url, $hcard);
287
288                 if (substr($url, 0, 5) === 'stat:') {
289                         // Every time we detect the remote subscription we define this as OStatus.
290                         // We do this even if it is not OStatus.
291                         // we only need to pass this through another section of the code.
292                         if ($network != Protocol::DIASPORA) {
293                                 $network = Protocol::OSTATUS;
294                         }
295
296                         $url = substr($url, 5);
297                 } else {
298                         $network = Protocol::DFRN;
299                 }
300
301                 Logger::log('dfrn_request: url: ' . $url . ',network=' . $network, Logger::DEBUG);
302
303                 if ($network === Protocol::DFRN) {
304                         $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1",
305                                 intval($uid),
306                                 DBA::escape($url)
307                         );
308
309                         if (DBA::isResult($ret)) {
310                                 if (strlen($ret[0]['issued-id'])) {
311                                         notice(L10n::t('You have already introduced yourself here.') . EOL);
312                                         return;
313                                 } elseif ($ret[0]['rel'] == Contact::FRIEND) {
314                                         notice(L10n::t('Apparently you are already friends with %s.', $a->profile['name']) . EOL);
315                                         return;
316                                 } else {
317                                         $contact_record = $ret[0];
318                                         $parms = ['dfrn-request' => $ret[0]['request']];
319                                 }
320                         }
321
322                         $issued_id = Strings::getRandomHex();
323
324                         if (is_array($contact_record)) {
325                                 // There is a contact record but no issued-id, so this
326                                 // is a reciprocal introduction from a known contact
327                                 $r = q("UPDATE `contact` SET `issued-id` = '%s' WHERE `id` = %d",
328                                         DBA::escape($issued_id),
329                                         intval($contact_record['id'])
330                                 );
331                         } else {
332                                 $url = Network::isUrlValid($url);
333                                 if (!$url) {
334                                         notice(L10n::t('Invalid profile URL.') . EOL);
335                                         $a->internalRedirect($a->cmd);
336                                         return; // NOTREACHED
337                                 }
338
339                                 if (!Network::isUrlAllowed($url)) {
340                                         notice(L10n::t('Disallowed profile URL.') . EOL);
341                                         $a->internalRedirect($a->cmd);
342                                         return; // NOTREACHED
343                                 }
344
345                                 if (Network::isUrlBlocked($url)) {
346                                         notice(L10n::t('Blocked domain') . EOL);
347                                         $a->internalRedirect($a->cmd);
348                                         return; // NOTREACHED
349                                 }
350
351                                 $parms = Probe::profile(($hcard) ? $hcard : $url);
352
353                                 if (!count($parms)) {
354                                         notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL);
355                                         $a->internalRedirect($a->cmd);
356                                 } else {
357                                         if (empty($parms['fn'])) {
358                                                 notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL);
359                                         }
360                                         if (empty($parms['photo'])) {
361                                                 notice(L10n::t('Warning: profile location has no profile photo.') . EOL);
362                                         }
363                                         $invalid = Probe::validDfrn($parms);
364                                         if ($invalid) {
365                                                 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);
366
367                                                 return;
368                                         }
369                                 }
370
371                                 $parms['url'] = $url;
372                                 $parms['issued-id'] = $issued_id;
373                                 $photo = $parms["photo"];
374
375                                 DBA::escapeArray($parms);
376                                 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`,
377                                         `request`, `confirm`, `notify`, `poll`, `network`, `blocked`, `pending` )
378                                         VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
379                                         intval($uid),
380                                         DBA::escape(DateTimeFormat::utcNow()),
381                                         $parms['url'],
382                                         DBA::escape(Strings::normaliseLink($url)),
383                                         $parms['addr'],
384                                         $parms['fn'],
385                                         $parms['nick'],
386                                         $parms['issued-id'],
387                                         $parms['photo'],
388                                         $parms['key'],
389                                         $parms['dfrn-request'],
390                                         $parms['dfrn-confirm'],
391                                         $parms['dfrn-notify'],
392                                         $parms['dfrn-poll'],
393                                         DBA::escape(Protocol::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 (DBA::isResult($r)) {
407                                                 $contact_record = $r[0];
408                                                 Contact::updateAvatar($photo, $uid, $contact_record["id"], true);
409                                         }
410                                 }
411                         }
412                         if ($r === false) {
413                                 notice(L10n::t('Failed to update contact record.') . EOL);
414                                 return;
415                         }
416
417                         $hash = Strings::getRandomHex() . (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                                         intval(!empty($_POST['knowyou'])),
425                                         DBA::escape(Strings::escapeTags(trim(defaults($_POST, 'dfrn-request-message', '')))),
426                                         DBA::escape($hash),
427                                         DBA::escape(DateTimeFormat::utcNow())
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(L10n::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($a->getBaseURL() . '/profile/' . $nickname);
438                         $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0);
439
440                         System::externalRedirect($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 === Protocol::DFRN
447                 } elseif (($network != Protocol::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 == Protocol::DIASPORA) {
455                                 $uri = $nickname . '@' . $a->getHostName();
456
457                                 if ($a->getURLPath()) {
458                                         $uri .= '/' . $a->getURLPath();
459                                 }
460
461                                 $uri = urlencode($uri);
462                         } else {
463                                 $uri = 'profile/' . $nickname;
464                         }
465
466                         $url = str_replace('{uri}', $uri, $url);
467                         System::externalRedirect($url);
468                         // NOTREACHED
469                         // END $network != Protocol::PHANTOM
470                 } else {
471                         notice(L10n::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 (!empty($_GET['dfrn_url'])) {
486                 if (!local_user()) {
487                         info(L10n::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(L10n::t("Incorrect identity currently logged in. Please login to <strong>this</strong> profile.") . EOL);
496                         return Login::form();
497                 }
498
499                 $dfrn_url = Strings::escapeTags(trim(hex2bin($_GET['dfrn_url'])));
500                 $aes_allow = !empty($_GET['aes_allow']);
501                 $confirm_key = defaults($_GET, 'confirm_key', "");
502
503                 // Checking fastlane for validity
504                 if (!empty($_SESSION['fastlane']) && (Strings::normaliseLink($_SESSION["fastlane"]) == Strings::normaliseLink($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"] = L10n::t('Confirm');
510
511                         dfrn_request_post($a);
512
513                         killme();
514                         return; // NOTREACHED
515                 }
516
517                 $tpl = Renderer::getMarkupTemplate("dfrn_req_confirm.tpl");
518                 $o = Renderer::replaceMacros($tpl, [
519                         '$dfrn_url' => $dfrn_url,
520                         '$aes_allow' => (($aes_allow) ? '<input type="hidden" name="aes_allow" value="1" />' : "" ),
521                         '$hidethem' => L10n::t('Hide this contact'),
522                         '$hidechecked' => '',
523                         '$confirm_key' => $confirm_key,
524                         '$welcome' => L10n::t('Welcome home %s.', $a->user['username']),
525                         '$please' => L10n::t('Please confirm your introduction/connection request to %s.', $dfrn_url),
526                         '$submit' => L10n::t('Confirm'),
527                         '$uid' => $_SESSION['uid'],
528                         '$nickname' => $a->user['nickname'],
529                         'dfrn_rawurl' => $_GET['dfrn_url']
530                 ]);
531                 return $o;
532         } elseif (!empty($_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                         DBA::escape($_GET['confirm_key'])
538                 );
539
540                 if (DBA::isResult($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 (DBA::isResult($r)) {
549                                 if ($r[0]['page-flags'] != Contact::PAGE_NORMAL && $r[0]['page-flags'] != Contact::PAGE_PRVGROUP) {
550                                         $auto_confirm = true;
551                                 }
552
553                                 if (!$auto_confirm) {
554                                         notification([
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']) : L10n::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 = [
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'] == Contact::PAGE_FREELOVE) ? 1 : 0),
578                                         ];
579                                         dfrn_confirm_post($a, $handsfree);
580                                 }
581                         }
582
583                         if (!$auto_confirm) {
584
585                                 // If we are auto_confirming, this record will have already been nuked
586                                 // in dfrn_confirm_post()
587
588                                 $r = q("UPDATE `intro` SET `blocked` = 0 WHERE `hash` = '%s'",
589                                         DBA::escape($_GET['confirm_key'])
590                                 );
591                         }
592                 }
593
594                 killme();
595                 return; // NOTREACHED
596         } else {
597                 // Normal web request. Display our user's introduction form.
598                 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
599                         if (!Config::get('system', 'local_block')) {
600                                 notice(L10n::t('Public access denied.') . EOL);
601                                 return;
602                         }
603                 }
604
605                 // Try to auto-fill the profile address
606                 // At first look if an address was provided
607                 // Otherwise take the local address
608                 if (!empty($_GET['addr'])) {
609                         $myaddr = hex2bin($_GET['addr']);
610                 } elseif (!empty($_GET['address'])) {
611                         $myaddr = $_GET['address'];
612                 } elseif (local_user()) {
613                         if (strlen($a->getURLPath())) {
614                                 $myaddr = System::baseUrl() . '/profile/' . $a->user['nickname'];
615                         } else {
616                                 $myaddr = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
617                         }
618                 } else {
619                         // last, try a zrl
620                         $myaddr = Profile::getMyURL();
621                 }
622
623                 $target_addr = $a->profile['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
624
625                 /* The auto_request form only has the profile address
626                  * because nobody is going to read the comments and
627                  * it doesn't matter if they know you or not.
628                  */
629                 if ($a->profile['page-flags'] == Contact::PAGE_NORMAL) {
630                         $tpl = Renderer::getMarkupTemplate('dfrn_request.tpl');
631                 } else {
632                         $tpl = Renderer::getMarkupTemplate('auto_request.tpl');
633                 }
634
635                 $page_desc = L10n::t("Please enter your 'Identity Address' from one of the following supported communications networks:");
636
637                 $invite_desc = sprintf(
638                         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>.'),
639                         get_server() . '/servers'
640                 );
641
642                 $o = Renderer::replaceMacros($tpl, [
643                         '$header' => L10n::t('Friend/Connection Request'),
644                         '$desc' => L10n::t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@gnusocial.de'),
645                         '$pls_answer' => L10n::t('Please answer the following:'),
646                         '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $a->profile['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
647                         '$add_note' => L10n::t('Add a personal note:'),
648                         '$page_desc' => $page_desc,
649                         '$friendica' => L10n::t('Friendica'),
650                         '$statusnet' => L10n::t("GNU Social \x28Pleroma, Mastodon\x29"),
651                         '$diaspora' => L10n::t("Diaspora \x28Socialhome, Hubzilla\x29"),
652                         '$diasnote' => L10n::t(' - please do not use this form.  Instead, enter %s into your Diaspora search bar.', $target_addr),
653                         '$your_address' => L10n::t('Your Identity Address:'),
654                         '$invite_desc' => $invite_desc,
655                         '$submit' => L10n::t('Submit Request'),
656                         '$cancel' => L10n::t('Cancel'),
657                         '$nickname' => $a->argv[1],
658                         '$name' => $a->profile['name'],
659                         '$myaddr' => $myaddr
660                 ]);
661                 return $o;
662         }
663
664         return; // Somebody is fishing.
665 }