protected function PuSHSubscriber::request in Feeds 8.2
Issue a subscribe or unsubcribe request to a PubsubHubbub hub.
@todo Make concurrency safe.
Parameters
$hub: The URL of the hub's subscription endpoint.
$topic: The topic URL of the feed to subscribe to.
$mode: 'subscribe' or 'unsubscribe'.
$callback_url: The subscriber's notifications callback URL.
Compare to http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.2.html#...
2 calls to PuSHSubscriber::request()
- PuSHSubscriber::subscribe in lib/
Drupal/ feeds/ PuSHSubscriber.php - Subscribe to a given URL. Attempt to retrieve 'hub' and 'self' links from document at $url and issue a subscription request to the hub.
- PuSHSubscriber::unsubscribe in lib/
Drupal/ feeds/ PuSHSubscriber.php - @todo Unsubscribe from a hub. @todo Make sure we unsubscribe with the correct topic URL as it can differ from the initial subscription URL.
File
- lib/
Drupal/ feeds/ PuSHSubscriber.php, line 248 - Pubsubhubbub subscriber library.
Class
- PuSHSubscriber
- PubSubHubbub subscriber.
Namespace
Drupal\feedsCode
protected function request($hub, $topic, $mode, $callback_url) {
$secret = hash('sha1', uniqid(rand(), TRUE));
$post_fields = array(
'hub.callback' => $callback_url,
'hub.mode' => $mode,
'hub.topic' => $topic,
'hub.verify' => 'sync',
'hub.lease_seconds' => '',
// Permanent subscription.
'hub.secret' => $secret,
'hub.verify_token' => md5(session_id() . rand()),
);
$sub = new $this->subscription_class($this->domain, $this->subscriber_id, $hub, $topic, $secret, $mode, $post_fields);
$sub
->save();
// Issue subscription request.
$request = curl_init($hub);
curl_setopt($request, CURLOPT_POST, TRUE);
curl_setopt($request, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($request);
$code = curl_getinfo($request, CURLINFO_HTTP_CODE);
if (in_array($code, array(
202,
204,
))) {
$this
->log("Positive response to \"{$mode}\" request ({$code}).");
}
else {
$sub->status = $mode . ' failed';
$sub
->save();
$this
->log("Error issuing \"{$mode}\" request to {$hub} ({$code}).", 'error');
}
curl_close($request);
}