You are here

public function PuSHSubscriber::verifyRequest in Feeds 8.2

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 lib/Drupal/feeds/PuSHSubscriber.php
Request handler for subscription callbacks.

File

lib/Drupal/feeds/PuSHSubscriber.php, line 187
Pubsubhubbub subscriber library.

Class

PuSHSubscriber
PubSubHubbub subscriber.

Namespace

Drupal\feeds

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'];
      drupal_exit();
    }
  }
  header('HTTP/1.1 404 "Not Found"', NULL, 404);
  $this
    ->log('Could not verify subscription.', 'error');
  drupal_exit();
}