You are here

public function PuSHSubscriber::verifyRequest in Feeds 7.2

Same name and namespace in other branches
  1. 6 libraries/PuSHSubscriber.inc \PuSHSubscriber::verifyRequest()
  2. 7 libraries/PuSHSubscriber.inc \PuSHSubscriber::verifyRequest()

Verify a request. After a hub has received a subscribe or unsubscribe request (see PuSHSubscriber::request()) it sends back a challenge verifying that an action indeed was requested ($_GET['hub_challenge']). This method handles the challenge.

1 call to PuSHSubscriber::verifyRequest()
PuSHSubscriber::handleRequest in libraries/PuSHSubscriber.inc
Request handler for subscription callbacks.

File

libraries/PuSHSubscriber.inc, line 185
Pubsubhubbub subscriber library.

Class

PuSHSubscriber
PubSubHubbub subscriber.

Code

public function verifyRequest() {
  if (!isset($_GET['hub_challenge'])) {
    return $this
      ->rejectRequest();
  }

  // Don't accept modes of 'subscribed' or 'unsubscribed'.
  if ($_GET['hub_mode'] !== 'subscribe' && $_GET['hub_mode'] !== 'unsubscribe') {
    return $this
      ->rejectRequest();
  }

  // No available subscription.
  if (!($sub = $this
    ->subscription())) {
    return $this
      ->rejectRequest();
  }

  // Not what we asked for.
  if ($_GET['hub_mode'] !== $sub->status) {
    return $this
      ->rejectRequest();
  }

  // Wrong URL.
  if ($_GET['hub_topic'] !== $sub->topic) {
    return $this
      ->rejectRequest();
  }
  if ($sub->status === 'subscribe') {
    $sub->status = 'subscribed';
    $this
      ->log('Verified "subscribe" request.');
  }
  else {
    $sub->status = 'unsubscribed';
    $this
      ->log('Verified "unsubscribe" request.');
  }
  $sub->post_fields = array();
  $sub
    ->save();
  header('HTTP/1.1 200 "Found"', NULL, 200);
  print check_plain($_GET['hub_challenge']);
  drupal_exit();
}