MyBB Community Forums

Full Version: How To test for user avatar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All
how do I test for a user avatar ?
I tried :-

if($mybb->user['avatar']){ $mybb->user['avatar'] = htmlspecialchars_uni($mybb->user['avatar']); }else{ $mybb->user['avatar'] = $mybb->settings['bburl']."/images/user.png"
//then display
<div class="header_side">
<div style="background: transparent url({$mybb->user['avatar']}) 0 0 no-repeat;width:100px;height:90px;float:left"></div>
			<div class="clear"></div>	
			</div>
This does not work Huh but the display code on its own does !
I guess there is an issue with the conditional ( typo ?)
Also If someone has any idea on how to resize the avatar to a size as when displayed some avatars are 2 big for the 100*90 box
You're missing the opening/closing PHP tags and a semi-colon at the end of the else statement. You also need to install the PHP in Templates plugin to be able to execute arbitrary PHP code in the templates.
for resizing you can use max-height & max-width attributes ...
(2011-08-08, 04:06 PM)ranjani Wrote: [ -> ]for resizing you can use max-height & max-width attributes ...

in which bit of code ?
(2011-08-08, 04:03 PM)faviouz Wrote: [ -> ]You're missing the opening/closing PHP tags and a semi-colon at the end of the else statement. You also need to install the PHP in Templates plugin to be able to execute arbitrary PHP code in the templates.

what tags should I use ?? I have tried a few .. I am using Template Conditionals (1.5) is that the best version to use ?
add max-width AND max-height in below code !!

<div style="background: transparent url({$mybb->user['avatar']}) 0 0 no-repeat;width:100px;height:90px;float:left"></div>


(2011-08-08, 04:20 PM)JimR Wrote: [ -> ]what tags should I use ?? I have tried a few .. I am using Template Conditionals (1.5) is that the best version to use ?
Nevermind the plugin. It's probably a better idea to hook your code directly in global.php:

1. Open global.php in a text editor.

2. Find:

// Run global_start plugin hook now that the basics are set up
$plugins->run_hooks("global_start");

3. Add afterwards:

if ($mybb->user['avatar'])
{
	$mybb->user['avatar'] = $mybb->user['avatar'];
}
else
{
	$mybb->user['avatar'] = $mybb->settings['bburl']."/images/user.png";
}

4. Use this in your template instead:

<div class="header_side">
<div style="background: transparent url({$mybb->user['avatar']}) 0 0 no-repeat;max-width:100px;max-height:90px;float:left"></div>
            <div class="clear"></div>    
            </div>
(2011-08-08, 04:47 PM)faviouz Wrote: [ -> ]
(2011-08-08, 04:20 PM)JimR Wrote: [ -> ]what tags should I use ?? I have tried a few .. I am using Template Conditionals (1.5) is that the best version to use ?
Nevermind the plugin. It's probably a better idea to hook your code directly in global.php:

1. Open global.php in a text editor.

2. Find:

// Run global_start plugin hook now that the basics are set up
$plugins->run_hooks("global_start");

3. Add afterwards:

if ($mybb->user['avatar'])
{
	$mybb->user['avatar'] = $mybb->user['avatar'];
}
else
{
	$mybb->user['avatar'] = $mybb->settings['bburl']."/images/user.png";
}

4. Use this in your template instead:

<div class="header_side">
<div style="background: transparent url({$mybb->user['avatar']}) 0 0 no-repeat;max-width:100px;max-height:90px;float:left"></div>
            <div class="clear"></div>    
            </div>

the global.php edit worked great but the max-height & max-width did not