You are here

protected static function OAuthDiscovery::discoverXRDS in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discoverXRDS()
  2. 7.2 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discoverXRDS()
  3. 7.3 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discoverXRDS()
  4. 7.4 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discoverXRDS()
  5. 7.6 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discoverXRDS()

* Discover the XRDS file at the uri. This is a bit primitive, you should overrule * this function so that the XRDS file can be cached for later referral. * *

Parameters

string uri: * @return string false when no XRDS file found

1 call to OAuthDiscovery::discoverXRDS()
OAuthDiscovery::discover in lib/oauth-php/library/OAuthDiscovery.php
* Return a description how we can do a consumer allocation. Prefers static allocation if * possible. If static allocation is possible * * See also: http://oauth.net/discovery/#consumer_identity_types * *

File

lib/oauth-php/library/OAuthDiscovery.php, line 139

Class

OAuthDiscovery

Code

protected static function discoverXRDS($uri, $recur = 0) {

  // Bail out when we are following redirects
  if ($recur > 10) {
    return false;
  }
  $data = self::curl($uri);

  // Check what we got back, could be:
  // 1. The XRDS discovery file itself (check content-type)
  // 2. The X-XRDS-Location header
  if (is_string($data) && !empty($data)) {
    list($head, $body) = explode("\r\n\r\n", $data);
    $body = trim($body);
    $m = false;

    // See if we got the XRDS file itself or we have to follow a location header
    if (preg_match('/^Content-Type:\\s*application\\/xrds+xml/im', $head) || preg_match('/^<\\?xml[^>]*\\?>\\s*<xrds\\s/i', $body) || preg_match('/^<xrds\\s/i', $body)) {
      $xrds = $body;
    }
    else {
      if (preg_match('/^X-XRDS-Location:\\s*([^\\r\\n]*)/im', $head, $m) || preg_match('/^Location:\\s*([^\\r\\n]*)/im', $head, $m)) {

        // Recurse to the given location
        if ($uri != $m[1]) {
          $xrds = self::discoverXRDS($m[1], $recur + 1);
        }
        else {

          // Referring to the same uri, bail out
          $xrds = false;
        }
      }
      else {

        // Not an XRDS file an nowhere else to check
        $xrds = false;
      }
    }
  }
  else {
    $xrds = false;
  }
  return $xrds;
}