aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-07-30 21:51:25 -0700
committerfriendica <info@friendica.com>2012-07-30 21:51:25 -0700
commit65160ffd12500260ffd723bcffe721a3cc38d7da (patch)
tree334d60dccab197ebf64f1092222f65ba42ae8c75
parent02cc436ec7cf0cfca5fc9b5166cc537bbee53671 (diff)
downloadvolse-hubzilla-65160ffd12500260ffd723bcffe721a3cc38d7da.tar.gz
volse-hubzilla-65160ffd12500260ffd723bcffe721a3cc38d7da.tar.bz2
volse-hubzilla-65160ffd12500260ffd723bcffe721a3cc38d7da.zip
functions to generate and check webbies interactively
-rw-r--r--include/text.php45
-rw-r--r--mod/zentity.php71
2 files changed, 107 insertions, 9 deletions
diff --git a/include/text.php b/include/text.php
index 9d52fd076..3e4817898 100644
--- a/include/text.php
+++ b/include/text.php
@@ -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 '';
+}
+ \ No newline at end of file
diff --git a/mod/zentity.php b/mod/zentity.php
index 32170a642..4963d7190 100644
--- a/mod/zentity.php
+++ b/mod/zentity.php
@@ -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(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($result);
+ 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");