encode() public method

public encode ( $input )
Exemplo n.º 1
1
 /**
  * Check if the email is valid.
  *
  * @param string $email
  * @param bool   $useExampleDomainCheck
  * @param bool   $useTypoInDomainCheck
  * @param bool   $useTemporaryDomainCheck
  * @param bool   $useDnsCheck (do not use, if you don't need it)
  *
  * @return bool
  */
 public static function isValid($email, $useExampleDomainCheck = false, $useTypoInDomainCheck = false, $useTemporaryDomainCheck = false, $useDnsCheck = false)
 {
     // must be a string
     if (!is_string($email)) {
         return false;
     }
     // make sure string length is limited to avoid DOS attacks
     $emailStringLength = strlen($email);
     if ($emailStringLength >= 320 || $emailStringLength <= 2) {
         return false;
     }
     unset($emailStringLength);
     $email = str_replace(array('.', '@'), array('.', '@'), $email);
     if (strpos($email, '@') === false || strpos($email, '.') === false && strpos($email, ':') === false) {
         return false;
     }
     if (!preg_match('/^(?<local>.*<?)(?:.*)@(?<domain>.*)(?:>?)$/', $email, $parts)) {
         return false;
     } else {
         $local = $parts['local'];
         $domain = $parts['domain'];
         // Escaped spaces are allowed in the "local"-part.
         $local = str_replace('\\ ', '', $local);
         // Spaces in quotes e.g. "firstname lastname"@foo.bar are also allowed in the "local"-part.
         $quoteHelperForIdn = false;
         if (preg_match('/^"(?<inner>[^"]*)"$/mU', $local, $parts)) {
             $quoteHelperForIdn = true;
             $local = trim(str_replace($parts['inner'], str_replace(' ', '', $parts['inner']), $local), '"');
         }
         if (strpos($local, ' ') !== false || strpos($local, '".') !== false) {
             return false;
         }
         if (function_exists('idn_to_ascii') && UTF8::max_chr_width($email) <= 3) {
             $localTmp = idn_to_ascii($local);
             if ($localTmp) {
                 $local = $localTmp;
             }
             unset($localTmp);
             $domainTmp = idn_to_ascii($domain);
             if ($domainTmp) {
                 $domain = $domainTmp;
             }
             unset($domainTmp);
         } else {
             static $punycode = null;
             if ($punycode === null) {
                 $punycode = new Punycode();
             }
             $local = $punycode->encode($local);
             $domain = $punycode->encode($domain);
         }
         if ($quoteHelperForIdn === true) {
             $local = '"' . $local . '"';
         }
         $email = $local . '@' . $domain;
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             return false;
         } else {
             $valid = true;
         }
         if ($useExampleDomainCheck === true && self::isExampleDomain($domain) === true) {
             return false;
         }
         if ($useTypoInDomainCheck === true && self::isTypoInDomain($domain) === true) {
             return false;
         }
         if ($useTemporaryDomainCheck === true && self::isTemporaryDomain($domain) === true) {
             return false;
         }
         if ($useDnsCheck === true && self::isDnsError($domain) === true) {
             return false;
         }
     }
     return $valid;
 }
Exemplo n.º 2
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);
 }
 public function query($dmName, $force = false)
 {
     //'http://reports.internic.net/cgi/whois?whois_nic=baidu.com&type=domain';
     $curl = new Curl();
     $curl->setReferer($this->refererUrl);
     $Punycode = new Punycode();
     $page = $curl->get($this->url, array('whois_nic' => $Punycode->encode($dmName), 'type' => 'domain'));
     return $this->parse($page);
 }
 public function query($dmName, $force = false)
 {
     //'https://whois.cnnic.net.cn/WhoisServlet?queryType=Domain&domain=teqhost.cn';
     $curl = new Curl();
     $curl->setReferer($this->refererUrl);
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     $Punycode = new Punycode();
     $page = $curl->get($this->url, array('domain' => $Punycode->encode($dmName), 'queryType' => 'Domain'));
     return $this->parse($page);
 }
Exemplo n.º 5
0
 /**
  * Extracts lower-case ASCII root domain from URL if it is available and valid, returns false otherwise
  *
  * @param string $url
  * @return string|bool
  */
 public static function getRootDomain($url)
 {
     $parsed = self::parseUrl($url);
     if (isset($parsed['rootdomain']) && !empty($parsed['rootdomain'])) {
         $punycode = new Punycode();
         $rootDomain = $punycode->encode($parsed['rootdomain']);
         return filter_var('http://' . $rootDomain, FILTER_VALIDATE_URL) ? strtolower($rootDomain) : false;
     }
     return false;
 }
Exemplo n.º 6
0
 public function punycode(Request $request, Texts $textsModel, functions $functions)
 {
     $Punycode = new Punycode();
     $method = $request->input('method');
     $source = $request->input('source');
     if ($method == '') {
         $method = 'to_puny';
     }
     if ($method == "to_puny") {
         $res = $Punycode->encode($source);
     } else {
         $res = $Punycode->decode($source);
     }
     $langLinks = $functions->giveLangLinks($request->url());
     $params = $textsModel->getLocaleOf('punicode');
     return view('indexuse', ['params' => $params, 'res' => $res, 'source' => $source, 'method' => $method, 'langLinks' => $langLinks]);
 }
Exemplo n.º 7
0
 /**
  * Checks an URL for validity, and punycode encode the returned component.
  *
  * @param string $url
  * @param int    $component
  *
  * @return string|false
  */
 private static function parseUrl($url, $component)
 {
     if (!isset(self::$cache[$url]['url'])) {
         // Strip protocol
         $scheme = parse_url($url, PHP_URL_SCHEME);
         $url = str_replace($scheme . '://', '', $url);
         $url = str_replace($scheme . ':', '', $url);
         // Punycode encode domain
         $host = parse_url('http://' . $url, PHP_URL_HOST);
         $punycode = new Punycode();
         $url = str_replace($host, $punycode->encode($host), $url);
         // Add back normalized protocol
         $url = 'http://' . $url;
         // Remove all illegal characters from a url
         $url = filter_var($url, FILTER_SANITIZE_URL);
         // Sanity check
         if (($check = filter_var($url, FILTER_VALIDATE_URL)) === false) {
             $url = false;
         }
         self::$cache[$url]['url'] = $url;
     }
     return parse_url(strtolower(self::$cache[$url]['url']), $component);
 }
Exemplo n.º 8
0
 protected function isValidHostPattern(array $data)
 {
     $data = explode($this->delimiter, $this->punycode->encode(implode($this->delimiter, $data)));
     $res = preg_grep('/^[0-9a-z]([0-9a-z-]{0,61}[0-9a-z])?$/i', $data, PREG_GREP_INVERT);
     return 0 == count($res);
 }
Exemplo n.º 9
0
            }
            $slds = empty($key) ? '' : '.' . $key . $sep;
            foreach ($value as $k => $v) {
                $glued = glue($k . (empty($key) ? '' : '.' . $key), $v, $sep);
                if ($glued === false) {
                    $slds .= 'HAI';
                } else {
                    $slds .= !empty($glued) ? $glued : '';
                }
            }
            return $slds;
        } else {
            return '.' . $key . $sep;
        }
    }
    $tlds = explode($sep, glue('', (array) $publicSuffixList, $sep));
}
// Edge case where a roottld is also on blocklist
foreach ($tlds as $k => $tld) {
    if (Nabble\SemaltBlocker\Blocker::isUrlOnBlocklist('http://www.' . $tld)) {
        unset($tlds[$k]);
    }
}
$tldsString = trim(implode($sep, $tlds), $sep);
$tldsString = $punycode->encode(html_entity_decode($tldsString));
$domainParserContents = file_get_contents($domainParserFile);
$regex = '/private static \\$suffixList = .*;/';
$domainParserContents = preg_replace($regex, 'private static $suffixList = \'' . $tldsString . '\';', $domainParserContents);
file_put_contents($domainParserFile, $domainParserContents);
echo "Got " . count($tlds) . " root tld's, done.\n";
exit;