Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Gluz on July 09, 2015, 06:08:43 PM

Title: Default Avatar by Username
Post by: Gluz on July 09, 2015, 06:08:43 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=4064)

Default Avatar by Username

Information
This MOD will show a default avatar based on the first letter of the Username (display name) for users that doesn't have an avatar.

Default Avatars only for the english letters (A-Z), not numbers or symbols.

2 Versions available, images or text.

Version 1.0.0 (uses images)
If you want to edit/change the images, they are in /Themes/yourtheme/images/avatar/ directory,
named from a.png to z.png and none.png for non-letter at first character usernames.

Version 1.1.0 (uses text)
Uses text instead of images, is a circle with a unique background color for each Username based on the MD5 hash of it.

Usage
Just install and it will show the default avatar.
To disable it, uninstall the mod.


(c) 2015
@author      Gluz (http://www.simplemachines.org/community/index.php?action=profile;u=338423)
@license      BSD http://opensource.org/licenses/BSD-3-Clause
@mod          Default Avatar by Username


Changelog:

Version 1.1.0
-Change the Images to a Circle colored span.

Version 1.0.0
-Change to lowercase the first letter of the Username.

Version 1.0.0
-Initial Release.
Title: Re: Default Avatar by Username
Post by: Diego Andrés on July 09, 2015, 06:14:25 PM
Nice mod, may I suggest one thing?

The avatar folder is being uploaded to each theme. I find this a bit unnecessary.
You see, users will barely modify your avatar pack. It's not like they are going to have a pack for every different theme they have.
So you could have used only default_images_url instead of images_url.

Regards, and good work.
Title: Re: Default Avatar by Username
Post by: Gluz on July 10, 2015, 12:35:55 AM
Thanks for the comment.

That was my first approach to this MOD, but then I realized that maybe someone would like to change the default avatars to match the theme, and if they have a few themes they can have different default avatars based on the theme.
Title: Re: Default Avatar by Username
Post by: Steve on July 10, 2015, 08:15:50 AM
Exactly. I looked at your images and thought the same thing. I'd want different color schemes for each theme I have. :)
Title: Re: Default Avatar by Username
Post by: Kindred on July 10, 2015, 08:42:02 AM
actually, if you go the route that the original requestor suggested...

get rid of images all together.

Use a single font letter with a CSS defined circle (using the CSS radius value)
then you could have/add a theme setting to define the base color for the circle/background

look at the board on/off icon on my test site...
test. turtleshellprod. com


<a class="off_button" href="http://test.turtleshellprod.com/index.php?action=unread;board=1.0;children">
TEXT CAN GO HERE
</a>



.off_button {
    display: block;
    width: 44px;
    height: 44px;
    border-radius: 22px;
    font-size: 20px;
    color: #FFF;
    line-height: 44px;
    text-align: center;
    background: linear-gradient(to bottom, #808080, #000) repeat scroll 0% 0% transparent;
}
Title: Re: Default Avatar by Username
Post by: Gluz on July 10, 2015, 02:47:03 PM
I'm thinking on changing that, but need to clarify some thing before.

I have it working in my test site with a round span with the letter with plain text and CSS as the original request was made, but the thing is that the SMF Customization team tells me that some Theme authors don't use the "image" key in the avatar array, and there is where I change the image for the span, if some theme uses only the URL of the avatar it will fail to show the default avatar because is not an image and that is what these themes expect.

If the SMF Customization team is OK with that, then I will add a side note to clarify that if nothing appears, then the theme needs to be edited.
Title: Re: Default Avatar by Username
Post by: Gluz on July 16, 2015, 09:05:20 PM
Updated.

Version 1.0.0 uses images, can be changed/modified for each theme.

Version 1.1.0 uses text, a circle with a unique background color for each username, can not be changed by theme.
Title: Re: Default Avatar by Username
Post by: Wellwisher on November 25, 2015, 05:32:53 PM
demo, screen shots, preview?
Title: Re: Default Avatar by Username
Post by: waplist on December 08, 2015, 09:59:15 AM
Please add support for redsy theme
Title: Re: Default Avatar by Username
Post by: Gluz on December 08, 2015, 11:50:13 AM
Quote from: Wellwisher on November 25, 2015, 05:32:53 PM
demo, screen shots, preview?
Oh, I forgot to take ones in my test forum, and for some reason I didn't set up notifications for this thread and didn't see this earlier. Soon I will add the images.

Quote from: waplist on December 08, 2015, 09:59:15 AM
Please add support for redsy theme
I will check that. What version do you use? Images or the CSS version.
Title: Re: Default Avatar by Username
Post by: waplist on December 10, 2015, 11:23:32 AM
Bytheway i am original requester for this mod. And i use css version
Title: Re: Default Avatar by Username
Post by: Gluz on December 10, 2015, 03:30:12 PM
Oh, yes, well, as I put in the Readme for that version, some Theme authors don't use the image key of the avatar array but the href one, and for the way it's generated the CSS avatar, is not possible to use it inside an img tag, so the href is empty.

This is the fix for Redsy Theme:
Quote
Display.template.php
Search:
<img src="', $message['member']['avatar']['href'], '" class="img-thumbnail img-circle" alt="*" />

Replace with:
', $message['member']['avatar']['image'], '


index.template.php
Search:
<img class="avatar img-circle" src="', !empty($context['user']['avatar']['href']) ? $context['user']['avatar']['href'] : $settings['images_url']. '/noavatar.png' ,'" alt="*" />

Replace with:
', $context['user']['avatar']['image'], '


PersonalMessage.template.php
Search:
<img src="', $message['member']['avatar']['href'], '" class="img-thumbnail img-circle" alt="*" />

Replace with:
', $message['member']['avatar']['image'], '


index.css
Add at the end:
.dropdown-toggle .avatar {
    font-size: 24px !important;
    line-height: 32px !important;
}


Title: Re: Default Avatar by Username
Post by: waplist on December 10, 2015, 08:17:06 PM
Thanks. Do i have to do it manually?
Title: Re: Default Avatar by Username
Post by: Gluz on December 10, 2015, 09:06:34 PM
Yes, that are specific Theme fixes and couldn't go into the installation package.

If you want, I can do it, you only need to attach that 4 files from your Redsy Theme.
-Display.template.php
-index.template.php
-PersonalMessage.template.php
-index.css
Title: Re: Default Avatar by Username
Post by: waplist on December 10, 2015, 10:50:17 PM
Ok please post that files.
Title: Re: Default Avatar by Username
Post by: Gluz on December 10, 2015, 11:32:29 PM
Quote from: Gluz on December 10, 2015, 09:06:34 PM
you only need to attach that 4 files from your Redsy Theme.
Title: Re: Default Avatar by Username
Post by: Tenebroso_MW on October 27, 2017, 05:39:48 PM

hi gluz

Should I modify a lot of code in my theme (modified default) so I call GIF file instead of png?

hola Gluz

Habria que modificar mucho código en mi tema ( por defecto modificado ) para que llame a archivo GIF en vez de png?
Title: Re: Default Avatar by Username
Post by: Gluz on October 28, 2017, 05:37:25 AM
The version 1.0.X uses PNG images, if you want them to be GIF then you only need to modify the call to the images in Load.php and Subs.php from PNG to GIF and upload the set of images in GIF to the avatar directory.

in Load.php:
// Default Avatar by Username.
if($memberContext[$user]['avatar']['image'] == '')
{
preg_match('/^[a-z]/i', $memberContext[$user]['name'], $damatch);
$damatch = empty($damatch) ? 'none' : strtolower($damatch[0][0]);
$memberContext[$user]['avatar'] = array(
'name' => $settings['images_url'] . '/avatar/' . $damatch . '.png',
'image' => '<img class="avatar" src="' . $settings['images_url'] . '/avatar/' . $damatch . '.png" alt="" />',
'href' => $settings['images_url'] . '/avatar/' . $damatch . '.png',
'url' => $settings['images_url'] . '/avatar/' . $damatch . '.png',
);
}


in Subs.php
// Default Avatar by Username.
if(empty($context['user']['avatar']['image']))
{
preg_match('/^[a-z]/i', $context['user']['name'], $damatch);
$damatch = empty($damatch) ? 'none' : strtolower($damatch[0][0]);
$context['user']['avatar'] = array(
'name' => $settings['images_url'] . '/avatar/' . $damatch . '.png',
'image' => '<img class="avatar" src="' . $settings['images_url'] . '/avatar/' . $damatch . '.png" alt="" />',
'href' => $settings['images_url'] . '/avatar/' . $damatch . '.png',
'url' => $settings['images_url'] . '/avatar/' . $damatch . '.png',
);
}


change all PNG to GIF and that's all, no Theme files need change.
Title: Re: Default Avatar by Username
Post by: Steve on October 28, 2017, 11:56:20 AM
Is it intentional that all usernames NOT beginning with an alphabetical letter display the question mark image? For example, one of my members name begins with a ~ and she gets the question mark.
Title: Re: Default Avatar by Username
Post by: Arantor on October 28, 2017, 12:21:21 PM
From the mod's description:

QuoteDefault Avatars only for the english letters (A-Z), not numbers or symbols.
Title: Re: Default Avatar by Username
Post by: Steve on October 29, 2017, 09:52:01 AM
Oops! Missed that somehow. Thanks. :)
Title: Re: Default Avatar by Username
Post by: Tenebroso_MW on October 30, 2017, 04:13:07 PM
Thanks Gluz.

I'll try local before and then the server.


Thanks, I have not been able to answer before. thanks for your prompt response.

Good MOD, congratulations

Tenebroso
Title: Re: Default Avatar by Username
Post by: iMiKK on September 24, 2018, 04:33:29 AM
Good Modification.
Thank for your work. :)
Title: Re: Default Avatar by Username
Post by: gecitli on October 30, 2019, 03:05:53 AM
Hi, can you edit this mode for SMF 2.1 RC2
Title: Re: Default Avatar by Username
Post by: SilverKnight on December 12, 2020, 03:04:17 AM
Confirmed as working for smf 2.0.17
Title: Re: Default Avatar by Username
Post by: Pipke on December 15, 2020, 04:52:08 PM
Quote from: gecitli on October 30, 2019, 03:05:53 AM
Hi, can you edit this mode for SMF 2.1 RC2

Avatars Display Integration (https://custom.simplemachines.org/mods/index.php?mod=4246)