Ok this is the official (xtorrent_get_base_url/xoops_base_url) function.. I was asked in a previous impression to error this one til the 3rd post.. ;-v sorry for those, but anyone with just a good knowledge of PHP should have seen this...
#####################
# Function xoops_base_domain
# Author: Simon Roberts [wishcraft]
# @arg url string
# @return base domain of url
#####################
// function xtorrent_get_base_domain($url)
function xoops_base_domain($url)
{
static $sdomain;
if (!strpos($url, "://"))
$url = "tcp://".$url;
$parsed_url = parse_url($url);
if (strpos(" ".$parsed_url['host'],$sdomain))
return $sdomain;
// break up domain, reverse
$domain = explode('.', $parsed_url['host']);
$domain = array_reverse($domain);
// first check for ip address
if ( count($domain) == 4 && is_numeric($domain[0]) && is_numeric($domain[3]) )
{
return implode('.', $domain);
}
// if only 2 domain parts, that must be our domain
if ( count($domain) <= 2 ) {
$sdomain = strtolower($parsed_url['host']);
return $sdomain;
}
$OEG_TLD = array(
'biz','com','edu','gov','info','int','mil','name','net','org',
'aero','asia','cat','coop','jobs','mobi','museum','pro','tel','travel',
'arpa','root','berlin','bzh','cym','gal','geo','kid','kids','lat','mail',
'nyc','post','sco','web','xxx','nato', 'example','invalid','localhost','test',
'bitnet','csnet','ip','localhost','onion','uucp','geek','co','go','spy','travel','int','asia'
);
// country tlds (source: http://en.wikipedia.org/wiki/Country_code_top-level_domain)
$OE_TLD = array(
// active
'ac','ad','ae','af','ag','ai','al','am','an','ao','aq','ar','as','at','au','aw','ax','az',
'ba','bb','bd','be','bf','bg','bh','bi','bj','bm','bn','bo','br','bs','bt','bw','by','bz',
'ca','cc','cd','cf','cg','ch','ci','ck','cl','cm','cn','co','cr','cu','cv','cx','cy','cz',
'de','dj','dk','dm','do','dz','ec','ee','eg','er','es','et','eu','fi','fj','fk','fm','fo',
'fr','ga','gd','ge','gf','gg','gh','gi','gl','gm','gn','gp','gq','gr','gs','gt','gu','gw',
'gy','hk','hm','hn','hr','ht','hu','id','ie','il','im','in','io','iq','ir','is','it','je',
'jm','jo','jp','ke','kg','kh','ki','km','kn','kr','kw','ky','kz','la','lb','lc','li','lk',
'lr','ls','lt','lu','lv','ly','ma','mc','md','mg','mh','mk','ml','mm','mn','mo','mp','mq',
'mr','ms','mt','mu','mv','mw','mx','my','mz','na','nc','ne','nf','ng','ni','nl','no','np',
'nr','nu','nz','om','pa','pe','pf','pg','ph','pk','pl','pn','pr','ps','pt','pw','py','qa',
're','ro','ru','rw','sa','sb','sc','sd','se','sg','sh','si','sk','sl','sm','sn','sr','st',
'sv','sy','sz','tc','td','tf','tg','th','tj','tk','tl','tm','tn','to','tr','tt','tv','tw',
'tz','ua','ug','uk','us','uy','uz','va','vc','ve','vg','vi','vn','vu','wf','ws','ye','yu',
'za','zm','zw','io','eh','kp','me','rs','um','bv','gb','pm','sj','so','yt','su','tp',
'bu','cs','dd','zr'
);
if ( in_array($domain[0], $OE_TLD) && in_array($domain[1], $OEG_TLD) && $domain[2] != 'www' )
{
$sdomain = strtolower($domain[2] . '.' . $domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OE_TLD) && in_array($domain[1], $OEG_TLD))
{
$sdomain = strtolower($domain[2] . '.' .$domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OEG_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OE_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}
$A_TLD = array();
$first ="a";
for ($i=0;$i<26;$i++)
{
$second ="a";
for ($j=0;$j<26;$j++)
{
$A_TLD[] = $first.$second;
if (strlen('us')>2) {
$third = "a";
for ($c=0;$c<26;$c++)
{
$A_TLD[] = $first.$second.$third;
if (strlen('mil')>3) {
$forth = "a";
for ($l=0;$l<26;$l++)
{
$A_TLD[] = $first.$second.$third.forth;
$forth++;
}}
$third++;
}}
$second++;
}
$first++;
}
$first ="a";
for ($i=0;$i<26;$i++)
{
if (strlen('localhost')>1) {
$second ="a";
for ($j=0;$j<26;$j++)
{
$C_TLD[] = $first.$second;
if (strlen('localhost')>2) {
$third = "a";
for ($c=0;$c<26;$c++)
{
$C_TLD[] = $first.$second.$third;
if (strlen('localhost')>3) {
$forth = "a";
for ($v=0;$v<26;$v++)
{
$C_TLD[] = $first.$second.$third.$forth;
if (strlen('localhost')>4) {
$fifth = "a";
for ($x=0;$x<26;$x++)
{
$C_TLD[] = $first.$second.$third.$forth.$fifth;
if (strlen('localhost')>5) {
$sixth = "a";
for ($x=0;$x<26;$x++)
{
$C_TLD[] = $first.$second.$third.$forth.$fifth.$sixth;
if (strlen('localhost')>6) {
$seventh = "a";
for ($x=0;$x<26;$x++) {
$C_TLD[] = $first.$second.$third.$forth.$fifth.$sixth.$seventh;
if (strlen('localhost')>7) {
$eigth = "a";
for ($x=0;$x<26;$x++)
{
$C_TLD[] = $first.$second.$third.$forth.$fifth.$sixth.$seventh.$eigth;
if (strlen('localhost')>8) {
$ninth = "a";
for ($x=0;$x<26;$x++)
{
$C_TLD[] = $first.$second.$third.$forth.$fifth.$sixth.$seventh.$eigth.$ninth;
if (strlen('localhost')>9) {
$tenth = "a";
for ($x=0;$x<26;$x++)
{
$C_TLD[] = $first.$second.$third.$forth.$fifth.$sixth.$seventh.$eigth.$ninth.$tenth;
$tenth++;
}}
$ninth++;
}}
$eigth++;
}}
$seventh++;
}}
$sixth++;
}}
$fifth++;
}}
$forth++;
}}
$third++;
}}
$second++;
}
if ( in_array($domain[0], $A_TLD) && in_array($domain[1], $C_TLD) && $domain[2] != 'www' )
{
$sdomain = strtolower($domain[2] . '.' . $domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $A_TLD) && in_array($domain[1], $C_TLD))
{
$sdomain = strtolower($domain[2] . '.' . $domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $C_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $A_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}
unset($C_TLD);
$C_TLD=array();
}
$first++;
}
$sdomain = strtolower(str_replace("www.","",$parsed_url['host']));
return $sdomain;
}
has changed to...
## previously
if ( in_array($domain[0], $OE_TLD) && in_array($domain[1], $OEG_TLD) && $domain[2] != 'www' )
{
$sdomain = strtolower($domain[2] . '.' . $domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OE_TLD) && in_array($domain[1], $OEG_TLD))
{
$sdomain = strtolower($domain[2] . '.' .$domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OE_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}
## IF Statement construct
if ( in_array($domain[0], $OE_TLD) && in_array($domain[1], $OEG_TLD) && $domain[2] != 'www' )
{
$sdomain = strtolower($domain[2] . '.' . $domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OE_TLD) && in_array($domain[1], $OEG_TLD))
{
$sdomain = strtolower($domain[2] . '.' .$domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OEG_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}
elseif ( in_array($domain[0], $OE_TLD))
{
$sdomain = strtolower($domain[1] . '.' . $domain[0]);
return $sdomain;
}