19 require_once
'Auth/Yadis/XML.php';
25 define(
'SERVICES_YADIS_MATCH_ALL', 101);
31 define(
'SERVICES_YADIS_MATCH_ANY', 102);
37 define(
'SERVICES_YADIS_MAX_PRIORITY', pow(2, 30));
42 define(
'Auth_Yadis_XMLNS_XRD_2_0',
'xri://$xrd*($v*2.0)');
47 define(
'Auth_Yadis_XMLNS_XRDS',
'xri://$xrds');
63 $index = array_rand($arr, 1);
90 $this->element = null;
103 foreach ($this->
getElements(
'xrd:Type') as $elem) {
104 $c = $this->parser->content($elem);
116 foreach ($this->
getTypes() as $typ) {
117 if (in_array($typ, $type_uris)) {
137 $uri_string = $this->parser->content($elem);
138 $attrs = $this->parser->attributes($elem);
140 array_key_exists(
'priority', $attrs)) {
141 $priority = intval($attrs[
'priority']);
142 if (!array_key_exists($priority, $uris)) {
143 $uris[$priority] = array();
146 $uris[$priority][] = $uri_string;
148 $last[] = $uri_string;
152 $keys = array_keys($uris);
157 foreach ($keys as $k) {
177 $attributes = $this->parser->attributes($this->element);
179 if (array_key_exists(
'priority', $attributes)) {
180 return intval($attributes[
'priority']);
203 return $this->parser->evalXPath($name, $this->element);
216 $expires_element = $xrd_element->$parser->evalXPath(
'/xrd:Expires');
217 if ($expires_element === null) {
220 $expires_string = $expires_element->text;
224 $t = strptime($expires_string,
"%Y-%m-%dT%H:%M:%SZ");
232 return mktime(
$t[
'tm_hour'],
$t[
'tm_min'],
$t[
'tm_sec'],
233 $t[
'tm_mon'],
$t[
'tm_day'],
$t[
'tm_year']);
260 $this->parser = $xmlParser;
261 $this->xrdNode = $xrdNodes[count($xrdNodes) - 1];
262 $this->allXrdNodes = $xrdNodes;
263 $this->serviceList = array();
276 static function parseXRDS($xml_string, $extra_ns_map = null)
288 if ($extra_ns_map && is_array($extra_ns_map)) {
289 $ns_map = array_merge($ns_map, $extra_ns_map);
292 if (!($parser && $parser->init($xml_string, $ns_map))) {
297 $root = $parser->evalXPath(
'/xrds:XRDS[1]');
302 if (is_array($root)) {
306 $attrs = $parser->attributes($root);
308 if (array_key_exists(
'xmlns:xrd', $attrs) &&
311 }
else if (array_key_exists(
'xmlns', $attrs) &&
312 preg_match(
'/xri/', $attrs[
'xmlns']) &&
318 $xrd_nodes = $parser->evalXPath(
'/xrds:XRDS[1]/xrd:XRD');
333 $priority = intval($priority);
335 if (!array_key_exists($priority, $this->serviceList)) {
336 $this->serviceList[$priority] = array();
339 $this->serviceList[$priority][] = $service;
350 $this->serviceList = array();
352 $services = $this->parser->evalXPath(
'xrd:Service', $this->xrdNode);
354 foreach ($services as $node) {
357 $s->parser = $this->parser;
359 $priority = $s->getPriority();
361 if ($priority === null) {
365 $this->_addService($priority, $s);
397 $pri_keys = array_keys($this->serviceList);
398 sort($pri_keys, SORT_NUMERIC);
403 (!is_array($filters))) {
406 foreach ($pri_keys as $pri) {
423 foreach ($pri_keys as $priority_value) {
424 $service_obj_list = $this->serviceList[$priority_value];
426 foreach ($service_obj_list as $service) {
430 foreach ($filters as $filter) {
432 if (call_user_func_array($filter, array(&$service))) {
436 $pri = $service->getPriority();
441 if (!array_key_exists($pri, $filtered)) {
442 $filtered[$pri] = array();
445 $filtered[$pri][] = $service;
452 ($matches == count($filters))) {
454 $pri = $service->getPriority();
459 if (!array_key_exists($pri, $filtered)) {
460 $filtered[$pri] = array();
462 $filtered[$pri][] = $service;
467 $pri_keys = array_keys($filtered);
468 sort($pri_keys, SORT_NUMERIC);
471 foreach ($pri_keys as $pri) {
const SERVICES_YADIS_MATCH_ANY
This match mode means a given service must match ANY filters (at least one) passed to the Auth_Yadis_...
Auth_Yadis_getXRDExpiration($xrd_element, $default=null)
Auth_Yadis_array_scramble($arr)
private
Auth_Yadis_Service()
Creates an empty service object.
static parseXRDS($xml_string, $extra_ns_map=null)
Parse an XML string (XRDS document) and return either a Auth_Yadis_XRDS object or null...
const Auth_Yadis_XMLNS_XRDS
XRDS XML namespace.
getURIs()
Return the URIs in the "URI" elements, if any, of this Service element.
getPriority()
Returns the "priority" attribute value of this <Service> element, if the attribute is present...
_parse()
Creates the service list using nodes from the XRDS XML document.
const SERVICES_YADIS_MAX_PRIORITY
The priority value used for service elements with no priority specified.
Auth_Yadis_getXMLParser()
Returns an instance of a Auth_Yadis_XMLParser subclass based on the availability of PHP extensions fo...
getElements($name)
Used to get XML elements from this object's <Service> element.
const SERVICES_YADIS_MATCH_ALL
Require the XPath implementation.
const Auth_Yadis_XMLNS_XRD_2_0
XRD XML namespace.
getTypes()
Return the URIs in the "Type" elements, if any, of this Service element.
_addService($priority, $service)
private
services($filters=null, $filter_mode=SERVICES_YADIS_MATCH_ANY)
Returns a list of service objects which correspond to <Service> elements in the XRDS XML document for...
Auth_Yadis_XRDS($xmlParser, $xrdNodes)
Instantiate a Auth_Yadis_XRDS object.