• Hello, thanks for this mod. How can I realize it? I have installed it on my Elgg engine (Elgg 1.8.16): http://dunkle-biene.honey-bees.de but after activation I cannot see any changes.

    Please help me. Thank You.

    Best regrads

    Kai

  • here's an update for this which correctly uses the current gravatar url format and also uses elgg's default images if no gravatar is available (and you have customised your default elgg images):

     

            // avatars must be square
            $size = $icon_sizes[$size]['w'];
            $default = elgg_get_site_url() . '_graphics/icons/user/default' . $params['size'] . '.gif';
            $hash = md5($params['entity']->email);
            $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $params['entity']->email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
            return $grav_url;

  • It is compatible without any changes, I just marked it explicitly. It's fastest to just give plugin a shot on 1.9 install and look for problems.

  • Nice! And still works with 2.2.3. However, there's a "WARNING: Deprecated in 2.2". Fix:

    function gravatar_avatar_hook($hook, $type, $url, $params) {
        // check if user already has an icon
        if (!$params['entity']->icontime) {
            $size = $params['size'];
            $sizes = function_exists("elgg_get_icon_sizes") ? elgg_get_icon_sizes('user') : elgg_get_config('icon_sizes');
            @$sizes[$size] or
                $size = 'small';
    
            // avatars must be square
            $pixels = @$sizes[$size]['w'] or 40;
    
            $default = "mm";
    #        $default = urlencode(elgg_get_site_url() . 'vendor/elgg/elgg/_graphics/icons/user/default' . $size . '.gif');
    
            $hash = md5($params['entity']->email);
            return "https://secure.gravatar.com/avatar/$hash.jpg?s=$pixels&d=$default";
        }
    }

    ura souls default-hack is included but commented out. Not everybody wants to send their URLs to gravatar and most are probably happy with gravatar's default-icon.

  • I made a PR with all the stuff in comments plus more reliable default URL calculation, including for Elgg 3. Anyone want to test it out?

  • Right, if (empty()) is less elegant but faster than @. And may i suggest

        $default = elgg_view_exists($i = "icons/user/default/{$size}.gif")
            ? elgg_get_simplecache_url($i)
            : elgg_get_simplecache_url("icons/user/default{$size}.gif");
    
        // Comment this out if you wanna send your URLs to gravatar and have your
        // own default icon displayed in case they have none for users email address
        $default = "mm";

    That of course is way slower, but speed doesn't matter at all in this case, imho. Also,for something thats meant to be included in the next release, function_exists() is not neccessary. Above, i've overdone that. Same goes for $pixels = @$sizes[$size]['w'] or 40; If elgg_get_icon_sizes() doesn't return something useful, elgg is broken, no need to try to fix it in a tiny little plugin.

  • I reworked it a bit. @ is unwise because it suppresses everything (not just what the author expected). Value assignments should always be standalone statements. Elgg guidelines suggest ?: only when it fits a single line.

  • IMO, we should only support the latest Elgg version. Not too keen on doing the a-la WordPress function_exists.

Elgg

Non-bundled plugins from the Elgg developers. This is not a support account.

Project Info

Stats

  • Category: Third Party integrations
  • License: GNU General Public License (GPL) version 2
  • Updated: 2014-11-17
  • Downloads: 1460
  • Recommendations: 12