Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: ScoobyDan on June 23, 2007, 07:44:09 PM

Title: Default Avatar On Registration
Post by: ScoobyDan on June 23, 2007, 07:44:09 PM
I created this modification so that all new users have a default avatar selected (which they can then change if they wish). I feel this makes the forum look far better than some users having an avatar and some not. This is different to the Default Avatar (http://www.simplemachines.org/community/index.php?topic=19500.0) tip, which 'fakes' a default avatar by changing the templates to insert an avatar if one does not exist in the database.

To implement this tip, simply edit Sources/Register.php, and find


// Include the additional options that might have been filled in.
foreach ($possible_strings as $var)
if (isset($_POST[$var]))
$regOptions['extra_register_vars'][$var] = '\'' . $func['htmlspecialchars']($_POST[$var]) . '\'';


(lines 286-289 on my v1.1.2 forum). Add the following after the above:


// Default Avatar On Registration Mod Start
$regOptions['extra_register_vars']['avatar'] = '\'avatar.gif\'';
// Default Avatar On Registration Mod End


(amend 'avatar.gif' to point to your default avatar file, stored in the 'avatars' folder).

That's it! Job done. :D

Mods: If suitable, please move this to the 'Tips & Tricks' forum. Thanks ;)
Title: Re: Default Avatar On Registration
Post by: codenaught on June 23, 2007, 07:57:37 PM
Thanks for sharing. :)

Moving to Tips and Tricks...
Title: Re: Default Avatar On Registration
Post by: lonrot on June 27, 2007, 04:20:20 PM
Excellent trick ScoobyDan, works like a charm!
Title: Re: Default Avatar On Registration
Post by: perro88 on August 06, 2007, 12:05:10 AM
Nice just a line on code but very useful hehe
Title: Re: Default Avatar On Registration
Post by: elfishtroll on August 12, 2007, 10:09:34 PM
Quote from: perro88 on August 06, 2007, 12:05:10 AM
Nice just a line on code but very useful hehe

ditto on that! I can use it to default other fields as well on registration :)
Title: Re: Default Avatar On Registration
Post by: MichaelMorris on August 27, 2007, 11:03:50 AM
Howdy.

Ok, im going to use your code to set the default avatar, but what I would aslo like is this:

The user joins the forum and their avatar is set. The moderator of the forum then changes their membergroup (so they have access to extra parts of the forum). If the user didnt change their avatar from when it was set on registration, then I would like it to change to an avatar for that group, but if they have changed it then just leave it.

Is this possible????

Thanks in advance
Michael.
Title: Re: Default Avatar On Registration
Post by: Goatie on September 03, 2007, 05:49:34 AM
Great, thanks for the tip....
I can't believe I had to register at the forums before I found this tip. I couldn't even find it by searching the forums >_<
But once again.. Thanks!!
Title: Re: Default Avatar On Registration
Post by: codenaught on September 03, 2007, 04:43:42 PM
Quote from: Goatie on September 03, 2007, 05:49:34 AM
Great, thanks for the tip....
I can't believe I had to register at the forums before I found this tip. I couldn't even find it by searching the forums >_<
But once again.. Thanks!!
The Tips and Tricks board is viewable by guests. I just logged out and could still see it. Just saying this because you seem to suggest otherwise.

@MichaelMorris, do you mean you want to have different avatars for those that have no avatar of there own, depending on what group the user is in?

If so, I would advise you to take a look at this - http://www.simplemachines.org/community/index.php?topic=19500.0. And adapt it to meet your needs.

Basically I think you would want to change the:

'/noava.gif"

Bit of code to include the group ID:

'/noava.gif_' . $message['member']['group_id'] . '"

And then you would have images with names reflecting the group ID.

Such as: noava_0.gif for regular members, noava_1.gif for admins, noava_2.gif for global mods, etc.
Title: Re: Default Avatar On Registration
Post by: Goatie on September 04, 2007, 09:11:13 AM
Quote from: akabugeyes on September 03, 2007, 04:43:42 PM
The Tips and Tricks board is viewable by guests. I just logged out and could still see it. Just saying this because you seem to suggest otherwise.
Ah sorry, I'm just not so good at looking the right places :-[
Title: Re: Default Avatar On Registration
Post by: MichaelMorris on September 05, 2007, 04:55:49 AM
@akabugeyes

Yea, thats perfect. Thanks!
Title: Re: Default Avatar On Registration
Post by: Cavan on September 09, 2007, 11:32:08 AM
How would I use this tip for users already registered? I have avatars set to display in the memberlist, so I'd like the default avatar to show up there for my previously registered users.
Title: Re: Default Avatar On Registration
Post by: codenaught on September 09, 2007, 12:07:35 PM
It can sort of depend what code you are using. There is another trick posted that explains how to show a default avatar for all members without an avatar (which doesn't take into account when the member registered), however that doesn't mention anything about the memberlist (mainly because the avatar is not shown there by default).

If you let us know some of the code you are using, possible files custom code may be in would likely include: Memberlist.php and Memberlist.template.php.
Title: Re: Default Avatar On Registration
Post by: Cavan on September 09, 2007, 03:01:19 PM
I'm using 1.1.3 and the orange-lt theme. I should also note that I only allow users to upload an avatar; I don't allow access to externally stored avatars nor do I let them select one from the www/avatars folder.

In www/Sources/Memberlist.php I have:

// Set up the columns...
$context['columns'] = array(
'isOnline' => array(
'label' => $txt['online8'],
'width' => '20'
),
'avatar' => array(
            'label' => 'Avatar'
        ),


In www/Themes/default/Memberlist.template.php I have:

// Assuming there are members loop through each one displaying their data.
if (!empty($context['members']))
{
foreach ($context['members'] as $member)
echo '
<tr style="text-align: center;"', empty($member['sort_letter']) ? '' : ' id="letter' . $member['sort_letter'] . '"', '>
<td class="windowbg2">
', $context['can_send_pm'] ? '<a href="' . $member['online']['href'] . '" title="' . $member['online']['text'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $member['online']['image_href'] . '" alt="' . $member['online']['text'] . '" align="middle" />' : $member['online']['label'], $context['can_send_pm'] ? '</a>' : '', '
</td>
<td class="windowbg" align="center" width="100px">',$member['avatar']['image'], '</td>
<td class="windowbg" align="left">', $member['link'], '</td>


I've been trying to get this to work in Memberlist.template.php by calling my default avatar (def_avatar.gif)  but I'm not sure how to distinguish between an uploaded avatar and one that's stored on the server (in this case).

I've tried inserting this bit of code from Profile.template.php but I played around with it and can't seem to make it work in Memberlist.template.php:

// This is the avatar selection table that is only displayed if avatars are enabled!
if (!empty($context['member']['avatar']['allow_server_stored']) || !empty($context['member']['avatar']['allow_upload']))


Any ideas? Thanks.
Title: Re: Default Avatar On Registration
Post by: Fiery on October 10, 2007, 12:00:42 AM
Were you able to get this working?

What about on the default theme, just to check to see if everything was done correctly?
Title: Re: Default Avatar On Registration
Post by: The -L- on June 21, 2009, 04:03:07 PM
What if i have 1.1.9 version???
Title: Re: Default Avatar On Registration
Post by: H on July 08, 2009, 04:36:02 PM
This should not need changes to work on 1.1.9