SimplePortal

Customization => Custom Coding => Topic started by: roomeat on August 31, 2009, 07:39:46 AM

Title: Shorten Username in Top Posters
Post by: roomeat on August 31, 2009, 07:39:46 AM
Would anyone know how I could shorten the usernames for the Top Posters block??
I have a few members with long usernames (Shawskin_Productions for example )
Would like the block to shorten that to Shawskin...
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on August 31, 2009, 05:30:48 PM
Moved to the Custom Coding Board.

Find this code (sources/SPortal2.php file, line ~981):
Code: [Select]
'name' => $row['real_name'],
Replace with this code:
Code: [Select]
'name' => substr($row['real_name'], 0, 15),
Title: Re: Shorten Username in Top Posters
Post by: roomeat on August 31, 2009, 08:06:42 PM
Thanks Nathaniel.. but that didn't seem to change anything :(
Title: Re: Shorten Username in Top Posters
Post by: ccbtimewiz on August 31, 2009, 08:28:43 PM
This is not possible in the way you want it.

You can't shorten every name to what you want. You can restrict how many characters appear, but that might not be what you want for every user.

Example, if I cut 15 chars, and my username was ThisIsATestLolLolLol, it would return: ThisIsATestLolL
Title: Re: Shorten Username in Top Posters
Post by: roomeat on August 31, 2009, 08:39:46 PM
So you can't make it so that:
Username under 15 characters appear normal
Username over 15 characters are cutoff and a ... put after it ?

Obviously I can't ask people to change their usernames to suit a block. The block should be able to compensate for such obstacles.

The phpbb portal that I am using on my live site at present has this ability.. but the coding is totally different to that of SMF so I have no idea what I am looking at :(
Title: Re: Shorten Username in Top Posters
Post by: ccbtimewiz on August 31, 2009, 10:06:28 PM
That is possible, and is probably recommended.

Did you perform the edits LHVWB provided?
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 01, 2009, 03:38:17 AM
LHVWB??? umm.. can't see any posts by a user with this name lol
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 01, 2009, 04:49:26 AM
LHVWB??? umm.. can't see any posts by a user with this name lol

That used to be my username. ;)

That edit will simple shorten the usernames, you can change the length by changing the '15' value. If you really want to add an ellipsis '...' then I can post an edit.
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 01, 2009, 09:18:32 AM
The ellipsis identify that it has been shortened.. but as mentioned above.. I didn't notice a change after making that edit.. and I double checked that I had the right edit done ;)
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 12:00:59 AM
Have pulled apart my existing site to see how the shortened names work and I guess it should work with SP as well.. but not sure where to place this function to get it to work??

Code: [Select]
function sp_checksize($txt,$len)
{
if(strlen($txt) > $len)
{
$txt = truncate_string($txt, $len);
$txt .= '...';
}
return($txt);
}


And in sources/SPortal2.php file, line ~981

I have changed
Code: [Select]
'name' => $row['real_name'],
To
Code: [Select]
'name' => sp_checksize($row['real_name'],15),
I get the following error:
Quote
Fatal error: Call to undefined function sp_checksize() in /var/www/vhosts/ozsuperbikes.com/httpdocs/Sources/SPortal2.php on line 981

I guess thats because I don't know where to put that first function lol.. Anyone able to help me out with this please? :)
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 02, 2009, 12:39:47 AM
Put it at the end of your SPortal2.php file.
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 12:52:03 AM
hmmm.. now I get
Quote
Fatal error: Call to undefined function truncate_string() in /var/www/vhosts/ozsuperbikes.com/httpdocs/Sources/SPortal2.php on line 3229
lol
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 02, 2009, 12:58:59 AM
Use the substr() function, like:
Code: [Select]
substr($txt, 0, $len)
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 01:13:55 AM
Sorry Nathaniel.. not sure where I need to add that?
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 02, 2009, 01:47:00 AM
Replace this code:
Code: [Select]
truncate_string($txt, $len)
With that last code snippet I posted.
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 01:52:23 AM
Thanks mate. That got rid of the errors.. but for some reason it's still not adjusting the length of the names :(

By the way.. where bouts in Aus are you?
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 02, 2009, 02:15:11 AM
I'm in Melbourne.

Do you have any usernames over 15 characters? Try shortening the length from '15' to '8' or something smaller, 15 is probably a bit long.
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 02:23:00 AM
Cool.. Gold Coast here ;)
Yeah already tried shortening the number.. but still nothing changed :(
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 02, 2009, 02:54:50 AM
That would be due to the way that SP colors the usernames.

Some more edits:
Code: ("Find this code (/sources/Subs-SPortal2.php)") [Select]
$color_profile[$row['id_member']]['link'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '"' . (!empty($onlineColor) ? ' style="color: ' . $onlineColor . ';"' : '') . '>' . $row['real_name'] . '</a>';
Code: ("Replace with this code") [Select]
$color_profile[$row['id_member']]['link'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '"' . (!empty($onlineColor) ? ' style="color: ' . $onlineColor . ';"' : '') . '>' . $row['real_name'] . '</a>';
$color_profile[$row['id_member']]['short_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '"' . (!empty($onlineColor) ? ' style="color: ' . $onlineColor . ';"' : '') . '>' . sp_checksize($row['real_name'], 8) . '</a>';

Code: ("Find this code (SPortal2.php, line ~1021)") [Select]
$member['link']
Code: ("Replace with this code") [Select]
$member['short_link']
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 03:16:12 AM
Still nothing :( Thanks for the efforts though ;)
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 03:18:13 AM
Actually.. I'll retract that statement.. I edited the first instance instead of the one you noted.
Have corrected.. but now I have NO usernames being displayed lol
Title: Re: Shorten Username in Top Posters
Post by: Nathaniel on September 02, 2009, 04:31:15 AM
Ah, forgot about the block's link. ;)

Replace this code (SPortal2.php, line ~982):
Code: [Select]
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
With this code:
Code: [Select]
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'short_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . sp_checksize($row['real_name'], 8) . '</a>',
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 04:54:48 AM
Almost ;)
It's shortening the names.. but from both ends lol.

Take a look at the Top Posters block on the right side at www.ozsuperbikes.com

The first poster is me.. and that appears coorect.
The second name is idroppedit but appears as it...
The last name in the list is Shawskin_Productions and for some reason it appears as _Productions...

Hmm.. actually.. after reading that it is cutting the front of the username rather than the back lol.
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 04:58:13 AM
Fixed.. a typo in my copy paste :D :D

Thanks heaps Nathaniel.. top work :)
Title: Re: Shorten Username in Top Posters
Post by: roomeat on September 02, 2009, 04:58:43 AM
Don't spose you want to have a crack at my scrolling recent topics?? lol ;)
SimplePortal 2.3.8 © 2008-2024, SimplePortal