formatter = $formatter; $this->logger = $logger; } public function getMetrics($domain) { $domain = str_replace('www.', '', $domain); $ages = array(); $age = $this->getAgeArchiveOrg($domain); if ($age > 0) { $ages[] = $age; } $age = $this->getAgeWhoIs($domain); if ($age > 0) { $ages[] = $age; } $age = $this->getAgeWhoisCom($domain); if ($age > 0) { $ages[] = $age; } if (count($ages) > 0) { $value = min($ages); $value = $this->formatter->getPrettyTimeFromSeconds(time() - $value, true); } else { $value = null; } return array( new Metric('domain-age', 'SEO_DomainAge', $value, 'plugins/Morpheus/icons/dist/SEO/whois.png') ); } /** * Returns the domain age archive.org lists for the current url * * @param string $domain * @return int */ private function getAgeArchiveOrg($domain) { $data = $this->getUrl('http://wayback.archive.org/web/*/' . urlencode($domain)); preg_match('#]*)' . preg_quote($domain) . '/\">([^<]*)<\/a>#', $data, $p); if (!empty($p[2])) { $value = strtotime($p[2]); if ($value === false) { return 0; } return $value; } return 0; } /** * Returns the domain age who.is lists for the current url * * @param string $domain * @return int */ private function getAgeWhoIs($domain) { $data = $this->getUrl('http://www.who.is/whois/' . urlencode($domain)); preg_match('#(?:Creation Date|Created On|created|Registered on)\.*:\s*([ \ta-z0-9\/\-:\.]+)#si', $data, $p); if (!empty($p[1])) { $value = strtotime(trim($p[1])); if ($value === false) { return 0; } return $value; } return 0; } /** * Returns the domain age whois.com lists for the current url * * @param string $domain * @return int */ private function getAgeWhoisCom($domain) { $data = $this->getUrl('http://www.whois.com/whois/' . urlencode($domain)); preg_match('#(?:Creation Date|Created On|created):\s*([ \ta-z0-9\/\-:\.]+)#si', $data, $p); if (!empty($p[1])) { $value = strtotime(trim($p[1])); if ($value === false) { return 0; } return $value; } return 0; } private function getUrl($url) { try { return str_replace(' ', ' ', Http::sendHttpRequest($url, $timeout = 10, @$_SERVER['HTTP_USER_AGENT'])); } catch (\Exception $e) { $this->logger->warning('Error while getting SEO stats (domain age): {message}', array('message' => $e->getMessage())); return ''; } } }