Default Avatar by Username

Started by Gluz, July 09, 2015, 06:08:43 PM

Previous topic - Next topic

Gluz

Link to Mod

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
@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.

Diego Andrés

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.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Gluz

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.

Steve

Exactly. I looked at your images and thought the same thing. I'd want different color schemes for each theme I have. :)
Please do not PM me for support.

Kindred

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;
}
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Gluz

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.

Gluz

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.


waplist

Please add support for redsy theme

Gluz

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.

waplist

Bytheway i am original requester for this mod. And i use css version

Gluz

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;
}



waplist

Thanks. Do i have to do it manually?

Gluz

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

waplist


Gluz


Tenebroso_MW


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?

Gluz

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.

Steve

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.
Please do not PM me for support.

Arantor

From the mod's description:

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

Advertisement: