functions to generate and check webbies interactively
This commit is contained in:
parent
02cc436ec7
commit
65160ffd12
@ -1655,3 +1655,48 @@ function is_a_date_arg($s) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function legal_webbie($s) {
|
||||
if(! strlen($s))
|
||||
return '';
|
||||
|
||||
$x = $s;
|
||||
do {
|
||||
$s = $x;
|
||||
$x = preg_replace('/^([^a-z])(.*?)/',"$2",$s);
|
||||
} while($x != $s);
|
||||
|
||||
return preg_replace('/([^a-z0-9\-\_])/','',$x);
|
||||
}
|
||||
|
||||
|
||||
function check_webbie($arr) {
|
||||
|
||||
$str = '';
|
||||
$taken = array();
|
||||
if(count($arr)) {
|
||||
foreach($arr as $x) {
|
||||
$y = legal_webbie($x);
|
||||
if(strlen($y)) {
|
||||
if($str)
|
||||
$str .= ',';
|
||||
$str .= "'" . dbesc($y) . "'";
|
||||
}
|
||||
}
|
||||
if(strlen($str)) {
|
||||
$r = q("select entity_address from entity where entity_address in ( $str ) ");
|
||||
if(count($r)) {
|
||||
foreach($r as $rr) {
|
||||
$taken[] = $rr['entity_address'];
|
||||
}
|
||||
}
|
||||
foreach($arr as $x) {
|
||||
if(! in_array($x,$taken)) {
|
||||
return $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
@ -7,22 +7,75 @@ function zentity_init(&$a) {
|
||||
$cmd = ((argc() > 1) ? argv(1) : '');
|
||||
|
||||
|
||||
if($cmd === 'email_check.json') {
|
||||
if($cmd === 'autofill.json') {
|
||||
require_once('library/urlify/URLify.php');
|
||||
$result = array('error' => false, 'message' => '');
|
||||
$email = $_REQUEST['email'];
|
||||
$n = trim($_REQUEST['name']);
|
||||
|
||||
if(! allowed_email($email))
|
||||
$result['message'] = t('Your email domain is not among those allowed on this site');
|
||||
if((! valid_email($email)) || (! validate_email($email)))
|
||||
$result['message'] .= t('Not a valid email address') . EOL;
|
||||
if($result['message'])
|
||||
$result['error'] = true;
|
||||
$x = strtolower(URLify::transliterate($n));
|
||||
|
||||
$test = array();
|
||||
|
||||
// first name
|
||||
$test[] = legal_webbie(substr($x,0,strpos($x,' ')));
|
||||
if($test[0]) {
|
||||
// first name plus first initial of last
|
||||
$test[] = ((strpos($x,' ')) ? $test[0] . legal_webbie(trim(substr($x,strpos($x,' '),2))) : '');
|
||||
// first name plus random number
|
||||
$test[] = $test[0] . mt_rand(1000,9999);
|
||||
}
|
||||
// fullname
|
||||
$test[] = legal_webbie($x);
|
||||
// fullname plus random number
|
||||
$test[] = legal_webbie($x) . mt_rand(1000,9999);
|
||||
|
||||
header('content-type: application/json');
|
||||
echo json_encode($result);
|
||||
echo json_encode(check_webbie($test));
|
||||
killme();
|
||||
}
|
||||
|
||||
if($cmd === 'checkaddr.json') {
|
||||
require_once('library/urlify/URLify.php');
|
||||
$result = array('error' => false, 'message' => '');
|
||||
$n = trim($_REQUEST['addr']);
|
||||
|
||||
$x = strtolower(URLify::transliterate($n));
|
||||
|
||||
$test = array();
|
||||
|
||||
$n = legal_webbie($x);
|
||||
if(strlen($n)) {
|
||||
$test[] = $n;
|
||||
$test[] = $n . mt_rand(1000,9999);
|
||||
}
|
||||
|
||||
for($y = 0; $y < 100; $y ++)
|
||||
$test[] = 'id' . mt_rand(1000,9999);
|
||||
|
||||
//print_r($test);
|
||||
|
||||
header('content-type: application/json');
|
||||
echo json_encode(check_webbie($test));
|
||||
killme();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// print_r($test);
|
||||
|
||||
// if(! allowed_email($email))
|
||||
// $result['message'] = t('Your email domain is not among those allowed on this site');
|
||||
// if((! valid_email($email)) || (! validate_email($email)))
|
||||
// $result['message'] .= t('Not a valid email address') . EOL;
|
||||
// if($result['message'])
|
||||
// $result['error'] = true;
|
||||
|
||||
// header('content-type: application/json');
|
||||
// echo json_encode($result);
|
||||
// killme();
|
||||
|
||||
|
||||
$pw1 = t("Password too short");
|
||||
$pw2 = t("Passwords do not match");
|
||||
|
||||
|
Reference in New Issue
Block a user