3 function hub_return($valid,$body) {
6 header($_SERVER["SERVER_PROTOCOL"] . ' 200 ' . 'OK');
11 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . 'Not Found');
18 // when receiving an XML feed, always return OK
20 function hub_post_return() {
22 header($_SERVER["SERVER_PROTOCOL"] . ' 200 ' . 'OK');
29 function pubsub_init(&$a) {
31 $nick = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
32 $contact_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
34 if($_SERVER['REQUEST_METHOD'] === 'GET') {
36 $hub_mode = notags(trim($_GET['hub.mode']));
37 $hub_topic = notags(trim($_GET['hub.topic']));
38 $hub_challenge = notags(trim($_GET['hub.challenge']));
39 $hub_lease = notags(trim($_GET['hub.lease_seconds']));
40 $hub_verify = notags(trim($_GET['hub.verify_token']));
42 $subscribe = (($hub_mode === 'subscribe') ? 1 : 0);
44 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
48 hub_return(false, '');
52 $sql_extra = ((strlen($hub_verify)) ? sprintf(" AND `hub-verify` = '%s' ", dbesc($hub_verify)) : '');
54 $r = q("SELECT * FROM `contact` WHERE `poll` = '%s' AND `id` = %d AND `uid` = %d AND `blocked` = 0 $sql_extra LIMIT 1",
60 hub_return(false, '');
64 // We must initiate an unsubscribe request with a verify_token.
65 // Don't allow outsiders to unsubscribe us.
67 if(($hub_mode === 'unsubscribe') && (! strlen($hub_verify)))
68 hub_return(false, '');
70 $r = q("UPDATE `contact` SET `usehub` = %d WHERE `id` = %d LIMIT 1",
72 intval($contact['id'])
75 hub_return(true, $hub_challenge);
81 function pubsub_post(&$a) {
83 $xml = file_get_contents('php://input');
85 $nick = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
86 $contact_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
88 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
96 $r = q("SELECT * FROM `contact` WHERE `usehub` = 1 AND `id` = %d AND `uid` = %d AND `blocked` = 0 LIMIT 1",
98 intval($importer['uid'])
105 consume_feed($xml,$importer,$contact);