From cdf1c82bd8e18a47cc1532a0a6fc8855920bf95a Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Mon, 22 Feb 2010 11:44:18 +0100 Subject: [PATCH] Moves make_username to PlUser. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/pluser.php | 30 ++++++++++++++++++++++-------- include/misc.inc.php | 24 ------------------------ 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/classes/pluser.php b/classes/pluser.php index 84bcc60..862ea9d 100644 --- a/classes/pluser.php +++ b/classes/pluser.php @@ -370,6 +370,22 @@ abstract class PlUser */ abstract public static function isForeignEmailAddress($email); + private static function stripBadChars($text) + { + return str_replace(array(' ', "'"), array('-', ''), + strtolower(stripslashed(replace_accent(trim($text))))); + } + + /** Creates a username from a first and last name + * @param $firstname User's firstname + * @param $lasttname User's lastname + * return STRING the corresponding username + */ + public static function makeUsername($firstname, $lastname) + { + return self::stripBadChars($firstname) . '.' . self::stripBadChars($lastname); + } + /** * Creates a user forlive identifier from: * @param $firstname User's firstname @@ -378,14 +394,12 @@ abstract class PlUser */ public static function makeHrid($firstname, $lastname, $category) { - assert(trim($category)); - $plainFirstname = replace_accent(trim($firstname)); - $plainLastname = replace_accent(trim($lastname)); - - $hrid = strtolower($plainFirstname . '.' . $plainLastname . '.' . trim($category)); - $hrid = str_replace(' ', '-', $hrid); - $hrid = str_replace("'", '', $hrid); - return $hrid; + $cat = self::stripBadChars($category); + if (!cat) { + Platal::page()->kill("$category is not a suitable category."); + } + + return self::makeUserName($firstname, $lastname) . '.' . $cat; } diff --git a/include/misc.inc.php b/include/misc.inc.php index 831685e..fa080e8 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -112,30 +112,6 @@ function replace_accent($string) return strtr($string, $uc_convert); } -/** creates a username from a first and last name - * - * @param $prenom the firstname - * @param $nom the last name - * - * return STRING the corresponding username - */ -function make_username($prenom,$nom) -{ - /* on traite le prenom */ - $prenomUS=replace_accent(trim($prenom)); - $prenomUS=stripslashes($prenomUS); - - /* on traite le nom */ - $nomUS=replace_accent(trim($nom)); - $nomUS=stripslashes($nomUS); - - // calcul du login - $username = strtolower($prenomUS.".".$nomUS); - $username = str_replace(" ","-",$username); - $username = str_replace("'","",$username); - return $username; -} - /* Un soundex en français posté par Frédéric Bouchery Voici une adaptation en PHP de la fonction soundex2 francisée de Frédéric BROUARD (http://sqlpro.developpez.com/Soundex/). C'est une bonne démonstration de la force des expressions régulières compatible Perl. -- 2.1.4