You are here

public function Callback::isValidHubVerification in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/PubSubHubbub/Subscriber/Callback.php \Zend\Feed\PubSubHubbub\Subscriber\Callback::isValidHubVerification()

Checks validity of the request simply by making a quick pass and confirming the presence of all REQUIRED parameters.

Parameters

array $httpGetData:

Return value

bool

1 call to Callback::isValidHubVerification()
Callback::handle in vendor/zendframework/zend-feed/src/PubSubHubbub/Subscriber/Callback.php
Handle any callback from a Hub Server responding to a subscription or unsubscription request. This should be the Hub Server confirming the the request prior to taking action on it.

File

vendor/zendframework/zend-feed/src/PubSubHubbub/Subscriber/Callback.php, line 132

Class

Callback

Namespace

Zend\Feed\PubSubHubbub\Subscriber

Code

public function isValidHubVerification(array $httpGetData) {

  /**
   * As per the specification, the hub.verify_token is OPTIONAL. This
   * implementation of Pubsubhubbub considers it REQUIRED and will
   * always send a hub.verify_token parameter to be echoed back
   * by the Hub Server. Therefore, its absence is considered invalid.
   */
  if (strtolower($_SERVER['REQUEST_METHOD']) !== 'get') {
    return false;
  }
  $required = [
    'hub_mode',
    'hub_topic',
    'hub_challenge',
    'hub_verify_token',
  ];
  foreach ($required as $key) {
    if (!array_key_exists($key, $httpGetData)) {
      return false;
    }
  }
  if ($httpGetData['hub_mode'] !== 'subscribe' && $httpGetData['hub_mode'] !== 'unsubscribe') {
    return false;
  }
  if ($httpGetData['hub_mode'] == 'subscribe' && !array_key_exists('hub_lease_seconds', $httpGetData)) {
    return false;
  }
  if (!Uri::factory($httpGetData['hub_topic'])
    ->isValid()) {
    return false;
  }

  /**
   * Attempt to retrieve any Verification Token Key attached to Callback
   * URL's path by our Subscriber implementation
   */
  if (!$this
    ->_hasValidVerifyToken($httpGetData)) {
    return false;
  }
  return true;
}