Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Reflection on July 13, 2009, 06:36:12 PM

Title: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Reflection on July 13, 2009, 06:36:12 PM
SMF 2.0:

Open ./Sources/Load.php

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

Replace with:
Code: [Select]
// 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:
Code: [Select]
                'local_time' => timeformat(time() + ($profile['timeOffset'] - $user_info['time_offset']) * 3600, false),
        );

        return true;

Replace with:
Code: [Select]
                '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;

Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: JBlaze on July 13, 2009, 06:45:07 PM
Nice idea :)

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

-[n3rve]
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: JBlaze on July 14, 2009, 12:21:45 PM
Indexed (http://www.simplemachines.org/community/index.php?topic=15899.msg161884#msg161884) as it wasn't :)

-[n3rve]

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

*goes back to sleep
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Hassan_the best on July 21, 2009, 09:28:15 AM
Nice
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Nibogo on July 22, 2009, 05:40:36 PM
Default Avatar (http://custom.simplemachines.org/mods/index.php?mod=975)?
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Sabre™ on July 22, 2009, 05:48:17 PM
Yeah, thats what I use
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Reflection on July 22, 2009, 05:50:18 PM
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. ;)
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Costa on July 22, 2009, 06:16:18 PM
Cool tip!

Thanks Reflection!
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Nibogo on July 22, 2009, 06:19:52 PM
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

;)
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Reflection on July 22, 2009, 06:27:29 PM
./Themes/default/ManageAttachments.template.php

:P
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Nibogo on July 22, 2009, 07:11:22 PM
./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) ;)
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Antechinus on July 22, 2009, 07:15:04 PM
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.
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Nibogo on July 22, 2009, 07:23:22 PM
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)
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Antechinus on July 22, 2009, 07:28:44 PM
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.
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: robinrobin on September 19, 2009, 04:15:45 PM
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.
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: N3RVE on September 30, 2009, 02:02:41 AM
Perhaps, you should try the mod instead?

-[n3rve]
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: C4G-TK on October 05, 2009, 11:32:39 PM
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.
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Nier on February 08, 2010, 08:24:51 AM
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..
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: curlin on February 08, 2010, 02:27:20 PM
     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!.

Code: [Select]
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>';
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Veliki Brat on February 24, 2010, 04:03:02 PM
Hi

In my case only admin see default_avatar no one else? How come?
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: flapjack on June 15, 2010, 08:16:51 PM
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
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: sona67 on April 02, 2011, 06:21:56 AM
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
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: pearpandas on April 14, 2011, 02:53:41 PM
This is awesome!  I'm gonna use it in my website right now!
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Xarcell on December 10, 2012, 05:48:43 PM
How come this doesn't work in the index.template.php, it works everywhere else?
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Antechinus on December 11, 2012, 02:05:51 PM
Not sure. It should. Have you got any weird code there?
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Xarcell on December 14, 2012, 05:52:41 PM
I think it's because member is not defined for some reason. I will attempt to debug...
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Xarcell on January 01, 2013, 07:17:48 PM
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:
Quote
Undefined index: image
in whatever template file is being viewed

Using:
Code: [Select]
', $context['user']['avatar']['image'], '
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Arantor on January 01, 2013, 07:19:37 PM
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.
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: drewactual on February 07, 2019, 09:45:35 AM
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:
Code: [Select]
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:
Code: [Select]
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
Code: [Select]
width="{whatever pixel you set}" height="[whatever pixel you set}"

and will render:

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

just a PSA!!!  thanks for the tip whomever wrote the original!!!
Title: Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
Post by: Arantor on February 07, 2019, 09:47:40 AM
It’s also implemented in 2.1 in a slightly different way.