Default Avatar On Registration

Started by ScoobyDan, June 23, 2007, 07:44:09 PM

Previous topic - Next topic

ScoobyDan

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

codenaught

Thanks for sharing. :)

Moving to Tips and Tricks...
Dev Consultant
Former SMF Doc Coordinator

lonrot

Excellent trick ScoobyDan, works like a charm!

perro88

Nice just a line on code but very useful hehe

elfishtroll

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 :)

MichaelMorris

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.

Goatie

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!!

codenaught

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.
Dev Consultant
Former SMF Doc Coordinator

Goatie

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 :-[

MichaelMorris

@akabugeyes

Yea, thats perfect. Thanks!

Cavan

#10
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.

codenaught

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.
Dev Consultant
Former SMF Doc Coordinator

Cavan

#12
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.

Fiery

Were you able to get this working?

What about on the default theme, just to check to see if everything was done correctly?

The -L-


H

This should not need changes to work on 1.1.9
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

Advertisement: