4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
7 function auto_redir(App $a, $contact_nick) {
11 if (x($_REQUEST,'redir') && intval($_REQUEST['redir']))
14 if ((! $contact_nick) || ($contact_nick === $a->user['nickname']))
19 // We need to find out if $contact_nick is a user on this hub, and if so, if I
20 // am a contact of that user. However, that user may have other contacts with the
21 // same nickname as me on other hubs or other networks. Exclude these by requiring
22 // that the contact have a local URL. I will be the only person with my nickname at
23 // this URL, so if a result is found, then I am a contact of the $contact_nick user.
25 // We also have to make sure that I'm a legitimate contact--I'm not blocked or pending.
27 $baseurl = System::baseUrl();
28 $domain_st = strpos($baseurl, "://");
29 if ($domain_st === false)
31 $baseurl = substr($baseurl, $domain_st + 3);
32 $nurl = normalise_link($baseurl);
34 /// @todo Why is there a query for "url" *and* "nurl"? Especially this normalising is strange.
35 $r = q("SELECT `id` FROM `contact` WHERE `uid` = (SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1)
36 AND `nick` = '%s' AND NOT `self` AND (`url` LIKE '%%%s%%' OR `nurl` LIKE '%%%s%%') AND NOT `blocked` AND NOT `pending` LIMIT 1",
38 dbesc($a->user['nickname']),
43 if ((! DBM::is_result($r)) || $r[0]['id'] == remote_user()) {
47 $r = q("SELECT * FROM contact WHERE nick = '%s'
48 AND network = '%s' AND uid = %d AND url LIKE '%%%s%%' LIMIT 1",
55 if (! DBM::is_result($r)) {
61 $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
63 if ($r[0]['duplex'] && $r[0]['issued-id']) {
64 $orig_id = $r[0]['issued-id'];
65 $dfrn_id = '1:' . $orig_id;
67 if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
68 $orig_id = $r[0]['dfrn-id'];
69 $dfrn_id = '0:' . $orig_id;
72 // ensure that we've got a valid ID. There may be some edge cases with forums and non-duplex mode
73 // that may have triggered some of the "went to {profile/intro} and got an RSS feed" issues
75 if (strlen($dfrn_id) < 3)
78 $sec = random_string();
80 q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
81 VALUES( %d, %s, '%s', '%s', %d )",
91 logger('auto_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
92 $dest = (($url) ? '&destination_url=' . $url : '');
93 goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
94 . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest );