Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.0.10.0
- * @ Author : DeZender
- * @ Release on : 09.04.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class TLDExtract
- {
- const SCHEME_RE = '#^([a-zA-Z][a-zA-Z0-9+\\-.]*:)?//#';
- private $fetch;
- private $cacheFile;
- private $extractor;
- public function __construct($fetch = true, $cacheFile = '')
- {
- $this->fetch = $fetch;
- $this->cacheFile = (!empty($cacheFile) ? $cacheFile : dirname(__FILE__) . DIRECTORY_SEPARATOR . '.tld_set');
- }
- public function __invoke($url)
- {
- return $this->extract($url);
- }
- public function extract($url)
- {
- $host = $this->getHost($url);
- $extractor = $this->getTldExtractor();
- list($registeredDomain, $tld) = $extractor->extract($host);
- if (empty($tld) && $this->isIp($host)) {
- return new TLDExtractResult('', $host, '');
- }
- $lastDot = strrpos($registeredDomain, '.');
- if ($lastDot !== false) {
- $subdomain = substr($registeredDomain, 0, $lastDot);
- $domain = substr($registeredDomain, $lastDot + 1);
- }
- else {
- $subdomain = '';
- $domain = $registeredDomain;
- }
- return new TLDExtractResult($subdomain, $domain, $tld);
- }
- private function getHost($url)
- {
- $host = preg_replace('#^([a-zA-Z][a-zA-Z0-9+\\-.]*:)?//#', '', $url);
- list($host) = explode('/', $host, 2);
- $pieces = explode('@', $host, 2);
- if (count($pieces) == 2) {
- $host = $pieces[1];
- }
- $closingBracket = strrpos($host, ']');
- if ($this->startsWith($host, '[') && $closingBracket) {
- $host = substr($host, 0, $closingBracket + 1);
- }
- else {
- list($host) = explode(':', $host);
- }
- return $host;
- }
- private function getTldExtractor()
- {
- if ($this->extractor !== NULL) {
- return $this->extractor;
- }
- $serializedTlds = @file_get_contents($this->cacheFile);
- if (!empty($serializedTlds)) {
- $this->extractor = new PublicSuffixListTLDExtractor(unserialize($serializedTlds));
- return $this->extractor;
- }
- $tlds = [];
- if ($this->fetch) {
- $tlds = $this->fetchTldList();
- }
- if (empty($tlds)) {
- $snapshotFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.tld_set_snapshot';
- $serializedTlds = @file_get_contents($snapshotFile);
- if (!empty($serializedTlds)) {
- $this->extractor = new PublicSuffixListTLDExtractor(unserialize($serializedTlds));
- return $this->extractor;
- }
- }
- else {
- @file_put_contents($this->cacheFile, serialize($tlds));
- }
- $this->extractor = new PublicSuffixListTLDExtractor($tlds);
- return $this->extractor;
- }
- private function fetchTldList()
- {
- $page = $this->fetchPage('http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1');
- $tlds = [];
- if (!empty($page) && preg_match_all('@^(?P<tld>[.*!]*\\w[\\S]*)@um', $page, $matches)) {
- $tlds = array_fill_keys($matches['tld'], true);
- .......................................................................................
- ..................................................
- .....................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement