]> git.mxchange.org Git - friendica.git/blob - mod/redir.php
Merge pull request #3149 from annando/1601-new-diaspora-mention
[friendica.git] / mod / redir.php
1 <?php
2
3 function redir_init(App $a) {
4
5         $url = ((x($_GET,'url')) ? $_GET['url'] : '');
6         $quiet = ((x($_GET,'quiet')) ? '&quiet=1' : '');
7         $con_url = ((x($_GET,'conurl')) ? $_GET['conurl'] : '');
8
9         // traditional DFRN
10
11         if( $con_url || (local_user() && $a->argc > 1 && intval($a->argv[1])) ) {
12
13                 if($con_url) {
14                         $con_url = str_replace('https', 'http', $con_url);
15
16                         $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
17                                 dbesc($con_url),
18                                 intval(local_user())
19                         );
20
21                         if((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN))
22                                 goaway(z_root());
23
24                         $cid = $r[0]['id'];
25                 }
26                 else {
27                         $cid = $a->argv[1];
28
29                         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
30                                 intval($cid),
31                                 intval(local_user())
32                         );
33
34                         if((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN))
35                                 goaway(z_root());
36                 }
37
38                 $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
39
40                 if($r[0]['duplex'] && $r[0]['issued-id']) {
41                         $orig_id = $r[0]['issued-id'];
42                         $dfrn_id = '1:' . $orig_id;
43                 }
44                 if($r[0]['duplex'] && $r[0]['dfrn-id']) {
45                         $orig_id = $r[0]['dfrn-id'];
46                         $dfrn_id = '0:' . $orig_id;
47                 }
48
49                 $sec = random_string();
50
51                 q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`)
52                         VALUES( %d, %s, '%s', '%s', %d )",
53                         intval(local_user()),
54                         intval($cid),
55                         dbesc($dfrn_id),
56                         dbesc($sec),
57                         intval(time() + 45)
58                 );
59
60                 logger('mod_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG);
61                 $dest = (($url) ? '&destination_url=' . $url : '');
62                 goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id
63                         . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet );
64         }
65
66         if (local_user()) {
67                 $handle = $a->user['nickname'] . '@' . substr(App::get_baseurl(),strpos(App::get_baseurl(),'://')+3);
68         }
69         if (remote_user()) {
70                 $handle = $_SESSION['handle'];
71         }
72
73         if ($url) {
74                 $url = str_replace('{zid}','&zid=' . $handle,$url);
75                 goaway($url);
76         }
77
78         goaway(z_root());
79 }