Esempio n. 1
0
 /**
  * Return the IDNA backend.
  *
  * @return mixed  IDNA backend (false if none available).
  */
 protected static function _getBackend()
 {
     if (!isset(self::$_backend)) {
         if (extension_loaded('intl')) {
             /* Only available in PHP > 5.4.0 */
             self::$_backend = defined('INTL_IDNA_VARIANT_UTS46') ? 'INTL_UTS46' : 'INTL';
         } else {
             self::$_backend = new Horde_Idna_Punycode();
         }
     }
     return self::$_backend;
 }
Esempio n. 2
0
 /**
  * @throws Horde_Idna_Exception
  */
 public function __get($name)
 {
     switch ($name) {
         case 'bare_address':
             return is_null($this->host) ? $this->mailbox : $this->mailbox . '@' . $this->host;
         case 'bare_address_idn':
             $personal = $this->_personal;
             $this->_personal = null;
             $res = $this->encoded;
             $this->_personal = $personal;
             return $res;
         case 'eai':
             return is_null($this->mailbox) ? false : Horde_Mime::is8bit($this->mailbox);
         case 'encoded':
             return $this->writeAddress(true);
         case 'host':
             return $this->_host;
         case 'host_idn':
             return Horde_Idna::encode($this->_host);
         case 'label':
             return is_null($this->personal) ? $this->bare_address : $this->_personal;
         case 'personal':
             return strcasecmp($this->_personal, $this->bare_address) === 0 ? null : $this->_personal;
         case 'personal_encoded':
             return Horde_Mime::encode($this->personal);
         case 'valid':
             return (bool) strlen($this->mailbox);
     }
 }
Esempio n. 3
0
 /**
  */
 public function callback($match)
 {
     $href = $orig_href = $match[0];
     if (strpos($match[2], ':') === false) {
         $href = 'http://' . $href;
     }
     if ($this->_params['callback']) {
         $href = call_user_func($this->_params['callback'], $href);
     }
     $href = htmlspecialchars($href);
     $class = $this->_params['class'];
     if (!empty($class)) {
         $class = ' class="' . $class . '"';
     }
     $target = $this->_params['target'];
     if (!empty($target)) {
         $target = ' target="' . $target . '"';
     }
     $decoded = $orig_href;
     try {
         if (strlen($host = $this->_parseurl($orig_href, PHP_URL_HOST))) {
             $decoded = substr_replace($orig_href, Horde_Idna::decode($host), strpos($orig_href, $host), strlen($host));
         }
     } catch (Horde_Idna_Exception $e) {
     } catch (InvalidArgumentException $e) {
     }
     $replacement = '<a href="' . $href . '"' . ($this->_params['nofollow'] ? ' rel="nofollow"' : '') . $target . $class . '>' . htmlspecialchars($decoded) . '</a>';
     if (!empty($this->_params['noprefetch'])) {
         $replacement = '<meta http-equiv="x-dns-prefetch-control" value="off" />' . $replacement . '<meta http-equiv="x-dns-prefetch-control" value="on" />';
     }
     if ($this->_params['encode']) {
         $replacement = chr(0) . chr(0) . chr(0) . base64_encode($replacement) . chr(0) . chr(0) . chr(0);
     }
     return $replacement;
 }
Esempio n. 4
0
 /**
  * @dataProvider domainNamesProvider
  */
 public function testDecode($decoded, $encoded)
 {
     $idna = new Horde_Idna();
     $this->assertEquals($decoded, $idna->decode($encoded));
 }