4 function dfrn_poll_init(&$a) {
7 $dfrn_id = $a->config['dfrn_poll_dfrn_id'] = $_GET['dfrn_id'];
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'];
19 if((x($type)) && ($type == 'profile')) {
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",
26 $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $dfrn_id . '&type=profile-check');
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",
41 $profile = ((strlen($r[0]['nickname'])) ? $r[0]['nickname'] : $r[0]['uid']);
42 goaway($a->get_baseurl() . "/profile/$profile/visit");
44 goaway($a->get_baseurl());
47 if((x($type)) && ($type == 'profile-check')) {
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",
60 // initial communication from external contact
61 $hash = random_string();
65 $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
67 $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )
68 VALUES( '%s', '%s', '%s', '%s', '%s' ) ",
70 dbesc(notags(trim($_GET['dfrn_id']))),
76 $r = q("SELECT * FROM `contact` WHERE `issued-id` = '%s' AND `blocked` = 0 LIMIT 1",
77 dbesc($_GET['dfrn_id']));
78 if((! count($r)) || (! strlen($r[0]['prvkey'])))
83 openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
84 $challenge = bin2hex($challenge);
85 echo '<?xml version="1.0" encoding="UTF-8"?><dfrn_poll><status>' .$status . '</status><dfrn_id>' . $_GET['dfrn_id'] . '</dfrn_id>'
86 . '<challenge>' . $challenge . '</challenge></dfrn_poll>' . "\r\n" ;
87 session_write_close();
94 function dfrn_poll_post(&$a) {
96 $dfrn_id = notags(trim($_POST['dfrn_id']));
97 $challenge = notags(trim($_POST['challenge']));
99 $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
106 $type = $r[0]['type'];
107 $last_update = $r[0]['last_update'];
109 $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
115 $r = q("SELECT * FROM `contact` WHERE `issued-id` = '%s' LIMIT 1",
121 $owner_uid = $r[0]['uid'];
122 $contact_id = $r[0]['id'];
125 if($type == 'reputation' && strlen($url)) {
126 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
134 $reputation = $r[0]['rating'];
135 $text = $r[0]['reason'];
137 if($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed
143 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
146 <rating>$reputation</rating>
147 <description>$text</description>
151 return; // NOTREACHED
161 function dfrn_poll_content(&$a) {