diff options
-rw-r--r-- | Services/Yadis/XRI.php | 46 | ||||
-rw-r--r-- | Services/Yadis/XRIRes.php | 4 |
2 files changed, 28 insertions, 22 deletions
diff --git a/Services/Yadis/XRI.php b/Services/Yadis/XRI.php index 6e58a03..a3c335a 100644 --- a/Services/Yadis/XRI.php +++ b/Services/Yadis/XRI.php @@ -13,24 +13,36 @@ require_once 'Services/Yadis/Misc.php'; require_once 'Services/Yadis/Yadis.php'; require_once 'Auth/OpenID.php'; -$DEFAULT_PROXY = 'http://proxy.xri.net/'; -$XRI_AUTHORITIES = array('!', '=', '@', '+', '$', '('); +function Services_Yadis_getDefaultProxy() +{ + return 'http://proxy.xri.net/'; +} -$parts = array(); -foreach (array_merge($__UCSCHAR, $__IPRIVATE) as $pair) { - list($m, $n) = $pair; - $parts[] = sprintf("%s-%s", chr($m), chr($n)); +function Services_Yadis_getXRIAuthorities() +{ + return array('!', '=', '@', '+', '$', '('); } -$_escapeme_re = sprintf('/[%s]/', implode('', $parts)); -$_xref_re = '/\((.*?)\)/'; +function Services_Yadis_getEscapeRE() +{ + $parts = array(); + foreach (array_merge($__UCSCHAR, $__IPRIVATE) as $pair) { + list($m, $n) = $pair; + $parts[] = sprintf("%s-%s", chr($m), chr($n)); + } -function Services_Yadis_identifierScheme($identifier) + return sprintf('/[%s]/', implode('', $parts)); +} + +function Services_Yadis_getXrefRE() { - global $XRI_AUTHORITIES; + return '/\((.*?)\)/'; +} +function Services_Yadis_identifierScheme($identifier) +{ if (_startswith($identifier, 'xri://') || - (in_array($identifier[0], $XRI_AUTHORITIES))) { + (in_array($identifier[0], Services_Yadis_getXRIAuthorities()))) { return "XRI"; } else { return "URI"; @@ -57,10 +69,9 @@ function _escape_xref($xref_match) function Services_Yadis_escapeForIRI($xri) { - global $_xref_re; - $xri = str_replace('%', '%25', $xri); - $xri = preg_replace_callback($_xref_re, '_escape_xref', $xri); + $xri = preg_replace_callback(Services_Yadis_getXrefRE(), + '_escape_xref', $xri); return $xri; } @@ -74,9 +85,8 @@ function Services_Yadis_iriToURI($iri) if (1) { return $iri; } else { - global $_escapeme_re; // According to RFC 3987, section 3.1, "Mapping of IRIs to URIs" - return preg_replace_callback($_escapeme_re, + return preg_replace_callback(Services_Yadis_getEscapeRE(), '_pct_escape_unicode', $iri); } } @@ -131,8 +141,6 @@ function Services_Yadis_providerIsAuthoritative($providerID, $canonicalID) function Services_Yadis_rootAuthority($xri) { - global $XRI_AUTHORITIES; - // Return the root authority for an XRI. $root = null; @@ -150,7 +158,7 @@ function Services_Yadis_rootAuthority($xri) // does that before we have a real xriparse function. // Hopefully nobody does that *ever*. $root = substr($authority, 0, strpos($authority, ')') + 1); - } else if (in_array($authority[0], $XRI_AUTHORITIES)) { + } else if (in_array($authority[0], Services_Yadis_getXRIAuthorities())) { // Other XRI reference. $root = $authority[0]; } else { diff --git a/Services/Yadis/XRIRes.php b/Services/Yadis/XRIRes.php index 5db35fc..b87cf04 100644 --- a/Services/Yadis/XRIRes.php +++ b/Services/Yadis/XRIRes.php @@ -6,12 +6,10 @@ require_once 'Services/Yadis/XRI.php'; class Services_Yadis_ProxyResolver { function Services_Yadis_ProxyResolver(&$fetcher, $proxy_url = null) { - global $DEFAULT_PROXY; - $this->fetcher =& $fetcher; $this->proxy_url = $proxy_url; if (!$this->proxy_url) { - $this->proxy_url = $DEFAULT_PROXY; + $this->proxy_url = Services_Yadis_getDefaultProxy(); } } |