Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Yadis

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /openid/Services/Yadis/XRI.php

Documentation is available at XRI.php

  1. <?php
  2.  
  3. /**
  4.  * Routines for XRI resolution.
  5.  *
  6.  * @package Yadis
  7.  * @author JanRain, Inc. <[email protected]>
  8.  * @copyright 2005 Janrain, Inc.
  9.  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  10.  */
  11.  
  12. require_once 'Services/Yadis/Misc.php';
  13. require_once 'Services/Yadis/Yadis.php';
  14. require_once 'Auth/OpenID.php';
  15.  
  16. $DEFAULT_PROXY 'http://proxy.xri.net/';
  17. $XRI_AUTHORITIES array('!''=''@''+''$''(');
  18.  
  19. $parts array();
  20. foreach (array_merge($__UCSCHAR$__IPRIVATEas $pair{
  21.     list($m$n$pair;
  22.     $parts[sprintf("%s-%s"chr($m)chr($n));
  23. }
  24.  
  25. $_escapeme_re sprintf('/[%s]/'implode(''$parts));
  26. $_xref_re '/\((.*?)\)/';
  27.  
  28. function Services_Yadis_identifierScheme($identifier)
  29. {
  30.     global $XRI_AUTHORITIES;
  31.  
  32.     if (_startswith($identifier'xri://'||
  33.         (in_array($identifier[0]$XRI_AUTHORITIES))) {
  34.         return "XRI";
  35.     else {
  36.         return "URI";
  37.     }
  38. }
  39.  
  40. {
  41.     if (!_startswith($xri'xri://')) {
  42.         $xri 'xri://' $xri;
  43.     }
  44.  
  45.     return Services_Yadis_escapeForIRI($xri);
  46. }
  47.  
  48. function _escape_xref($xref_match)
  49. {
  50.     $xref $xref_match[0];
  51.     $xref str_replace('/''%2F'$xref);
  52.     $xref str_replace('?''%3F'$xref);
  53.     $xref str_replace('#''%23'$xref);
  54.     return $xref;
  55. }
  56.  
  57. {
  58.     global $_xref_re;
  59.  
  60.     $xri str_replace('%''%25'$xri);
  61.     $xri preg_replace_callback($_xref_re'_escape_xref'$xri);
  62.     return $xri;
  63. }
  64.  
  65. {
  66. }
  67.  
  68. function Services_Yadis_iriToURI($iri)
  69. {
  70.     if (1{
  71.         return $iri;
  72.     else {
  73.         global $_escapeme_re;
  74.         // According to RFC 3987, section 3.1, "Mapping of IRIs to URIs"
  75.         return preg_replace_callback($_escapeme_re,
  76.                                      '_pct_escape_unicode'$iri);
  77.     }
  78. }
  79.  
  80.  
  81. function Services_Yadis_XRIAppendArgs($url$args)
  82. {
  83.     // Append some arguments to an HTTP query.  Yes, this is just like
  84.     // OpenID's appendArgs, but with special seasoning for XRI
  85.     // queries.
  86.  
  87.     if (count($args== 0{
  88.         return $url;
  89.     }
  90.  
  91.     // Non-empty array; if it is an array of arrays, use multisort;
  92.     // otherwise use sort.
  93.     if (array_key_exists(0$args&&
  94.         is_array($args[0])) {
  95.         // Do nothing here.
  96.     else {
  97.         $keys array_keys($args);
  98.         sort($keys);
  99.         $new_args array();
  100.         foreach ($keys as $key{
  101.             $new_args[array($key$args[$key]);
  102.         }
  103.         $args $new_args;
  104.     }
  105.  
  106.     // According to XRI Resolution section "QXRI query parameters":
  107.     //
  108.     // "If the original QXRI had a null query component (only a
  109.     //  leading question mark), or a query component consisting of
  110.     //  only question marks, one additional leading question mark MUST
  111.     //  be added when adding any XRI resolution parameters."
  112.     if (strpos(rtrim($url'?')'?'!== false{
  113.         $sep '&';
  114.     else {
  115.         $sep '?';
  116.     }
  117.  
  118.     return $url $sep Auth_OpenID::httpBuildQuery($args);
  119. }
  120.  
  121. function Services_Yadis_providerIsAuthoritative($providerID$canonicalID)
  122. {
  123.     $lastbang strrpos($canonicalID'!');
  124.     $p substr($canonicalID0$lastbang);
  125.     return $p == $providerID;
  126. }
  127.  
  128. {
  129.     global $XRI_AUTHORITIES;
  130.  
  131.     // Return the root authority for an XRI.
  132.  
  133.     $root null;
  134.  
  135.     if (_startswith($xri'xri://')) {
  136.         $xri substr($xri6);
  137.     }
  138.  
  139.     $authority explode('/'$xri2);
  140.     $authority $authority[0];
  141.     if ($authority[0== '('{
  142.         // Cross-reference.
  143.         // XXX: This is incorrect if someone nests cross-references so
  144.         //   there is another close-paren in there.  Hopefully nobody
  145.         //   does that before we have a real xriparse function.
  146.         //   Hopefully nobody does that *ever*.
  147.         $root substr($authority0strpos($authority')'1);
  148.     else if (in_array($authority[0]$XRI_AUTHORITIES)) {
  149.         // Other XRI reference.
  150.         $root $authority[0];
  151.     else {
  152.         // IRI reference.
  153.         $_segments explode("!"$authority);
  154.         $segments array();
  155.         foreach ($_segments as $s{
  156.             $segments array_merge($segmentsexplode("*"$s));
  157.         }
  158.         $root $segments[0];
  159.     }
  160.  
  161.     return Services_Yadis_XRI($root);
  162. }
  163.  
  164. function Services_Yadis_XRI($xri)
  165. {
  166.     if (!_startswith($xri'xri://')) {
  167.         $xri 'xri://' $xri;
  168.     }
  169.     return $xri;
  170. }
  171.  
  172. function Services_Yadis_getCanonicalID($iname$xrds)
  173. {
  174.     // Returns FALSE or a canonical ID value.
  175.  
  176.     // Now nodes are in reverse order.
  177.     $xrd_list array_reverse($xrds->allXrdNodes);
  178.     $parser =$xrds->parser;
  179.     $node $xrd_list[0];
  180.  
  181.     $canonicalID_nodes $parser->evalXPath('xrd:CanonicalID'$node);
  182.  
  183.     if (!$canonicalID_nodes{
  184.         return false;
  185.     }
  186.  
  187.     $canonicalID $canonicalID_nodes[count($canonicalID_nodes1];
  188.     $canonicalID Services_Yadis_XRI($parser->content($canonicalID));
  189.  
  190.     $childID $canonicalID;
  191.  
  192.     for ($i 1$i count($xrd_list)$i++{
  193.         $xrd $xrd_list[$i];
  194.  
  195.         $parent_sought substr($childID0strrpos($childID'!'));
  196.         $parent_list array();
  197.  
  198.         foreach ($parser->evalXPath('xrd:CanonicalID'$xrdas $c{
  199.             $parent_list[Services_Yadis_XRI($parser->content($c));
  200.         }
  201.  
  202.         if (!in_array($parent_sought$parent_list)) {
  203.             // raise XRDSFraud.
  204.             return false;
  205.         }
  206.  
  207.         $childID $parent_sought;
  208.     }
  209.  
  210.     $root Services_Yadis_rootAuthority($iname);
  211.     if (!Services_Yadis_providerIsAuthoritative($root$childID)) {
  212.         // raise XRDSFraud.
  213.         return false;
  214.     }
  215.  
  216.     return $canonicalID;
  217. }
  218.  
  219. ?>

Documentation generated on Mon, 05 Mar 2007 21:33:12 +0000 by phpDocumentor 1.3.1