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 = ((x($_GET,'hub_mode')) ? notags(trim($_GET['hub_mode'])) : '');
37 $hub_topic = ((x($_GET,'hub_topic')) ? notags(trim($_GET['hub_topic'])) : '');
38 $hub_challenge = ((x($_GET,'hub_challenge')) ? notags(trim($_GET['hub_challenge'])) : '');
39 $hub_lease = ((x($_GET,'hub_lease_seconds')) ? notags(trim($_GET['hub_lease_seconds'])) : '');
40 $hub_verify = ((x($_GET,'hub_verify_token')) ? notags(trim($_GET['hub_verify_token'])) : '');
42 logger('pubsub: Subscription from' . $_SERVER['REMOTE_ADDR'] . print_r($_GET,true));
44 $subscribe = (($hub_mode === 'subscribe') ? 1 : 0);
46 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
50 hub_return(false, '');
55 $sql_extra = ((strlen($hub_verify)) ? sprintf(" AND `hub-verify` = '%s' ", dbesc($hub_verify)) : '');
57 $r = q("SELECT * FROM `contact` WHERE `poll` = '%s' AND `id` = %d AND `uid` = %d AND `blocked` = 0 $sql_extra LIMIT 1",
63 hub_return(false, '');
67 // We must initiate an unsubscribe request with a verify_token.
68 // Don't allow outsiders to unsubscribe us.
70 if(($hub_mode === 'unsubscribe') && (! strlen($hub_verify)))
71 hub_return(false, '');
73 $r = q("UPDATE `contact` SET `subhub` = %d WHERE `id` = %d LIMIT 1",
75 intval($contact['id'])
78 hub_return(true, $hub_challenge);
82 require_once('include/security.php');
84 function pubsub_post(&$a) {
86 $xml = file_get_contents('php://input');
88 logger('pubsub: feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $a->cmd );
89 logger('pubsub: user-agent: ' . $_SERVER['HTTP_USER_AGENT'] );
90 logger('pubsub: data: ' . $xml, LOGGER_DATA);
92 $nick = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
93 $contact_id = (($a->argc > 2) ? intval($a->argv[2]) : 0 );
95 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
103 $r = q("SELECT * FROM `contact` WHERE `subhub` = 1 AND `id` = %d AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
105 intval($importer['uid'])
114 require_once('include/items.php');
116 consume_feed($xml,$importer,$contact,$feedhub,1);
118 // do it a second time so that any children find their parents.
120 consume_feed($xml,$importer,$contact,$feedhub,1);