4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
7 function redir_init(App $a) {
9 $url = ((x($_GET,'url')) ? $_GET['url'] : '');
10 $quiet = ((x($_GET,'quiet')) ? '&quiet=1' : '');
11 $con_url = ((x($_GET,'conurl')) ? $_GET['conurl'] : '');
15 if ($con_url || (local_user() && $a->argc > 1 && intval($a->argv[1]))) {
18 $con_url = str_replace('https', 'http', $con_url);
20 $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
25 if (!DBM::is_result($r)) {
26 goaway(System::baseUrl());
28 if ($r[0]['network'] !== NETWORK_DFRN) {
29 goaway(($url != '' ? $url : $r[0]['url']));
35 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
40 if (!DBM::is_result($r)) {
41 goaway(System::baseUrl());
43 if ($r[0]['network'] !== NETWORK_DFRN) {
44 goaway(($url != '' ? $url : $r[0]['url']));
48 $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
50 if ($r[0]['duplex'] && $r[0]['issued-id']) {
51 $orig_id = $r[0]['issued-id'];
52 $dfrn_id = '1:' . $orig_id;
54 if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
55 $orig_id = $r[0]['dfrn-id'];
56 $dfrn_id = '0:' . $orig_id;
59 $sec = random_string();
61 q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
62 VALUES( %d, %s, '%s', '%s', %d )",
70 logger('mod_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
71 $dest = (($url) ? '&destination_url=' . $url : '');
72 goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
73 . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet);
77 $handle = $a->user['nickname'] . '@' . substr(System::baseUrl(),strpos(System::baseUrl(),'://')+3);
80 $handle = $_SESSION['handle'];
84 $url = str_replace('{zid}','&zid=' . $handle,$url);
88 goaway(System::baseUrl());