Advertisement
Guest User

Untitled

a guest
Apr 16th, 2020
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.0.10.0
  8. * @ Author : DeZender
  9. * @ Release on : 09.04.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class TLDExtract
  15. {
  16. const SCHEME_RE = '#^([a-zA-Z][a-zA-Z0-9+\\-.]*:)?//#';
  17.  
  18. private $fetch;
  19. private $cacheFile;
  20. private $extractor;
  21.  
  22. public function __construct($fetch = true, $cacheFile = '')
  23. {
  24. $this->fetch = $fetch;
  25. $this->cacheFile = (!empty($cacheFile) ? $cacheFile : dirname(__FILE__) . DIRECTORY_SEPARATOR . '.tld_set');
  26. }
  27.  
  28. public function __invoke($url)
  29. {
  30. return $this->extract($url);
  31. }
  32.  
  33. public function extract($url)
  34. {
  35. $host = $this->getHost($url);
  36. $extractor = $this->getTldExtractor();
  37. list($registeredDomain, $tld) = $extractor->extract($host);
  38. if (empty($tld) && $this->isIp($host)) {
  39. return new TLDExtractResult('', $host, '');
  40. }
  41.  
  42. $lastDot = strrpos($registeredDomain, '.');
  43.  
  44. if ($lastDot !== false) {
  45. $subdomain = substr($registeredDomain, 0, $lastDot);
  46. $domain = substr($registeredDomain, $lastDot + 1);
  47. }
  48. else {
  49. $subdomain = '';
  50. $domain = $registeredDomain;
  51. }
  52.  
  53. return new TLDExtractResult($subdomain, $domain, $tld);
  54. }
  55.  
  56. private function getHost($url)
  57. {
  58. $host = preg_replace('#^([a-zA-Z][a-zA-Z0-9+\\-.]*:)?//#', '', $url);
  59. list($host) = explode('/', $host, 2);
  60. $pieces = explode('@', $host, 2);
  61.  
  62. if (count($pieces) == 2) {
  63. $host = $pieces[1];
  64. }
  65.  
  66. $closingBracket = strrpos($host, ']');
  67. if ($this->startsWith($host, '[') && $closingBracket) {
  68. $host = substr($host, 0, $closingBracket + 1);
  69. }
  70. else {
  71. list($host) = explode(':', $host);
  72. }
  73.  
  74. return $host;
  75. }
  76.  
  77. private function getTldExtractor()
  78. {
  79. if ($this->extractor !== NULL) {
  80. return $this->extractor;
  81. }
  82.  
  83. $serializedTlds = @file_get_contents($this->cacheFile);
  84.  
  85. if (!empty($serializedTlds)) {
  86. $this->extractor = new PublicSuffixListTLDExtractor(unserialize($serializedTlds));
  87. return $this->extractor;
  88. }
  89.  
  90. $tlds = [];
  91.  
  92. if ($this->fetch) {
  93. $tlds = $this->fetchTldList();
  94. }
  95.  
  96. if (empty($tlds)) {
  97. $snapshotFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.tld_set_snapshot';
  98. $serializedTlds = @file_get_contents($snapshotFile);
  99.  
  100. if (!empty($serializedTlds)) {
  101. $this->extractor = new PublicSuffixListTLDExtractor(unserialize($serializedTlds));
  102. return $this->extractor;
  103. }
  104. }
  105. else {
  106. @file_put_contents($this->cacheFile, serialize($tlds));
  107. }
  108.  
  109. $this->extractor = new PublicSuffixListTLDExtractor($tlds);
  110. return $this->extractor;
  111. }
  112.  
  113. private function fetchTldList()
  114. {
  115. $page = $this->fetchPage('http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1');
  116. $tlds = [];
  117. if (!empty($page) && preg_match_all('@^(?P<tld>[.*!]*\\w[\\S]*)@um', $page, $matches)) {
  118. $tlds = array_fill_keys($matches['tld'], true);
  119. .......................................................................................
  120. ..................................................
  121. .....................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement