Log in

View Full Version : Spacing


Lilmikeishere
12-18-2010, 12:37 AM
How would you make it so a username can have more than 1 space in their username?

At the moment you can only have one space in your name.

calorie
12-18-2010, 12:44 AM
Would need to do a file edit:

/**
* Verifies that the provided username is valid, and attempts to correct it if it is not valid
*
* @param string Username
*
* @return boolean Returns true if the username is valid, or has been corrected to be valid
*/
function verify_username(&$username)
{
// fix extra whitespace and invisible ascii stuff
$username = trim(preg_replace('#[ \r\n\t]+#si', ' ', strip_blank_ascii($username, ' ')));

Lilmikeishere
12-18-2010, 12:45 AM
Which file would that be done in?

calorie
12-18-2010, 12:47 AM
File class_dm_user.php and maybe elsewhere, you'd need to check to be sure.

Lilmikeishere
12-18-2010, 12:49 AM
Anyone know what I would specifically have to do?

--------------- Added 1292642489 at 1292642489 ---------------

bump

kh99
12-18-2010, 01:50 AM
You could try taking the space out of the pattern that condenses white space, like this:


// fix extra whitespace and invisible ascii stuff
$username = trim(preg_replace('#[\r\n\t]+#si', ' ', strip_blank_ascii($username, ' ')));



(the red is where I took out the space)

But I haven't tried it, and I don't know if that's all you would have to do.

Lilmikeishere
12-18-2010, 04:53 PM
Im assuming some knowledge of regex patterns would be useful here?

kh99
12-18-2010, 05:22 PM
Im assuming some knowledge of regex patterns would be useful here?

Well, yeah, if you want to understand that code. I'm not an expert in that field, but this:

preg_replace('#[ \r\n\t]+#si', ' ', ...

says replace all sequences of one or more "white space" characters (space, carriage return, newline, tab) with a single space. So obviously any name entered with more than one space in a row will be changed to one space. I was suggesting taking the space out of that pattern (the one right before \r).

Lilmikeishere
12-18-2010, 08:14 PM
Well, yeah, if you want to understand that code. I'm not an expert in that field, but this:

preg_replace('#[ \r\n\t]+#si', ' ', ...

says replace all sequences of one or more "white space" characters (space, carriage return, newline, tab) with a single space. So obviously any name entered with more than one space in a row will be changed to one space. I was suggesting taking the space out of that pattern (the one right before \r).

Didn't seem to work.

Actually, when you edit it in the admin cp, the name has 2 spaces, but it only shows one space publicly on the current users, or users visited in 24 hours, so I'm guessing something else would have to be modified as well.

kh99
12-18-2010, 08:42 PM
I wonder if that's just HTML - normally multiple spaces get condensed to one. I'm not sure how to fix that easily. You could find everywhere a user name is being displayed and change spaces to  , but that seems like a lot of places.

There's a function called fetch_musername() in includes/functions that gets the "marked up" user name, so if you changed that it would probably handle most places, but I know there are some places where it's just the bare user name.

In retrospect, the single-space thing is probably a good thing because having people with the same user name other than spacing could get confusing (but I'm sure you have your reasons for wanting to allow it).

Lilmikeishere
12-19-2010, 06:30 AM
I wonder if that's just HTML - normally multiple spaces get condensed to one. I'm not sure how to fix that easily. You could find everywhere a user name is being displayed and change spaces to  , but that seems like a lot of places.

There's a function called fetch_musername() in includes/functions that gets the "marked up" user name, so if you changed that it would probably handle most places, but I know there are some places where it's just the bare user name.

In retrospect, the single-space thing is probably a good thing because having people with the same user name other than spacing could get confusing (but I'm sure you have your reasons for wanting to allow it).

My reasons are that I read the username of vBull with my java server, and people can have usernames with 2 spaces on the game, unfortunately they cannot on the forum, and that causes a conflict.

kh99
12-19-2010, 09:44 AM
I see - I figured you had a good reason.

So I notice that there's a hook at the end of fetch_musername so you don't have to edit that file if you don't want to, you could probably just use hook location fetch_musername with something like

$username = str_replace(' ', ' ', $username);
$user['musername'] = $vbulletin->usergroupcache["$displaygroupid"]['opentag'] . $username . $vbulletin->usergroupcache["$displaygroupid"]['closetag'];

Lilmikeishere
01-04-2011, 12:20 AM
Does anyone know exactly how to do it yet?