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) {
 
  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) {