Click anywhere to close this dialog

Farewell

Great is the art of beginning, but greater is the art of ending
Henry Wadsworth Longfellow

I announce that I cease all development and activity in the programming universe indefinitely. My career has reached the turning point I was not expecting for at least another year, leaving me highly off guard and without laid-out plans for this hobby's continuity. I have begun a 5-year residency program in Neurosurgery which is clearly not compatible, time-wise, with programming.

I gave in all my passion for developing, and you gave me back your loyalty and trust, even when I did not deserve that much. Now it is the time for payback. I release all my present and past work as Open Source software, in the hope some talented developer will continue maintaining and expanding my vision of a modern, sleek forum software. The intrinsic flexibility of MyBB is the true hidden gem of an otherwise outdated codebase; I do hope the project can continue and be updated complying to the latest coding standards.

I hereby thank Euan, kawaii, andrewjs18, Ben, Matt, Omar G., effone, Eric J., Devilshakerz, Wildcard, JordanMussi and all the other team members I have had the opportunity to work with when I was a MyBB team member. I thank Tomm M, my mentor, who inspired me to pick up coding with his piece-of-art plugins. And finally, I thank all of you MyBBoost subscribers who have helped me getting through my toughest university years economically.

Yours sincerely, Filippo

Default avatar with Hovercards

6 Aug 2019
#1
This issue is marked as solved
@Shade Great job. However, how to set a default avatar if user has none?

Best answer

Shade 6 Aug 2019 Edited
inc/plugins/hovercards.php, line 388:

$users[] = $user
Add before:

if (!$user['avatar']) {
    
$user['avatar'] = 'what you want';

Btw, it's not overkill even for hundreds thousands of users. You could run a single query to set a default avatar, and install a plugin that takes care of new users when they register. Just my two cents.
day-day likes this post

All replies

Shade 6 Aug 2019 Edited
#2
Hovercards does not come with this ability. There are plenty of plugins that handle it though. I suggest you to use Letter Avatars 1.0.2 which adds some style to default avatars.
ProX 6 Aug 2019
#3
Hovercards does not come with this ability. There are plenty of plugins that handle it though. I suggest you to use Letter Avatars 1.0.2 which adds some style to default avatars.
Shade (6 Aug 2019)
Should this already fix it?
function defaultavatarfix()
{
    global $mybb;

    if(!$mybb->user['avatar'] && !empty($mybb->settings['useravatar']))
    {
        $mybb->user['avatar'] = $mybb->settings['useravatar'];
    }
}
$plugins->add_hook("global_intermediate", "defaultavatarfix");
Shade 6 Aug 2019
#4
This does not work with Hovercards as it's just a local fix. Letter Avatars 1.0.2 and all related plugins store the default avatar in the database which is the source from which Hovercards pulls data from.
ProX 6 Aug 2019
#5
This does not work with Hovercards as it's just a local fix. Letter Avatars 1.0.2 and all related plugins store the default avatar in the database which is the source from which Hovercards pulls data from.
Shade (6 Aug 2019)
Just checked the code, seems like avatars are handled by javascript.

Basically the first statement checks if the avatar contains link from the db? If yes, it uses google proxy to show image. Else it returns empty avatar, right? So we can just define user.avatar?
if (user.avatar.indexOf('http') > -1) {
                        image.src = 'https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&refresh=300&url=' + encodeURIComponent(user.avatar);
                    } else {
                        image.src = user.avatar;
                    }
Shade 6 Aug 2019 Edited
#6
Nope, it just checks if it’s an uploaded avatar or a remote one. Remotes have to pass through Google to get adaptive colors due to CORS restrictions. Either way modifying Hovercards is a hassle, much simpler to use plugins for such things.
ProX 6 Aug 2019
#7
Nope, it just checks if it’s an uploaded avatar or a remote one. Remotes have to pass through Google to get adaptive colors due to CORS restrictions. Either way modifying Hovercards is a hassle, much simpler to use plugins for such things.
Shade (6 Aug 2019)
The letter avatar adds remote api which I really don't like. So will have to edit it manually. Can you just tell me which function checks if avatar exists? I've tried with negative Hovercards.exists(user.avatar), but doesn't seem to be working.
Shade 6 Aug 2019
#8
It's not in the JS, but in the database, so you'll have to hack inc/plugins/hovercards.php. If you don't like external APIs, you can look for default avatar plugins on the community forums, there are plenty.
ProX 6 Aug 2019 Edited
#9
It's not in the JS, but in the database, so you'll have to hack inc/plugins/hovercards.php. If you don't like external APIs, you can look for default avatar plugins on the community forums, there are plenty.
Shade (6 Aug 2019)
Something like this?
if (empty($args[9])) // position of avatar column in db
return '/images/default_avatar.png';
Setting default avatar for hundreds of thousand members will do overkill. Even if limited it would take lots of time.
Shade 6 Aug 2019 Edited
#10
inc/plugins/hovercards.php, line 388:

$users[] = $user
Add before:

if (!$user['avatar']) {
    
$user['avatar'] = 'what you want';

Btw, it's not overkill even for hundreds thousands of users. You could run a single query to set a default avatar, and install a plugin that takes care of new users when they register. Just my two cents.
day-day likes this post