Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Reflection in Juli 13, 2009, 06:36:12 NACHMITTAGS

Titel: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Reflection in Juli 13, 2009, 06:36:12 NACHMITTAGS
SMF 2.0:

Open ./Sources/Load.php

Find:
// First do a quick run through to make sure there is something to be shown.
$memberContext[$user]['has_messenger'] = false;


Replace with:

// Default avatar. ^^
if (empty($memberContext[$user]['avatar']['image']))
$memberContext[$user]['avatar']['image'] = '<img src="' . $settings['images_url'] . '/default_avatar.png" alt="Default Avatar" title="Default Avatar" width="' . $avatar_width . '" height="' . $avatar_height . '" />';

// First do a quick run through to make sure there is something to be shown.
$memberContext[$user]['has_messenger'] = false;


The default avatar should be uploaded to ./Themes/[your_theme]/, it should be named default_avatar.png and it should obviously be in .png format.

SMF 1.1.x:

Open ./Sources/Load.php

Find:
                'local_time' => timeformat(time() + ($profile['timeOffset'] - $user_info['time_offset']) * 3600, false),
        );

        return true;


Replace with:
                'local_time' => timeformat(time() + ($profile['timeOffset'] - $user_info['time_offset']) * 3600, false),
        );

// Default avatar. ^^
if (empty($memberContext[$user]['avatar']['image']))
$memberContext[$user]['avatar']['image'] = '<img src="' . $settings['images_url'] . '/default_avatar.png" alt="Default Avatar" title="Default Avatar" width="' . $avatar_width . '" height="' . $avatar_height . '" />';

        return true;


Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: JBlaze in Juli 13, 2009, 06:45:07 NACHMITTAGS
Nice idea :)

Would you like this moved to Tips and Tricks (http://www.simplemachines.org/community/index.php?board=72.0)?
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Reflection in Juli 13, 2009, 06:46:57 NACHMITTAGS
Go right ahead. Thanks. :)
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: JBlaze in Juli 13, 2009, 06:48:04 NACHMITTAGS
Moved :)
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: JeremyB. in Juli 14, 2009, 03:34:15 VORMITTAG
Nice tip.
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: N3RVE in Juli 14, 2009, 04:07:12 VORMITTAG
Indexed (http://www.simplemachines.org/community/index.php?topic=15899.msg161884#msg161884) as it wasn't :)

-[n3rve]
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: JBlaze in Juli 14, 2009, 12:21:45 NACHMITTAGS
Zitat von: [n3rve] in Juli 14, 2009, 04:07:12 VORMITTAG
Indexed (http://www.simplemachines.org/community/index.php?topic=15899.msg161884#msg161884) as it wasn't :)

-[n3rve]

Phooey... I forgot :(
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Sabre™ in Juli 19, 2009, 06:11:10 NACHMITTAGS
I wonder if replacing the blank.gif in your avatar folder with a default one would work. :)

*goes back to sleep
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Hassan_the best in Juli 21, 2009, 09:28:15 VORMITTAG
Nice
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Nibogo in Juli 22, 2009, 05:40:36 NACHMITTAGS
Default Avatar (http://custom.simplemachines.org/mods/index.php?mod=975)?
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Sabre™ in Juli 22, 2009, 05:48:17 NACHMITTAGS
Yeah, thats what I use
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Reflection in Juli 22, 2009, 05:50:18 NACHMITTAGS
Zitat von: NIBOGO in Juli 22, 2009, 05:40:36 NACHMITTAGS
Default Avatar (http://custom.simplemachines.org/mods/index.php?mod=975)?

Again, this edit makes the default avatar appear EVERYWHERE without editing any templates.. That mod edits templates, and the default avatar wouldn't appear everywhere. ;)
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Costa in Juli 22, 2009, 06:16:18 NACHMITTAGS
Cool tip!

Thanks Reflection!
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Nibogo in Juli 22, 2009, 06:19:52 NACHMITTAGS
Zitat von: Reflection in Juli 22, 2009, 05:50:18 NACHMITTAGS
Zitat von: NIBOGO in Juli 22, 2009, 05:40:36 NACHMITTAGS
Default Avatar (http://custom.simplemachines.org/mods/index.php?mod=975)?

Again, this edit makes the default avatar appear EVERYWHERE without editing any templates.. That mod edits templates, and the default avatar wouldn't appear everywhere. ;)

Please tell me where do you see a template edit, the mod do the same also edits the Load.php file:

http://custom.simplemachines.org/mods/index.php?action=parse;mod=975;attach=54824;smf_version=1.1.4

;)
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Reflection in Juli 22, 2009, 06:27:29 NACHMITTAGS
./Themes/default/ManageAttachments.template.php

:P
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Nibogo in Juli 22, 2009, 07:11:22 NACHMITTAGS
Zitat von: Reflection in Juli 22, 2009, 06:27:29 NACHMITTAGS
./Themes/default/ManageAttachments.template.php

:P

That is to set the image url nothing else, the image will appear everywhere, obviouslly if you can change the url from the admin panel (requires the edit of that file only used by the default theme) it's a lot better than modify the code (like your trick) ;)
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Antechinus in Juli 22, 2009, 07:15:04 NACHMITTAGS
Can't see how it is a lot better. Most sites will only set a default avatar once. Load one image. All done. No problem.
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Nibogo in Juli 22, 2009, 07:23:22 NACHMITTAGS
Zitat von: Antechinus in Juli 22, 2009, 07:15:04 NACHMITTAGS
Can't see how it is a lot better. Most sites will only set a default avatar once. Load one image. All done. No problem.

Because if you want to change the avatar you don't need ftp access (for example in my iPod)
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Antechinus in Juli 22, 2009, 07:28:44 NACHMITTAGS
Meh. Like I said, default avatars are usually a once-only thing anyway. Both ways of tackling the problem seem more or less equally good to me. Can't see that one is hugely better than the other. The only thing I could see as an improvement to Reflection's idea is to call the default avatar from the default/images folder, or even from the site's images folder. That way if you are using multiple themes to give your users some choice you still only need to deal with one image.
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: robinrobin in September 19, 2009, 04:15:45 NACHMITTAGS
Well this trick doesn't make the avatar appear in the left container in the collapsible personal space at the top of the forum with the default style. Maybe there should be some more edits. Making newly registered members see a difference when they actually are logged in is the only thing i wanted from this trick.
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: N3RVE in September 30, 2009, 02:02:41 VORMITTAG
Perhaps, you should try the mod instead?

-[n3rve]
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: C4G-TK in Oktober 05, 2009, 11:32:39 NACHMITTAGS
The .png should go into: Themes/"your theme"/images/   and not just Themes/"your theme" as in the first post.  At least, that's where I placed it in order for it to appear correctly.
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Nier in Februar 08, 2010, 08:24:51 VORMITTAG
I did exacly what was said in first post: The file load, searched and replaced it. Saved it. Upload a default_avatar.png to my theme map. Nothing happend if i dont select a avatar..
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: curlin in Februar 08, 2010, 02:27:20 NACHMITTAGS
     Hello

  This works in the posts but it is not showing in my "newest member" simple portal block. Could you tell me what to add below? Thanks!.

global $context, $memberContext, $modSettings, $color_profile;

   $latest_member_id = $context['common_stats']['latest_member']['id'];
   loadMemberData($latest_member_id);
   loadMemberContext($latest_member_id);

   echo '
   <div style="text-align: center;">';

   if (!empty($memberContext[$latest_member_id]['avatar']['href']))
      echo '
      <img src="'.$memberContext[$latest_member_id]['avatar']['href'].'" alt="" width="60" /><br />';

   echo '
      ', $memberContext[$latest_member_id]['link'], '
   </div>';
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Veliki Brat in Februar 24, 2010, 04:03:02 NACHMITTAGS
Hi

In my case only admin see default_avatar no one else? How come?
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: flapjack in Juni 15, 2010, 08:16:51 NACHMITTAGS
I just came up with an idea: use default_avatar.png as a background for where avatar is being displayed. one small css change. however it's not 100% foolproof, when user's avatar will not be standard size, it will not look pretty
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: sona67 in April 02, 2011, 06:21:56 VORMITTAG
Zitat von: Veliki Brat in Februar 24, 2010, 04:03:02 NACHMITTAGS
Hi

In my case only admin see default_avatar no one else? How come?

same problem. This edit doesn't work. I'm using 1.1.13
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: pearpandas in April 14, 2011, 02:53:41 NACHMITTAGS
This is awesome!  I'm gonna use it in my website right now!
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Xarcell in Dezember 10, 2012, 05:48:43 NACHMITTAGS
How come this doesn't work in the index.template.php, it works everywhere else?
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Antechinus in Dezember 11, 2012, 02:05:51 NACHMITTAGS
Not sure. It should. Have you got any weird code there?
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Xarcell in Dezember 14, 2012, 05:52:41 NACHMITTAGS
I think it's because member is not defined for some reason. I will attempt to debug...
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Xarcell in Januar 01, 2013, 07:17:48 NACHMITTAGS
I have attempted to debug, but the default avatar just doesn't load in the header of the index.template.php file. Error log says:
ZitatUndefined index: image
in whatever template file is being viewed

Using:
', $context['user']['avatar']['image'], '
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Arantor in Januar 01, 2013, 07:19:37 NACHMITTAGS
Probably because it's not declared there, and that you need to modify the separate loading of the avatar for the current user, IIRC that's in Load.php instead.
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: drewactual in Februar 07, 2019, 09:45:35 VORMITTAG
this is a nice little trick to use!!!!

however, and I don't know if it's something that has changed in the decade since it was first posted, this needs to be altered from:

if (empty($memberContext[$user]['avatar']['image']))
$memberContext[$user]['avatar']['image'] = '<img src="' . $settings['images_url'] . '/default_avatar.png" alt="Default Avatar" title="Default Avatar" width="' . $avatar_width . '" height="' . $avatar_height . '" />';



to:

if (empty($memberContext[$user]['avatar']['image']))
$memberContext[$user]['avatar']['image'] = '<img src="' . $settings['images_url'] . '/default_avatar.png" alt="Default Avatar" title="Default Avatar" ' . $avatar_width . ' ' . $avatar_height . ' />';

/


as the admin section settings already appends the

width="{whatever pixel you set}" height="[whatever pixel you set}"


and will render:

Zitat....... width=" width="{whatever pixel you set}""  height=" height="{whatever pixel you set}""

just a PSA!!!  thanks for the tip whomever wrote the original!!!
Titel: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Beitrag von: Arantor in Februar 07, 2019, 09:47:40 VORMITTAG
It's also implemented in 2.1 in a slightly different way.