You are here

public function PuSHSubscriber::verifyRequest in Feeds 7

Same name and namespace in other branches
  1. 6 libraries/PuSHSubscriber.inc \PuSHSubscriber::verifyRequest()
  2. 7.2 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 183
Pubsubhubbub subscriber library.

Class

PuSHSubscriber
PubSubHubbub subscriber.

Code

public function verifyRequest() {
  if (isset($_GET['hub_challenge'])) {

    /**
     * If a subscription is present, compare the verify token. If the token
     * matches, set the status on the subscription record and confirm
     * positive.
     *
     * If we cannot find a matching subscription and the hub checks on
     * 'unsubscribe' confirm positive.
     *
     * In all other cases confirm negative.
     */
    if ($sub = $this
      ->subscription()) {
      if ($_GET['hub_verify_token'] == $sub->post_fields['hub.verify_token']) {
        if ($_GET['hub_mode'] == 'subscribe' && $sub->status == 'subscribe') {
          $sub->status = 'subscribed';
          $sub->post_fields = array();
          $sub
            ->save();
          $this
            ->log('Verified "subscribe" request.');
          $verify = TRUE;
        }
        elseif ($_GET['hub_mode'] == 'unsubscribe' && $sub->status == 'unsubscribe') {
          $sub->status = 'unsubscribed';
          $sub->post_fields = array();
          $sub
            ->save();
          $this
            ->log('Verified "unsubscribe" request.');
          $verify = TRUE;
        }
      }
    }
    elseif ($_GET['hub_mode'] == 'unsubscribe') {
      $this
        ->log('Verified "unsubscribe" request.');
      $verify = TRUE;
    }
    if ($verify) {
      header('HTTP/1.1 200 "Found"', null, 200);
      print $_GET['hub_challenge'];
      exit;
    }
  }
  header('HTTP/1.1 404 "Not Found"', null, 404);
  $this
    ->log('Could not verify subscription.', 'error');
  exit;
}