From: Evan Prodromou Date: Tue, 26 Apr 2011 20:17:24 +0000 (-0400) Subject: get a free site nickname by email or domain X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=57d1a3dcc0fb58eb13e2a47254ba3f2b656dd3f3;p=quix0rs-gnu-social.git get a free site nickname by email or domain --- diff --git a/plugins/EmailRegistration/scripts/proposesite.php b/plugins/EmailRegistration/scripts/proposesite.php new file mode 100644 index 0000000000..345128d20c --- /dev/null +++ b/plugins/EmailRegistration/scripts/proposesite.php @@ -0,0 +1,94 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); + +$helptext = << +Prints site information for the domain given + +END_OF_SITEFORDOMAIN_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; +require_once INSTALLDIR.'/plugins/EmailRegistration/extlib/effectiveTLDs.inc.php'; +require_once INSTALLDIR.'/plugins/EmailRegistration/extlib/regDomain.inc.php'; + +function nicknameAvailable($nickname) +{ + $sn = Status_network::staticGet('nickname', $nickname); + return !empty($sn); +} + +function nicknameForDomain($domain) +{ + global $tldTree; + + $registered = getRegisteredDomain($domain, $tldTree); + + $parts = explode('.', $registered); + + $base = $parts[0]; + + if (nicknameAvailable($base)) { + return $base; + } + + $domainish = str_replace('.', '-', $registered); + + if (nicknameAvailable($domainish)) { + return $domainish; + } + + $i = 1; + + // We don't need to keep doing this forever + + while ($i < 1024) { + $candidate = $domainish.'-'.$i; + if (nicknameAvailable($candidate)) { + return $candidate; + } + } + + return null; +} + +$raw = $args[0]; + +$parts = explode('@', $raw); + +if (count($parts) == 1) { + $domain = $parts[0]; +} else { + $domain = $parts[1]; +} + +$domain = strtolower(trim($domain)); + +$nickname = nicknameForDomain($domain); + +if (empty($nickname)) { + throw ClientException("No candidate found."); +} else { + print $nickname; + print "\n"; +}