From 65160ffd12500260ffd723bcffe721a3cc38d7da Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 30 Jul 2012 21:51:25 -0700 Subject: functions to generate and check webbies interactively --- include/text.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'include') 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 -- cgit v1.2.3