4 * Handles PuSH subscription responses
6 header('HTTP/1.0 500 Internal Server Error');
7 require 'www-header.php';
9 //PHP converts dots to underscore, so hub.mode becomes hub_mode
10 if (!isset($_GET['hub_mode'])) {
11 header('HTTP/1.0 400 Bad Request');
12 echo "Parameter missing: hub.mode\n";
15 $hubMode = $_GET['hub_mode'];
17 if (!isset($_GET['hub_topic'])) {
18 header('HTTP/1.0 400 Bad Request');
19 echo "Parameter missing: hub.topic\n";
22 if (!isValidUrl($_GET['hub_topic'])) {
23 header('HTTP/1.0 400 Bad Request');
24 echo "Invalid parameter value for hub.topic: Invalid URL\n";
27 $hubTopic = $_GET['hub_topic'];
29 $subDb = new Subscriptions();
31 if ($hubMode == 'denied') {
32 //TODO: Inspect Location header to retry subscription
33 //TODO: remove subscription
35 } else if ($hubMode == 'subscribe') {
37 $pos = array_search($hubTopic, $GLOBALS['phinde']['subscriptions']);
39 //we do not want to subscribe
40 header('HTTP/1.0 404 Not Found');
41 echo "We are not interested in this hub.topic\n";
44 if (!isset($_GET['hub_challenge'])) {
45 header('HTTP/1.0 400 Bad Request');
46 echo "Parameter missing: hub.challenge\n";
49 $hubChallenge = $_GET['hub_challenge'];
51 if (!isset($_GET['hub_lease_seconds'])) {
52 header('HTTP/1.0 400 Bad Request');
53 echo "Parameter missing: hub.lease_seconds\n";
56 $hubLeaseSeconds = $_GET['hub_lease_seconds'];
58 //FIXME: store in database
60 header('HTTP/1.0 200 OK');
61 header('Content-type: text/plain');
65 } else if ($hubMode == 'unsubscribe') {
66 $sub = $subDb->get($hubTopic);
68 //we do not know this subscription
69 header('HTTP/1.0 404 Not Found');
70 echo "We are not subscribed to this hub.topic\n";
73 $pos = array_search($hubTopic, $GLOBALS['phinde']['subscriptions']);
75 //we do not want to unsubscribe
76 header('HTTP/1.0 404 Not Found');
77 echo "We do not want to unsubscribe from this hub.topic\n";
80 $sub->remove($hubTopic);
81 header('HTTP/1.0 200 OK');
82 header('Content-type: text/plain');
83 echo "Unsubscribed.\n";
86 header('HTTP/1.0 400 Bad Request');
87 echo "Invalid parameter value for hub.mode\n";
92 function isValidUrl($url)
94 if (filter_var($url, FILTER_VALIDATE_URL) === false) {
97 if (substr($url, 0, 7) == 'http://'
98 || substr($url, 0, 8) == 'https://'