]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_poll.php
remote comments working now
[friendica.git] / mod / dfrn_poll.php
1 <?php
2
3
4 function dfrn_poll_init(&$a) {
5
6         if(x($_GET,'dfrn_id'))
7                 $dfrn_id = $a->config['dfrn_poll_dfrn_id'] = $_GET['dfrn_id'];
8         if(x($_GET,'type'))
9                 $type = $a->config['dfrn_poll_type'] = $_GET['type'];
10         if(x($_GET,'last_update'))
11                 $last_update = $a->config['dfrn_poll_last_update'] = $_GET['last_update'];
12
13
14
15         if(! x($dfrn_id))
16                 return;
17
18
19         if((x($type)) && ($type == 'profile')) {
20
21                 $r = q("SELECT `contact`.*, `user`.`nickname` 
22                         FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
23                         WHERE `issued-id` = '%s' LIMIT 1",
24                         dbesc($dfrn_id));
25                 if(count($r)) {
26                         $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $dfrn_id . '&type=profile-check');
27                         if(strlen($s)) {
28                                 $xml = simplexml_load_string($s);
29                                 if((int) $xml->status == 1) {
30                                         $_SESSION['authenticated'] = 1;
31                                         $_SESSION['visitor_id'] = $r[0]['id'];
32                                         $_SESSION['sysmsg'] .= "Hi {$r[0]['name']}" . EOL;
33                                         // Visitors get 1 day session.
34                                         $session_id = session_id();
35                                         $expire = time() + 86400;
36                                         q("UPDATE `session` SET `expire` = '%s' WHERE `sid` = '%s' LIMIT 1",
37                                                 dbesc($expire),
38                                                 dbesc($session_id)); 
39                                 }
40                         }
41                         $profile = ((strlen($r[0]['nickname'])) ? $r[0]['nickname'] : $r[0]['uid']);
42                         goaway($a->get_baseurl() . "/profile/$profile/visit");
43                 }
44                 goaway($a->get_baseurl());
45         }
46
47         if((x($type)) && ($type == 'profile-check')) {
48
49                 q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
50                 $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
51                         dbesc($dfrn_id));
52                 if(count($r))
53                         xml_status(1);
54                 xml_status(0);
55                 return; // NOTREACHED
56         }
57
58 }