コード例 #1
0
 /**
  * Encode a domain to its Punycode version
  *
  * @param string $input Domain name in Unicode to be encoded
  *
  * @return string Punycode representation in ASCII
  */
 public function encode($input)
 {
     if ($this->idnSupport === true) {
         return idn_to_ascii($input);
     }
     return self::$punycode->encode($input);
 }
コード例 #2
0
 /**
  * Safely convert UTF-8 encoded domain name to ASCII
  * @param string $domainName  the UTF-8 encoded email
  * @return string
  */
 protected function idnToAscii($domainName)
 {
     if (extension_loaded('intl')) {
         return idn_to_ascii($domainName) ?: $domainName;
     }
     return $domainName;
 }
コード例 #3
0
 /**
  * @param Field $field
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     $emailValid = filter_var($fieldValue, FILTER_VALIDATE_EMAIL);
     if ($emailValid === false) {
         return false;
     }
     if ($this->checkMx === false) {
         return true;
     }
     $domain = substr($fieldValue, strrpos($fieldValue, '@') + 1);
     $mxRecords = array();
     if (getmxrr(idn_to_ascii($domain), $mxRecords) === true) {
         return true;
     }
     // Port 25 fallback check if there's no MX record
     $aRecords = dns_get_record($domain, DNS_A);
     if (count($aRecords) <= 0) {
         return false;
     }
     $connection = @fsockopen($aRecords[0]['ip'], 25);
     if (is_resource($connection) === true) {
         fclose($connection);
         return true;
     }
     return false;
 }
コード例 #4
0
 private function santise()
 {
     foreach ($this->domains as $key => $domain) {
         // Add IND support
         $idnDomain = idn_to_ascii($domain);
         if ($idnDomain === false) {
             continue;
         }
         // Validates domain as URL (according to » @link http://www.faqs.org/rfcs/rfc2396)
         if (!filter_var('http://' . idn_to_ascii($idnDomain) . '/', FILTER_VALIDATE_URL)) {
             continue;
         }
         // Replace *.example.com with just example.com
         if (strpos($domain, '*.') === 0) {
             $domain = substr($domain, 2);
         }
         // Doesn't handle wild cards yet.
         if (strpos($domain, '*') !== false) {
             continue;
         }
         // Minimum Length
         // x.yy is sortest domain possible.
         if (empty($domain) || mb_strlen($domain) < 4) {
             continue;
         }
         // Trim and lowercase
         $this->domainsProcessed[] = trim(strtolower($domain));
     }
     $this->domainsProcessedCount = count($this->domainsProcessed);
 }
コード例 #5
0
ファイル: Validate_helper.php プロジェクト: dreeye/helper
 /**
  * Valid Email
  *
  * @param   string
  * @return  bool
  */
 public static function isEmail($str)
 {
     if (function_exists('idn_to_ascii') && ($atpos = strpos($str, '@'))) {
         $str = substr($str, 0, ++$atpos) . idn_to_ascii(substr($str, $atpos));
     }
     return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
 }
コード例 #6
0
ファイル: DaemonConfigDNS.php プロジェクト: gOOvER/EasySCP
 /**
  * @return mixed
  */
 public static function CreatePDNSPass()
 {
     System_Daemon::debug('Starting "DaemonConfigDNS::createPDNSPass" subprocess.');
     $xml = simplexml_load_file(DaemonConfig::$cfg->{'CONF_DIR'} . '/tpl/EasySCP_Config_DNS.xml');
     System_Daemon::debug('Building the new pdns config file');
     $xml->{'PDNS_USER'} = 'powerdns';
     $xml->{'PDNS_PASS'} = DB::encrypt_data(DaemonCommon::generatePassword(18));
     $xml->{'HOSTNAME'} = idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'});
     $handle = fopen(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml', "wb");
     fwrite($handle, $xml->asXML());
     fclose($handle);
     DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640);
     // Create/Update Powerdns control user account if needed
     System_Daemon::debug('Adding the PowerDNS control user');
     $sql_param = array(':PDNS_USER' => $xml->{'PDNS_USER'}, ':PDNS_PASS' => DB::decrypt_data($xml->{'PDNS_PASS'}), ':HOSTNAME' => $xml->{'HOSTNAME'});
     $sql_query = "\n\t\t\tGRANT ALL PRIVILEGES ON powerdns.* TO :PDNS_USER@:HOSTNAME IDENTIFIED BY :PDNS_PASS;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
     DB::prepare($sql_query);
     DB::execute($sql_param)->closeCursor();
     $sql_param = array(':DATABASE_USER' => DaemonConfig::$cfg->DATABASE_USER, ':DATABASE_HOST' => idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'}));
     $sql_query = "\n\t\t\tGRANT ALL PRIVILEGES ON powerdns.* TO :DATABASE_USER@:DATABASE_HOST;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
     DB::prepare($sql_query);
     DB::execute($sql_param)->closeCursor();
     System_Daemon::debug('Finished "DaemonConfigDNS::createPDNSPass" subprocess.');
     return true;
 }
コード例 #7
0
ファイル: Email.php プロジェクト: mollux/civicrm-packages
 /**
  * Validates an email address
  *
  * @param     string    $email          Email address
  * @param     boolean   $checkDomain    True if dns check should be performed
  * @access    public
  * @return    boolean   true if email is valid
  */
 function validate($email, $checkDomain = false)
 {
     if (function_exists('idn_to_ascii')) {
         if ($parts = explode('@', $email)) {
             if (sizeof($parts) == 2) {
                 foreach ($parts as &$part) {
                     $part = idn_to_ascii($part);
                 }
                 $email = implode('@', $parts);
             }
         }
     }
     // Fix for bug #10799: add 'D' modifier to regex
     if (preg_match($this->regex . 'D', $email)) {
         if ($checkDomain && function_exists('checkdnsrr')) {
             $tokens = explode('@', $email);
             if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
                 return true;
             }
             return false;
         }
         return true;
     }
     return false;
 }
コード例 #8
0
ファイル: Punycode.php プロジェクト: bitbybit/avdetect
 public static function encodeHostName($hostname)
 {
     if (!self::is_valid_utf8($hostname)) {
         return $hostname;
         //invalid
     }
     if (function_exists('idn_to_ascii') && 0) {
         return idn_to_ascii($hostname);
         //php 5.3+
     }
     $old_encoding = mb_internal_encoding();
     mb_internal_encoding("UTF-8");
     $pieces = explode(".", self::mb_strtolower($hostname));
     $punycode_pieces = array();
     foreach ($pieces as $piece) {
         if (preg_match("/[\\x{80}-\\x{FFFF}]/u", $piece)) {
             $punycode_pieces[] = "xn--" . self::encode($piece);
         } else {
             if (preg_match('/^[a-z\\d][a-z\\d-]{0,62}$/i', $piece) && !preg_match('/-$/', $piece)) {
                 $punycode_pieces[] = $piece;
             } else {
                 mb_internal_encoding($old_encoding);
                 return $hostname;
                 //invalid domain
             }
         }
     }
     mb_internal_encoding($old_encoding);
     return implode(".", $punycode_pieces);
 }
コード例 #9
0
ファイル: EmailValidator.php プロジェクト: arogachev/yii2
 /**
  * @inheritdoc
  */
 protected function validateValue($value)
 {
     if (!is_string($value)) {
         $valid = false;
     } elseif (!preg_match('/^(?P<name>(?:"?([^"]*)"?\\s)?)(?:\\s+)?(?:(?P<open><?)((?P<local>.+)@(?P<domain>[^>]+))(?P<close>>?))$/i', $value, $matches)) {
         $valid = false;
     } else {
         if ($this->enableIDN) {
             $matches['local'] = idn_to_ascii($matches['local']);
             $matches['domain'] = idn_to_ascii($matches['domain']);
             $value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];
         }
         if (strlen($matches['local']) > 64) {
             // The maximum total length of a user name or other local-part is 64 octets. RFC 5322 section 4.5.3.1.1
             // http://tools.ietf.org/html/rfc5321#section-4.5.3.1.1
             $valid = false;
         } elseif (strlen($matches['local'] . '@' . $matches['domain']) > 254) {
             // There is a restriction in RFC 2821 on the length of an address in MAIL and RCPT commands
             // of 254 characters. Since addresses that do not fit in those fields are not normally useful, the
             // upper limit on address lengths should normally be considered to be 254.
             //
             // Dominic Sayers, RFC 3696 erratum 1690
             // http://www.rfc-editor.org/errata_search.php?eid=1690
             $valid = false;
         } else {
             $valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value);
             if ($valid && $this->checkDNS) {
                 $valid = checkdnsrr($matches['domain'], 'MX') || checkdnsrr($matches['domain'], 'A');
             }
         }
     }
     return $valid ? null : [$this->message, []];
 }
コード例 #10
0
ファイル: Rpc.php プロジェクト: gridguyz/multisite
 /**
  * Is domain available
  *
  * @param string $domain
  * @return bool
  */
 public function isDomainAvailable($domain, $values = null)
 {
     $domain = @idn_to_ascii($domain);
     if (empty($domain)) {
         return false;
     }
     $config = $this->getServiceLocator()->get('Config')['db'];
     if (!empty($config['defaultDomain']) && $domain == $config['defaultDomain']) {
         return false;
     }
     $parts = explode('.', $domain);
     if (count($parts) < 2) {
         return false;
     }
     if (is_object($values)) {
         $values = (array) $values;
     }
     if (!empty($values['id'])) {
         $excludeId = (int) $values['id'];
     } else {
         $excludeId = null;
     }
     $mapper = $this->getMapper();
     $domain = array_pop($parts);
     do {
         $domain = array_pop($parts) . '.' . $domain;
         if ($mapper->isDomainExists($domain, $excludeId)) {
             return false;
         }
     } while (!empty($parts));
     return true;
 }
コード例 #11
0
ファイル: domainhelper.inc.php プロジェクト: noumenia/aetolos
 /**
  * Convert IDN names and verify the validity and specification constraints
  * @param string $domainName Domain name
  * @return string
  */
 private function verifyDomainName($domainName)
 {
     Log::debug('Verify domain: ' . $domainName);
     // Since PHP does not support IDN domain names, convert to ASCII by default
     $domainName = strtolower(idn_to_ascii(trim($domainName)));
     // Validate domain name length, max length 253
     if (strlen($domainName) > 253) {
         Log::error('Domain name exceedes the max length of 253 characters: ' . $domainName);
         return false;
     }
     // Make sure there is at least one "dot"
     if (strpos($domainName, '.') === false) {
         Log::error('Domain name is missing a dot character: ' . $domainName);
         return false;
     }
     // Explode "dot" separated parts
     $parts = explode('.', $domainName);
     // Validate parts
     foreach ($parts as $p) {
         // Max length 63 characters
         if (strlen($p) > 63) {
             Log::error('A domain name part exceedes the mas length of 63 characters: ' . $p);
             return false;
         }
         // Validate characters
         if (preg_match('/^[-a-z0-9]+$/i', $p) !== 1) {
             Log::error('Invalid characters in the domain name part: ' . $p);
             return false;
         }
     }
     return $domainName;
 }
コード例 #12
0
 public function test_compose_withPunycodeHost_returnsValidURL()
 {
     $punycode = 'http://' . idn_to_ascii('piña.com');
     $expectedComposedUrl = 'http://xn--pia-8ma.com';
     $url = new UrlComposer($punycode);
     $this->assertEquals($expectedComposedUrl, $url->compose());
 }
コード例 #13
0
ファイル: HostProcessing.php プロジェクト: esperecyan/url
 /**
  * Return true if a domain is a valid domain.
  * @link https://url.spec.whatwg.org/#valid-domain URL Standard
  * @param string $domain A UTF-8 string.
  * @return boolean
  */
 public static function isValidDomain($domain)
 {
     $valid = mb_strlen($domain, 'UTF-8') <= self::PHP_IDN_HANDLEABLE_LENGTH;
     if ($valid) {
         $result = idn_to_ascii($domain, IDNA_USE_STD3_RULES | IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
         if (!is_string($result)) {
             $valid = false;
         }
     }
     if ($valid) {
         $domainNameLength = strlen($result);
         if ($domainNameLength < 1 || $domainNameLength > 253) {
             $valid = false;
         }
     }
     if ($valid) {
         foreach (explode('.', $result) as $label) {
             $labelLength = strlen($label);
             if ($labelLength < 1 || $labelLength > 63) {
                 $valid = false;
                 break;
             }
         }
     }
     if ($valid) {
         $result = idn_to_utf8($result, IDNA_USE_STD3_RULES, INTL_IDNA_VARIANT_UTS46, $idna_info);
         if ($idna_info['errors'] !== 0) {
             $valid = false;
         }
     }
     return $valid;
 }
コード例 #14
0
ファイル: Structure.php プロジェクト: gridguyz/multisite
 /**
  * Set domain
  *
  * @param string $domain
  * @return \MultisitePlatform\Model\Domain\Structure
  */
 public function setDomain($domain)
 {
     $domain = @idn_to_ascii($domain);
     if (!empty($domain)) {
         $this->domain = $domain;
     }
     return $this;
 }
コード例 #15
0
 function valid_email($address)
 {
     $patternselect = 'auto';
     //
     // Added by Ivan Tcholakov, 17-OCT-2015.
     if (function_exists('idn_to_ascii') && ($atpos = strpos($address, '@'))) {
         $address = substr($address, 0, ++$atpos) . idn_to_ascii(substr($address, $atpos));
     }
     //
     if (!$patternselect or $patternselect == 'auto') {
         //Check this constant first so it works when extension_loaded() is disabled by safe mode
         //Constant was added in PHP 5.2.4
         if (defined('PCRE_VERSION')) {
             //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
             if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
                 $patternselect = 'pcre8';
             } else {
                 $patternselect = 'pcre';
             }
         } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
             //Fall back to older PCRE
             $patternselect = 'pcre';
         } else {
             //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
             if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
                 $patternselect = 'php';
             } else {
                 $patternselect = 'noregex';
             }
         }
     }
     switch ($patternselect) {
         case 'pcre8':
             /**
              * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
              * @link http://squiloople.com/2009/12/20/email-address-validation/
              * @copyright 2009-2010 Michael Rushton
              * Feel free to use and redistribute this code. But please keep this copyright notice.
              */
             return (bool) preg_match('/^(?!(?>(?1)"?(?>\\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\\[ -~]|[^"])"?(?1)){65,}@)' . '((?>(?>(?>((?>(?>(?>\\x0D\\x0A)?[\\t ])+|(?>[\\t ]*\\x0D\\x0A)?[\\t ]+)?)(\\((?>(?2)' . '(?>[\\x01-\\x08\\x0B\\x0C\\x0E-\'*-\\[\\]-\\x7F]|\\\\[\\x00-\\x7F]|(?3)))*(?2)\\)))+(?2))|(?2))?)' . '([!#-\'*+\\/-9=?^-~-]+|"(?>(?2)(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\x7F]))*' . '(?2)")(?>(?1)\\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' . '(?>(?1)\\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' . '|(?!(?:.*[a-f0-9][:\\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' . '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\\.(?9)){3}))\\])(?1)$/isD', $address);
         case 'pcre':
             //An older regex that doesn't need a recent PCRE
             return (bool) preg_match('/^(?!(?>"?(?>\\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\\[ -~]|[^"])"?){65,}@)(?>' . '[!#-\'*+\\/-9=?^-~-]+|"(?>(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\xFF]))*")' . '(?>\\.(?>[!#-\'*+\\/-9=?^-~-]+|"(?>(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\xFF]))*"))*' . '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\\.(?![a-z0-9-]{64,})' . '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' . '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' . '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' . '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' . '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\\])$/isD', $address);
         case 'html5':
             /**
              * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
              * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
              */
             return (bool) preg_match('/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' . '[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address);
         case 'noregex':
             //No PCRE! Do something _very_ approximate!
             //Check the address is 3 chars or longer and contains an @ that's not the first or last char
             return strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1;
         case 'php':
         default:
             return (bool) filter_var($address, FILTER_VALIDATE_EMAIL);
     }
 }
コード例 #16
0
 function validate_email($variable, $options = null)
 {
     if (($pos = strrpos($variable, '@')) === false) {
         return false;
     }
     $local_part = substr($variable, 0, $pos);
     $domain_part = substr($variable, $pos + 1);
     return (bool) filter_var($local_part . '@' . idn_to_ascii($domain_part), FILTER_VALIDATE_EMAIL, $options);
 }
コード例 #17
0
 public function create_identity($p)
 {
     $rcmail = rcmail::get_instance();
     // prefs are set in create_user()
     if ($this->prefs) {
         if ($this->prefs['full_name']) {
             $p['record']['name'] = $this->prefs['full_name'];
         }
         if (($this->identities_level == 0 || $this->identities_level == 2) && $this->prefs['email_address']) {
             $p['record']['email'] = $this->prefs['email_address'];
         }
         if ($this->prefs['___signature___']) {
             $p['record']['signature'] = $this->prefs['___signature___'];
         }
         if ($this->prefs['reply_to']) {
             $p['record']['reply-to'] = $this->prefs['reply_to'];
         }
         if (($this->identities_level == 0 || $this->identities_level == 1) && isset($this->prefs['identities']) && $this->prefs['identities'] > 1) {
             for ($i = 1; $i < $this->prefs['identities']; $i++) {
                 unset($ident_data);
                 $ident_data = array('name' => '', 'email' => '');
                 // required data
                 if ($this->prefs['full_name' . $i]) {
                     $ident_data['name'] = $this->prefs['full_name' . $i];
                 }
                 if ($this->identities_level == 0 && $this->prefs['email_address' . $i]) {
                     $ident_data['email'] = $this->prefs['email_address' . $i];
                 } else {
                     $ident_data['email'] = $p['record']['email'];
                 }
                 if ($this->prefs['reply_to' . $i]) {
                     $ident_data['reply-to'] = $this->prefs['reply_to' . $i];
                 }
                 if ($this->prefs['___sig' . $i . '___']) {
                     $ident_data['signature'] = $this->prefs['___sig' . $i . '___'];
                 }
                 // insert identity
                 $identid = $rcmail->user->insert_identity($ident_data);
             }
         }
         // copy address book
         $contacts = $rcmail->get_address_book(null, true);
         if ($contacts && count($this->abook)) {
             foreach ($this->abook as $rec) {
                 // #1487096 handle multi-address and/or too long items
                 $rec['email'] = array_shift(explode(';', $rec['email']));
                 if (check_email(idn_to_ascii($rec['email']))) {
                     $rec['email'] = idn_to_utf8($rec['email']);
                     $contacts->insert($rec, true);
                 }
             }
         }
         // mark identity as complete for following hooks
         $p['complete'] = true;
     }
     return $p;
 }
コード例 #18
0
ファイル: Normaliser.php プロジェクト: sintoris/Known
 /**
  * Host is case-insensitive, normalise to lowercase and to ascii version of
  * IDN format
  */
 private function normaliseHost()
 {
     if (isset($this->parts['host'])) {
         $host = idn_to_ascii($this->parts['host']->get());
         $host = trim($host);
         $host = strtolower($host);
         $this->parts['host']->set($host);
     }
 }
コード例 #19
0
ファイル: Validator.php プロジェクト: africc/php-epp2
 /**
  * returns true if email is usuable
  * @param string $email
  */
 public static function isEmail($email)
 {
     $pos = strrpos($email, '@');
     if ($pos === false) {
         return false;
     }
     $ascii_email = substr($email, 0, $pos) . '@' . idn_to_ascii(substr($email, $pos + 1), 0, INTL_IDNA_VARIANT_2003);
     return filter_var($ascii_email, FILTER_VALIDATE_EMAIL);
 }
コード例 #20
0
ファイル: Host.php プロジェクト: sintoris/Known
 /**
  * 
  * @param \webignition\Url\Host\Host $comparator
  * @param array $excludeParts
  * @return boolean
  */
 public function isEquivalentTo(Host $comparator, $excludeParts = array())
 {
     $thisHost = new Host(idn_to_ascii((string) $this));
     $comparatorHost = new Host(idn_to_ascii((string) $comparator));
     if (!is_array($excludeParts) || count($excludeParts) == 0) {
         return $thisHost->equals($comparatorHost);
     }
     $thisParts = $this->excludeParts($thisHost->getParts(), $excludeParts);
     $comparatorParts = $this->excludeParts($comparatorHost->getParts(), $excludeParts);
     return $thisParts == $comparatorParts;
 }
コード例 #21
0
ファイル: Idna.php プロジェクト: x59/horde-idna
 /**
  * @throws Horde_Idna_Exception
  */
 public static function encode($data)
 {
     switch ($backend = static::_getBackend()) {
         case 'INTL':
             return idn_to_ascii($data);
         case 'INTL_UTS46':
             return idn_to_ascii($data, 0, INTL_IDNA_VARIANT_UTS46);
         default:
             return $backend->encode($data);
     }
 }
コード例 #22
0
 function convert_to_ascii($url)
 {
     $parts = parse_url($url);
     if (!isset($parts['host'])) {
         return $url;
     }
     if (mb_detect_encoding($parts['host']) != 'ASCII') {
         $url = str_replace($parts['host'], idn_to_ascii($parts['host']), $url);
     }
     return $url;
 }
コード例 #23
0
ファイル: Email.php プロジェクト: arvici/framework
 /**
  * Execute assert on the field, in the data provided.
  *
  * @param array $data Full data array.
  * @param string $field Field Name.
  * @param array $options Optional options given at runtime.
  * @return bool
  *
  * @throws ValidationException
  */
 public function execute(&$data, $field, $options = array())
 {
     if (!isset($data[$field])) {
         return false;
     }
     $email = $data[$field];
     if (function_exists('idn_to_ascii')) {
         $email = idn_to_ascii($email);
     }
     return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
 }
コード例 #24
0
ファイル: Validator.php プロジェクト: goragod/kotchasan
 /**
  * ตรวจสอบความถูกของอีเมล์
  *
  * @param string $email
  * @return boolean คืนค่า true ถ้ารูปแบบอีเมล์ถูกต้อง
  *
  * @assert ('*****@*****.**') [==] true
  * @assert ('admin@localhost') [==] true
  * @assert ('ทดสอบ@localhost') [==] false
  */
 public static function email($email)
 {
     if (function_exists('idn_to_ascii') && preg_match('/(.*)@(.*)/', $email, $match)) {
         // โดเมนภาษาไทย
         $email = $match[1] . '@' . idn_to_ascii($match[2]);
     }
     if (preg_match('/^[a-zA-Z0-9\\._\\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $email)) {
         return true;
     } else {
         return false;
     }
 }
コード例 #25
0
ファイル: Url.php プロジェクト: ksst/kf
 protected function processValidationLogic($value)
 {
     /*
      * Note: filter_var() does not support IDNA.
      * The INTL extension provides the method idn_to_ascii().
      * It converts a multibyte URL to a punycode ASCII string.
      */
     if (extension_loaded('intl')) {
         $value = idn_to_ascii($value);
     }
     return filter_var($value, FILTER_VALIDATE_URL, $this->getOptions());
 }
コード例 #26
0
 /**
  * Convert idn to ascii Format
  * 
  * @param string $name
  * 
  * @return string
  */
 public static function convertIdnToAsciiFormat($name)
 {
     if (empty($name)) {
         return;
     }
     if (!function_exists('idn_to_ascii')) {
         \DBG::msg('Idn is not supported in this system.');
     } else {
         $name = idn_to_ascii($name);
     }
     return $name;
 }
コード例 #27
0
 /**
  * @param $address
  * @return bool
  */
 public static function urlAvailable($address)
 {
     if ($address == NULL) {
         return false;
     }
     $host = parse_url($address, PHP_URL_HOST);
     $address = mb_ereg_replace($host, idn_to_ascii($host), $address);
     $ch = curl_init($address);
     curl_setopt_array($ch, [CURLOPT_TIMEOUT => 5, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_RETURNTRANSFER => true, CURLOPT_NOBODY => true]);
     curl_exec($ch);
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     return $httpCode >= 200 && $httpCode < 300;
 }
コード例 #28
0
ファイル: InterWiki.php プロジェクト: logue/pukiwiki_adv
 public function __toString()
 {
     global $nofollow;
     $rel = 'external' . ($nofollow === TRUE) ? ' nofollow' : '';
     $target = empty($this->redirect) ? $this->name : $this->redirect . rawurlencode($this->name);
     $purl = parse_url($target);
     if (isset($purl['host']) && extension_loaded('intl')) {
         // Fix punycode URL
         $url = preg_replace('/' . $purl['host'] . '/', idn_to_ascii($purl['host']), $target);
     } else {
         $url = $target;
     }
     return parent::setLink($this->alias, $url, $this->name, $rel);
 }
コード例 #29
0
 /**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fldValue = $this->ignoreSurroundingSpaces ? trim($field->getValue()) : $field->getValue();
     $fldValue = preg_replace(array('@^[a-z]+://@i', '@^www\\.@i'), null, $fldValue);
     if (($lastPoint = strrpos($fldValue, '.')) === false) {
         return false;
     }
     if ($this->publicTld === true && strlen(substr($fldValue, $lastPoint + 1)) < 2) {
         return false;
     }
     return filter_var('http://' . idn_to_ascii($fldValue), FILTER_VALIDATE_URL) !== false;
 }
コード例 #30
0
ファイル: lib_rss.php プロジェクト: buggithubs/FreshRSS
function idn_to_puny($url)
{
    if (function_exists('idn_to_ascii')) {
        $parts = parse_url($url);
        if (!empty($parts['host'])) {
            $idn = $parts['host'];
            $puny = idn_to_ascii($idn);
            $pos = strpos($url, $idn);
            if ($pos !== false) {
                return substr_replace($url, $puny, $pos, strlen($idn));
            }
        }
    }
    return $url;
}