5 * Subscribe with PubSubHubbub to an URL
7 require_once __DIR__ . '/../src/init.php';
9 $cc = new \Console_CommandLine();
10 $cc->description = 'Subscribe to URL updates';
11 $cc->version = '0.0.1';
15 'description' => 'URL to process',
21 } catch (\Exception $e) {
22 $cc->displayError($e->getMessage());
25 $subDb = new Subscriptions();
27 $url = $res->args['url'];
28 $url = Helper::addSchema($url);
29 $urlObj = new \Net_URL2($url);
30 $url = $urlObj->getNormalizedURL();
31 if (!Helper::isUrlAllowed($url)) {
32 Log::error("Domain is not allowed; not subscribing");
37 list($topic, $hub) = $subDb->detectHub($url);
39 Log::error('No hub URL found for topic');
43 Log::info('Topic URL differs from URL: ' . $topic);
46 $sub = $subDb->get($topic);
48 $subDb->create($topic, $hub);
51 'Topic exists already in subscription table with status '
54 Log::info('Renewing subscription...');
55 $subDb->renew($sub->sub_id);
58 $sub = $subDb->get($topic);
60 $callbackUrl = $GLOBALS['phinde']['baseurl'] . 'push-subscription.php'
61 . '?hub.topic=' . urlencode($topic)
62 . '&capkey=' . urlencode($sub->sub_capkey);
63 $req = new HttpRequest($hub, 'POST');
64 $req->addPostParameter('hub.callback', $callbackUrl);
65 $req->addPostParameter('hub.mode', 'subscribe');
66 $req->addPostParameter('hub.topic', $topic);
67 $req->addPostParameter('hub.lease_seconds', $sub->sub_lease_seconds);
68 $req->addPostParameter('hub.secret', $sub->sub_secret);
71 if (intval($res->getStatus()) == 202) {
72 Log::info('Subscription initiated');
77 'Error: Subscription response status code was not 202 but '
80 Log::error($res->getBody());