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 $url = $res->args['url'];
26 $url = Helper::addSchema($url);
27 $urlObj = new \Net_URL2($url);
28 $url = $urlObj->getNormalizedURL();
29 if (!Helper::isUrlAllowed($url)) {
30 Log::error("Domain is not allowed; not crawling");
34 $subDb = new Subscriptions();
36 list($topic, $hub) = $subDb->detectHub($url);
38 Log::error('No hub URL found for topic');
42 Log::info('Topic URL differs from URL: ' . $topic);
45 $sub = $subDb->get($topic);
47 $subDb->create($topic);
50 'Topic exists already in subscription table with status '
53 Log::info('Renewing subscription...');
54 $subDb->renew($sub->sub_id);
56 $sub = $subDb->get($topic);
58 $callbackUrl = $GLOBALS['phinde']['baseurl'] . 'push-subscription.php'
59 . '?hub.topic=' . urlencode($topic)
60 . '&capkey=' . urlencode($sub->sub_capkey);
61 $req = new HttpRequest($hub, 'POST');
62 $req->addPostParameter('hub.callback', $callbackUrl);
63 $req->addPostParameter('hub.mode', 'subscribe');
64 $req->addPostParameter('hub.topic', $topic);
65 $req->addPostParameter('hub.lease_seconds', $sub->sub_lease_seconds);
66 $req->addPostParameter('hub.secret', $sub->sub_secret);
69 if (intval($res->getStatus()) == 202) {
70 Log::info('Subscription initiated');
75 'Error: Subscription response status code was not 202 but '
78 Log::error($res->getBody());