10 defined(
'JPATH_PLATFORM') or die;
12 JLoader::register('
idna_convert', JPATH_ROOT . '/libraries/idna_convert/idna_convert.class.php');
36 public static function toPunycode($utfString)
38 $idn =
new idna_convert;
40 return $idn->encode($utfString);
52 public static function fromPunycode($punycodeString)
54 $idn =
new idna_convert;
56 return $idn->decode($punycodeString);
69 public static function urlToPunycode($uri)
73 if (!isset($parsed[
'host']) || $parsed[
'host'] ==
'')
79 $host = $parsed[
'host'];
80 $hostExploded = explode(
'.', $host);
83 foreach ($hostExploded as $hostex)
85 $hostex = static::toPunycode($hostex);
86 $newhost .= $hostex .
'.';
89 $newhost = substr($newhost, 0, -1);
92 if (!empty($parsed[
'scheme']))
95 $newuri .= $parsed[
'scheme'] .
'://';
103 if (!empty($parsed[
'port']))
105 $newuri .=
':' . $parsed[
'port'];
108 if (!empty($parsed[
'path']))
110 $newuri .= $parsed[
'path'];
113 if (!empty($parsed[
'query']))
115 $newuri .=
'?' . $parsed[
'query'];
130 public static function urlToUTF8($uri)
139 if (!isset($parsed[
'host']) || $parsed[
'host'] ==
'')
145 $host = $parsed[
'host'];
146 $hostExploded = explode(
'.', $host);
149 foreach ($hostExploded as $hostex)
151 $hostex = self::fromPunycode($hostex);
152 $newhost .= $hostex .
'.';
155 $newhost = substr($newhost, 0, -1);
158 if (!empty($parsed[
'scheme']))
161 $newuri .= $parsed[
'scheme'] .
'://';
164 if (!empty($newhost))
169 if (!empty($parsed[
'port']))
171 $newuri .=
':' . $parsed[
'port'];
174 if (!empty($parsed[
'path']))
176 $newuri .= $parsed[
'path'];
179 if (!empty($parsed[
'query']))
181 $newuri .=
'?' . $parsed[
'query'];
197 public static function emailToPunycode($email)
199 $explodedAddress = explode(
'@', $email);
202 $newEmail = $explodedAddress[0];
204 if (!empty($explodedAddress[1]))
206 $domainExploded = explode(
'.', $explodedAddress[1]);
209 foreach ($domainExploded as $domainex)
211 $domainex = static::toPunycode($domainex);
212 $newdomain .= $domainex .
'.';
215 $newdomain = substr($newdomain, 0, -1);
216 $newEmail = $newEmail .
'@' . $newdomain;
232 public static function emailToUTF8($email)
234 $explodedAddress = explode(
'@', $email);
237 $newEmail = $explodedAddress[0];
239 if (!empty($explodedAddress[1]))
241 $domainExploded = explode(
'.', $explodedAddress[1]);
244 foreach ($domainExploded as $domainex)
246 $domainex = static::fromPunycode($domainex);
247 $newdomain .= $domainex .
'.';
250 $newdomain = substr($newdomain, 0, -1);
251 $newEmail = $newEmail .
'@' . $newdomain;