You are here

function xrds_xrd_oauth in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/discovery/xrds_parse.php \xrds_xrd_oauth()
  2. 7.2 lib/oauth-php/library/discovery/xrds_parse.php \xrds_xrd_oauth()
  3. 7.4 lib/oauth-php/library/discovery/xrds_parse.php \xrds_xrd_oauth()
  4. 7.5 lib/oauth-php/library/discovery/xrds_parse.php \xrds_xrd_oauth()
  5. 7.6 lib/oauth-php/library/discovery/xrds_parse.php \xrds_xrd_oauth()

Parse a XRD definition for OAuth and return the uris etc.

Parameters

XPath xpath:

string id:

Return value

array

1 call to xrds_xrd_oauth()
xrds_parse in lib/oauth-php/library/discovery/xrds_parse.php
Parse the xrds file in the argument. The xrds description must have been fetched via curl or something else.

File

lib/oauth-php/library/discovery/xrds_parse.php, line 100

Code

function xrds_xrd_oauth($xpath, $id) {
  $oauth = array();
  $xrd = $xpath
    ->query('//xrds:XRDS/xrd:XRD[@xml:id="' . $id . '"]');
  if ($xrd->length == 0) {

    // Yahoo! uses another namespace
    $xrd = $xpath
      ->query('//xrds:XRDS/xrd2:XRD[@xml:id="' . $id . '"]');
  }
  if ($xrd->length >= 1) {
    $x = $xrd
      ->item(0);
    $services = array();
    foreach ($x->childNodes as $n) {
      switch ($n->nodeName) {
        case 'Type':
          if ($n->nodeValue != 'xri://$xrds*simple') {

            // Not a simple XRDS document
            return false;
          }
          break;
        case 'Expires':
          $oauth['expires'] = $n->nodeValue;
          break;
        case 'Service':
          list($type, $service) = xrds_xrd_oauth_service($n);
          if ($type) {
            $services[$type][xrds_priority($n)][] = $service;
          }
          break;
      }
    }

    // Flatten the services on priority
    foreach ($services as $type => $service) {
      $oauth[$type] = xrds_priority_flatten($service);
    }
  }
  else {
    $oauth = false;
  }
  return $oauth;
}