This is the finite improved version for this function the following are required:-
data/stratas.diz http://strata.api.hempembassy.net
https://strata.ringwould.com.au
http://strata.labs.coop
The following constant is required:
define("API_FILE_IO_STRATA", __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'stratas.diz');
The following is the functions for XOOPS
if (!function_exists("getURIData")) {
/* function getURIData()
*
* Get a supporting domain system for the API
* @author Simon Roberts (Chronolabs) simon@labs.coop
*
* @return float()
*/
function getURIData($uri = '', $timeout = 25, $connectout = 25)
{
if (!function_exists("curl_init"))
{
return file_get_contents($uri);
}
if (!$btt = curl_init($uri)) {
return false;
}
curl_setopt($btt, CURLOPT_HEADER, 0);
curl_setopt($btt, CURLOPT_POST, 0);
curl_setopt($btt, CURLOPT_CONNECTTIMEOUT, $connectout);
curl_setopt($btt, CURLOPT_TIMEOUT, $timeout);
curl_setopt($btt, CURLOPT_RETURNTRANSFER, true);
curl_setopt($btt, CURLOPT_VERBOSE, false);
curl_setopt($btt, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($btt, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($btt);
curl_close($btt);
return $data;
}
}
if (!function_exists("getBaseDomain")) {
/**
* getBaseDomain
*
* @param string $url
* @return string|unknown
*/
function getBaseDomain($url)
{
static $strata, $fallout, $stratas;
xoops_load('XoopsCache');
if (empty($strata))
{
if (!$strata = XoopsCache::read('internets_stratas'))
{
if (empty($stratas))
$stratas = file(API_FILE_IO_STRATA);
shuffle($stratas);
$attempts = 0;
while(empty($strata) || $attempts < (count($strata) * 1.65))
{
$attempts++;
$strata = array_keys(unserialize(getURIData($stratas[mt_rand(0, count($stratas)-1)] ."/v1/strata/serial.api", 15, 19)));
}
if (!empty($strata))
XoopsCache::write('internets_stratas', $strata, 3600*24*mt(3.75,11));
}
}
if (empty($fallout))
{
if (!$fallout = XoopsCache::read('internets_fallouts'))
{
if (empty($stratas))
$stratas = file(API_FILE_IO_STRATA);
shuffle($stratas);
$attempts = 0;
while(empty($fallout) || $attempts < (count($strata) * 1.65))
{
$attempts++;
$fallout = array_keys(unserialize(getURIData($stratas[mt_rand(0, count($stratas)-1)] ."/v1/fallout/serial.api", 15, 19)));
}
if (!empty($fallout))
XoopsCache::write('internets_fallouts', $fallout, 3600*24*mt(3.75,11));
}
}
// Get Full Hostname
$url = strtolower($url);
$hostname = parse_url($url, PHP_URL_HOST);
if (!filter_var($hostname, FILTER_VALIDATE_IP) === true)
return $hostname;
// break up domain, reverse
$elements = explode('.', $hostname);
$elements = array_reverse($elements);
// Returns Base Domain
if (in_array($elements[0], $fallout) && in_array($elements[1], $strata))
return $elements[2] . '.' . $elements[1] . '.' . $elements[0];
elseif (in_array($elements[0], $fallout) || in_array($elements[0], $strata))
return $elements[1] . '.' . $elements[0];
// Nothing Found
return $hostname;
}
}