]> git.mxchange.org Git - friendica.git/blob - mod/redir.php
Remove unused global cache constants
[friendica.git] / mod / redir.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
6
7 function redir_init(App $a) {
8
9         $url = ((x($_GET,'url')) ? $_GET['url'] : '');
10         $quiet = ((x($_GET,'quiet')) ? '&quiet=1' : '');
11         $con_url = ((x($_GET,'conurl')) ? $_GET['conurl'] : '');
12
13         // traditional DFRN
14
15         if ($con_url || (local_user() && $a->argc > 1 && intval($a->argv[1]))) {
16
17                 if ($con_url) {
18                         $con_url = str_replace('https', 'http', $con_url);
19
20                         $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
21                                 dbesc($con_url),
22                                 intval(local_user())
23                         );
24
25                         if (!DBM::is_result($r)) {
26                                 goaway(System::baseUrl());
27                         }
28                         if ($r[0]['network'] !== NETWORK_DFRN) {
29                                 goaway(($url != '' ? $url : $r[0]['url']));
30                         }
31                         $cid = $r[0]['id'];
32                 } else {
33                         $cid = $a->argv[1];
34
35                         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
36                                 intval($cid),
37                                 intval(local_user())
38                         );
39
40                         if (!DBM::is_result($r)) {
41                                 goaway(System::baseUrl());
42                         }
43                         if ($r[0]['network'] !== NETWORK_DFRN) {
44                                 goaway(($url != '' ? $url : $r[0]['url']));
45                         }
46                 }
47
48                 $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
49
50                 if ($r[0]['duplex'] && $r[0]['issued-id']) {
51                         $orig_id = $r[0]['issued-id'];
52                         $dfrn_id = '1:' . $orig_id;
53                 }
54                 if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
55                         $orig_id = $r[0]['dfrn-id'];
56                         $dfrn_id = '0:' . $orig_id;
57                 }
58
59                 $sec = random_string();
60
61                 q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
62                         VALUES( %d, %s, '%s', '%s', %d )",
63                         intval(local_user()),
64                         intval($cid),
65                         dbesc($dfrn_id),
66                         dbesc($sec),
67                         intval(time() + 45)
68                 );
69
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);
74         }
75
76         if (local_user()) {
77                 $handle = $a->user['nickname'] . '@' . substr(System::baseUrl(),strpos(System::baseUrl(),'://')+3);
78         }
79         if (remote_user()) {
80                 $handle = $_SESSION['handle'];
81         }
82
83         if ($url) {
84                 $url = str_replace('{zid}','&zid=' . $handle,$url);
85                 goaway($url);
86         }
87
88         goaway(System::baseUrl());
89 }