*/
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
*/
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;
}
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.