Replace idna_convert with PHP native functions and true/punycode

This commit is contained in:
Kijin Sung 2016-01-13 15:46:41 +09:00
parent 192e81620d
commit 9da3653fcd
9 changed files with 34 additions and 4743 deletions

View file

@ -1199,16 +1199,42 @@ class Context
return $obj->str;
}
/**
* Encode UTF-8 domain into IDNA (punycode)
*
* @param string $domain Domain to convert
* @return string Converted string
*/
public static function encodeIdna($domain)
{
if(function_exists('idn_to_ascii'))
{
return idn_to_ascii($domain);
}
else
{
$encoder = new TrueBV\Punycode();
return $encoder->encode($domain);
}
}
/**
* Convert IDNA (punycode) domain into UTF-8
*
* @param string $domain Domain to convert
* @return string Converted string
*/
public static function decodeIdna($domain)
{
if(strpos($domain, 'xn--') !== FALSE)
if(function_exists('idn_to_utf8'))
{
require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php');
$IDN = new idna_convert(array('idn_version' => 2008));
$domain = $IDN->decode($domain);
return idn_to_utf8($domain);
}
else
{
$decoder = new TrueBV\Punycode();
return $decoder->decode($domain);
}
return $domain;
}
/**