|
32 | 32 | //* This class is loaded automatically by the ispconfig framework. |
33 | 33 |
|
34 | 34 | class functions { |
35 | | - |
| 35 | + var $idn_converter = null; |
| 36 | + var $idn_converter_name = ''; |
36 | 37 |
|
37 | 38 | public function mail($to, $subject, $text, $from, $filepath = '', $filetype = 'application/pdf', $filename = '', $cc = '', $bcc = '', $from_name = '') { |
38 | 39 | global $app,$conf; |
@@ -310,6 +311,72 @@ public function intval($string, $force_numeric = false) { |
310 | 311 | return intval($string); |
311 | 312 | } |
312 | 313 | } |
| 314 | + |
| 315 | + /** IDN converter wrapper. |
| 316 | + * all converter classes should be placed in ISPC_CLASS_PATH.'/idn/' |
| 317 | + */ |
| 318 | + public function idn_encode($domain) { |
| 319 | + if($domain == '') return ''; |
| 320 | + if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded |
| 321 | + |
| 322 | + // get domain and user part if it is an email |
| 323 | + $user_part = false; |
| 324 | + if(strpos($domain, '@') !== false) { |
| 325 | + $user_part = substr($domain, 0, strrpos($domain, '@')); |
| 326 | + $domain = substr($domain, strrpos($domain, '@') + 1); |
| 327 | + } |
| 328 | + |
| 329 | + if(function_exists('idn_to_ascii')) { |
| 330 | + $domain = idn_to_ascii($domain); |
| 331 | + } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { |
| 332 | + /* use idna class: |
| 333 | + * @author Matthias Sommerfeld <mso@phlylabs.de> |
| 334 | + * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de |
| 335 | + * @version 0.8.0 2011-03-11 |
| 336 | + */ |
| 337 | + |
| 338 | + if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') { |
| 339 | + include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); |
| 340 | + $this->idn_converter = new idna_convert(array('idn_version' => 2008)); |
| 341 | + $this->idn_converter_name = 'idna_convert.class'; |
| 342 | + } |
| 343 | + $domain = $this->idn_converter->encode($domain); |
| 344 | + } |
| 345 | + |
| 346 | + if($user_part !== false) return $user_part . '@' . $domain; |
| 347 | + else return $domain; |
| 348 | + } |
| 349 | + |
| 350 | + public function idn_decode($domain) { |
| 351 | + if($domain == '') return ''; |
| 352 | + if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee decoded |
| 353 | + |
| 354 | + // get domain and user part if it is an email |
| 355 | + $user_part = false; |
| 356 | + if(strpos($domain, '@') !== false) { |
| 357 | + $user_part = substr($domain, 0, strrpos($domain, '@')); |
| 358 | + $domain = substr($domain, strrpos($domain, '@') + 1); |
| 359 | + } |
| 360 | + if(function_exists('idn_to_utf8')) { |
| 361 | + $domain = idn_to_utf8($domain); |
| 362 | + } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { |
| 363 | + /* use idna class: |
| 364 | + * @author Matthias Sommerfeld <mso@phlylabs.de> |
| 365 | + * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de |
| 366 | + * @version 0.8.0 2011-03-11 |
| 367 | + */ |
| 368 | + |
| 369 | + if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') { |
| 370 | + include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); |
| 371 | + $this->idn_converter = new idna_convert(array('idn_version' => 2008)); |
| 372 | + $this->idn_converter_name = 'idna_convert.class'; |
| 373 | + } |
| 374 | + $domain = $this->idn_converter->decode($domain); |
| 375 | + } |
| 376 | + |
| 377 | + if($user_part !== false) return $user_part . '@' . $domain; |
| 378 | + else return $domain; |
| 379 | + } |
313 | 380 |
|
314 | 381 | } |
315 | 382 |
|
|
0 commit comments