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