Advertisement:

Author Topic: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)  (Read 55936 times)

Offline Reflection

  • Full Member
  • ***
  • Posts: 503
  • Gender: Male
    • Wii Powered
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;

Good "SMF" Portals
Tiny Portal [SMF 1.1.x only]
Simple Portal [SMF 1.1.x and 2.0]


Good "SMF" Theme Sites
SMF Themes [SMF 1.1.x and 2.0]
Dziner Studio [SMF 1.1.x and 2.0]

Offline JBlaze

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,159
  • Gender: Male
    • @fragicide on Twitter
Nice idea :)

Would you like this moved to Tips and Tricks?
Jason Clemons
Former Lead Customizer/Support Specialist
Twitter | Facebook | Instagram

Offline Reflection

  • Full Member
  • ***
  • Posts: 503
  • Gender: Male
    • Wii Powered
Go right ahead. Thanks. :)
Good "SMF" Portals
Tiny Portal [SMF 1.1.x only]
Simple Portal [SMF 1.1.x and 2.0]


Good "SMF" Theme Sites
SMF Themes [SMF 1.1.x and 2.0]
Dziner Studio [SMF 1.1.x and 2.0]

Offline JBlaze

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,159
  • Gender: Male
    • @fragicide on Twitter
Moved :)
Jason Clemons
Former Lead Customizer/Support Specialist
Twitter | Facebook | Instagram

Offline JeremyB.

  • Jr. Member
  • **
  • Posts: 298
  • Gender: Male
  • $phpJeremyB;?>
Nice tip.
"The most overlooked advantage to owning a computer is that if they foul up, there's no law against whacking them around a little."

Offline N3RVE

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,907
  • Gender: Male
    • N3RVE.COM
Indexed as it wasn't :)

-[n3rve]
Ralph "[n3rve]" Otowo
Former Marketing Co-ordinator, Simple Machines.
ralph [at] simplemachines [dot] org                       
Quote
“Somewhere, something incredible is waiting to be known.” - Carl Sagan

Offline JBlaze

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,159
  • Gender: Male
    • @fragicide on Twitter
Jason Clemons
Former Lead Customizer/Support Specialist
Twitter | Facebook | Instagram

Offline Sabre™

  • SMF Hero
  • ******
  • Posts: 2,527
  • Gender: Male
  • IF IT AINT BROKE, I CAN FIX IT TILL IT IS!!
I wonder if replacing the blank.gif in your avatar folder with a default one would work. :)

*goes back to sleep
« Last Edit: July 22, 2009, 06:22:26 PM by Sabre™ »
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Offline Hassan_the best

  • Full Member
  • ***
  • Posts: 592
  • Gender: Male
  • Lost in life
Nice


Offline Sabre™

  • SMF Hero
  • ******
  • Posts: 2,527
  • Gender: Male
  • IF IT AINT BROKE, I CAN FIX IT TILL IT IS!!
Yeah, thats what I use
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Offline Reflection

  • Full Member
  • ***
  • Posts: 503
  • Gender: Male
    • Wii Powered
Default Avatar?

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. ;)
Good "SMF" Portals
Tiny Portal [SMF 1.1.x only]
Simple Portal [SMF 1.1.x and 2.0]


Good "SMF" Theme Sites
SMF Themes [SMF 1.1.x and 2.0]
Dziner Studio [SMF 1.1.x and 2.0]

Offline Costa

  • SMF Hero
  • ******
  • Posts: 3,045
  • Gender: Male
  • Do NOT feed the trolls...
Cool tip!

Thanks Reflection!
Hugo "Costa" Fernandes
Todas as MP's a pedir ajuda são sujeitas a radioactividade, microondas, queimadas e atiradas borda fora.

"At least someone appreciates the fact that I am doing and not thinking..."
"Laziness is counter-revolutionary."

Offline Nibogo

  • SMF Hero
  • ******
  • Posts: 6,663
  • Gender: Male
    • smfpacks on Facebook
    • @smfpacks on Twitter
    • SMFPacks
Default Avatar?

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

;)

Offline Reflection

  • Full Member
  • ***
  • Posts: 503
  • Gender: Male
    • Wii Powered
./Themes/default/ManageAttachments.template.php

:P
Good "SMF" Portals
Tiny Portal [SMF 1.1.x only]
Simple Portal [SMF 1.1.x and 2.0]


Good "SMF" Theme Sites
SMF Themes [SMF 1.1.x and 2.0]
Dziner Studio [SMF 1.1.x and 2.0]

Offline Nibogo

  • SMF Hero
  • ******
  • Posts: 6,663
  • Gender: Male
    • smfpacks on Facebook
    • @smfpacks on Twitter
    • SMFPacks
./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) ;)

Online Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,760
  • Master of BBC Abuse
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.

Offline Nibogo

  • SMF Hero
  • ******
  • Posts: 6,663
  • Gender: Male
    • smfpacks on Facebook
    • @smfpacks on Twitter
    • SMFPacks
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)

Online Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,760
  • Master of BBC Abuse
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.

Offline robinrobin

  • Jr. Member
  • **
  • Posts: 297
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #19 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.

Offline N3RVE

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,907
  • Gender: Male
    • N3RVE.COM
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #20 on: September 30, 2009, 02:02:41 AM »
Perhaps, you should try the mod instead?

-[n3rve]
Ralph "[n3rve]" Otowo
Former Marketing Co-ordinator, Simple Machines.
ralph [at] simplemachines [dot] org                       
Quote
“Somewhere, something incredible is waiting to be known.” - Carl Sagan

Offline C4G-TK

  • Sr. Member
  • ****
  • Posts: 961
  • SHOW others respect & you GET respect in return.
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #21 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.
-img removed-

Offline Nier

  • Semi-Newbie
  • *
  • Posts: 44
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #22 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..

Offline curlin

  • Jr. Member
  • **
  • Posts: 106
    • Thoroughbred Junkie
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #23 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>';
Hoss Talk At Thoroughbred Junkie

Offline Veliki Brat

  • Jr. Member
  • **
  • Posts: 259
  • Gender: Male
    • Sve za dom
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #24 on: February 24, 2010, 04:03:02 PM »
Hi

In my case only admin see default_avatar no one else? How come?
Follow us on Twitter - Join us on Facebook - Visit our Website - Visit Forum

Web Designer & SEO Expert - WPZoom & IntenseDebate team member

SZD:M - Our latest work

Offline flapjack

  • SMF Hero
  • ******
  • Posts: 2,615
  • Gender: Male
  • I pity the fools!
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

Offline sona67

  • Semi-Newbie
  • *
  • Posts: 13
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

Offline pearpandas

  • Semi-Newbie
  • *
  • Posts: 26
    • Cutest Quotes
This is awesome!  I'm gonna use it in my website right now!

Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #28 on: December 10, 2012, 05:48:43 PM »
How come this doesn't work in the index.template.php, it works everywhere else?

Online Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,760
  • Master of BBC Abuse
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #29 on: December 11, 2012, 02:05:51 PM »
Not sure. It should. Have you got any weird code there?

Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #30 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...

Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #31 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'], '

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,643
    • StoryBB/StoryBB on GitHub
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #32 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline drewactual

  • Full Member
  • ***
  • Posts: 694
    • College Football Fan Site CFB51
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #33 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!!!

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,643
    • StoryBB/StoryBB on GitHub
Re: [Tip/Trick] Making a "real" default avatar (Eg: without editing templates)
« Reply #34 on: February 07, 2019, 09:47:40 AM »
It’s also implemented in 2.1 in a slightly different way.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.