static function getAutoUsername($firstName, $lastName, $email, $genericPrefixStr, $socialUserId, $usernamePrefixFormat) { // Scrub the first/last name for invalid characters that Joomla will deny: $stripChars = array('<', '>', '\\', '"', "'", '%', ';', '(', ')', '&'); $firstName = str_replace($stripChars, '', $firstName); $lastName = str_replace($stripChars, '', $lastName); if ($usernamePrefixFormat == AUTONAME_EXT) { return $genericPrefixStr . $socialUserId; } else { if ($usernamePrefixFormat == AUTONAME_FIRSTLAST) { $firstName = SCStringUtilities::strtolower($firstName); $lastName = SCStringUtilities::strtolower($lastName); if ($lastName != '') { $prefix = $firstName . "." . $lastName; } else { $prefix = $firstName; } } else { if ($usernamePrefixFormat == AUTONAME_FIRLAS) { $firstName = SCStringUtilities::strtolower($firstName); $lastName = SCStringUtilities::strtolower($lastName); // Try to always make usernames at least 6 characters $lastLength = strlen(utf8_decode($lastName)); $firstLength = strlen(utf8_decode($firstName)); $firstPrefix = SCStringUtilities::substr($firstName, 0, max(3, 6 - $lastLength)); $lastPrefix = SCStringUtilities::substr($lastName, 0, max(3, 6 - $firstLength)); $prefix = $firstPrefix . $lastPrefix; } else { if ($email != '') { $prefix = $email; } } } } if ($prefix != '') { $suffix = SCUserUtilities::getUsernameUniqueNumber($prefix); return $prefix . $suffix; } else { return ''; } }