Mettre un avatar gravatar aléatoire aux membres sans avatar

Voir le sujet précédent Voir le sujet suivant Aller en bas

  • 0

Astuce Mettre un avatar gravatar aléatoire aux membres sans avatar

Message par Ea Mar 9 Aoû 2011 - 11:03

Mettre un avatar gravatar aléatoire aux membres sans avatar

Gravatar est un service d'hébergement d'avatar (et sur certains blog qui l'implémente, votre avatar apparaîtra pour un commentaire juste en mettant l'adresse email d'un compte gravatar) qu'il est possible sur Forumactif d'utiliser par l'option "Lier l'Avatar à partir d'un autre site".

Cette astuce utilise une fonctionnalité de gravatar permettant d'afficher un avatar aléatoire, pour le mettre dans les sujets aux membres qui n'ont pas d'avatar défini :

Voir illustration :

Si vous voulez simplement mettre un avatar par défaut aux membres sans qu'il soit aléatoire, vous pouvez le faire depuis votre panneau d'administration :

Panneau d'administration  Affichage  Avatars - Gestions des avatars (onglet Avatars par défaut)

Création du script


Panneau d'administration  Modules  HTML & JAVASCRIPT - Gestion des codes Javascript

Assurez-vous que la gestion des codes Javascript soit activée, puis créez un nouveau javascript ayant pour titre "Gravatar" et pour placement "Sur les sujets" (plus d'informations sur la gestion des scripts).

Code:
// chiffre de la taille ( de 1 à 512 )
var default_avatar_size = 100;
// type d'avatar par défaut : "identicon", "retro", "wavatar" ou "monsterid"
var default_avatar_type = "identicon";
// identifiant pour votre forum ( peut être laissé vide )
var default_avatar_id = "";
// messages répétés de la page précédente ( suivant l'option du panneau d'administration )
var default_avatar_repeat = 0;
// premier message du sujet répéter sur toutes les pages ( 1 si oui 0 si non )
var default_avatar_first = 0;

function _h(e) {
    function i(a, b) {
        var c, d, e, f, g;
        e = a & 2147483648;
        f = b & 2147483648;
        c = a & 1073741824;
        d = b & 1073741824;
        g = (a & 1073741823) + (b & 1073741823);
        if (c & d) return g ^ 2147483648 ^ e ^ f;
        return c | d ? g & 1073741824 ? g ^ 3221225472 ^ e ^ f : g ^ 1073741824 ^ e ^ f : g ^ e ^ f
    }

    function j(a, b, c, d, e, f, g) {
        a = i(a, i(i(b & c | ~b & d, e), g));
        return i(a << f | a >>> 32 - f, b)
    }

    function k(a, b, c, d, e, f, g) {
        a = i(a, i(i(b & d | c & ~d, e), g));
        return i(a << f | a >>> 32 - f, b)
    }

    function l(a, b, d, c, e, f, g) {
        a = i(a, i(i(b ^ d ^ c, e), g));
        return i(a << f | a >>> 32 - f, b)
    }

    function m(a, b, d, c, e, f, g) {
        a = i(a, i(i(d ^ (b |
            ~c), e), g));
        return i(a << f | a >>> 32 - f, b)
    }

    function n(a) {
        var b = "",
            d = "",
            c;
        for (c = 0; c <= 3; c++) d = a >>> c * 8 & 255, d = "0" + d.toString(16), b += d.substr(d.length - 2, 2);
        return b
    }
    var f = [],
        o, p, q, r, a, b, c, d, e = function(a) {
            for (var a = a.replace(/\r\n/g, "\n"), b = "", d = 0; d < a.length; d++) {
                var c = a.charCodeAt(d);
                c < 128 ? b += String.fromCharCode(c) : (c > 127 && c < 2048 ? b += String.fromCharCode(c >> 6 | 192) : (b += String.fromCharCode(c >> 12 | 224), b += String.fromCharCode(c >> 6 & 63 | 128)), b += String.fromCharCode(c & 63 | 128))
            }
            return b
        }(e),
        f = function(a) {
            var b, c = a.length;
            b = c + 8;
            for (var d = ((b - b % 64) / 64 + 1) * 16, e = Array(d - 1), f = 0, g = 0; g < c;) b = (g - g % 4) / 4, f = g % 4 * 8, e[b] |= a.charCodeAt(g) << f, g++;
            e[(g - g % 4) / 4] |= 128 << g % 4 * 8;
            e[d - 2] = c << 3;
            e[d - 1] = c >>> 29;
            return e
        }(e);
    a = 1732584193;
    b = 4023233417;
    c = 2562383102;
    d = 271733878;
    for (e = 0; e < f.length; e += 16) o = a, p = b, q = c, r = d, a = j(a, b, c, d, f[e + 0], 7, 3614090360), d = j(d, a, b, c, f[e + 1], 12, 3905402710), c = j(c, d, a, b, f[e + 2], 17, 606105819), b = j(b, c, d, a, f[e + 3], 22, 3250441966), a = j(a, b, c, d, f[e + 4], 7, 4118548399), d = j(d, a, b, c, f[e + 5], 12, 1200080426), c = j(c, d, a, b, f[e + 6], 17, 2821735955),
        b = j(b, c, d, a, f[e + 7], 22, 4249261313), a = j(a, b, c, d, f[e + 8], 7, 1770035416), d = j(d, a, b, c, f[e + 9], 12, 2336552879), c = j(c, d, a, b, f[e + 10], 17, 4294925233), b = j(b, c, d, a, f[e + 11], 22, 2304563134), a = j(a, b, c, d, f[e + 12], 7, 1804603682), d = j(d, a, b, c, f[e + 13], 12, 4254626195), c = j(c, d, a, b, f[e + 14], 17, 2792965006), b = j(b, c, d, a, f[e + 15], 22, 1236535329), a = k(a, b, c, d, f[e + 1], 5, 4129170786), d = k(d, a, b, c, f[e + 6], 9, 3225465664), c = k(c, d, a, b, f[e + 11], 14, 643717713), b = k(b, c, d, a, f[e + 0], 20, 3921069994), a = k(a, b, c, d, f[e + 5], 5, 3593408605), d = k(d, a, b, c, f[e + 10], 9, 38016083),
        c = k(c, d, a, b, f[e + 15], 14, 3634488961), b = k(b, c, d, a, f[e + 4], 20, 3889429448), a = k(a, b, c, d, f[e + 9], 5, 568446438), d = k(d, a, b, c, f[e + 14], 9, 3275163606), c = k(c, d, a, b, f[e + 3], 14, 4107603335), b = k(b, c, d, a, f[e + 8], 20, 1163531501), a = k(a, b, c, d, f[e + 13], 5, 2850285829), d = k(d, a, b, c, f[e + 2], 9, 4243563512), c = k(c, d, a, b, f[e + 7], 14, 1735328473), b = k(b, c, d, a, f[e + 12], 20, 2368359562), a = l(a, b, c, d, f[e + 5], 4, 4294588738), d = l(d, a, b, c, f[e + 8], 11, 2272392833), c = l(c, d, a, b, f[e + 11], 16, 1839030562), b = l(b, c, d, a, f[e + 14], 23, 4259657740), a = l(a, b, c, d, f[e + 1], 4, 2763975236),
        d = l(d, a, b, c, f[e + 4], 11, 1272893353), c = l(c, d, a, b, f[e + 7], 16, 4139469664), b = l(b, c, d, a, f[e + 10], 23, 3200236656), a = l(a, b, c, d, f[e + 13], 4, 681279174), d = l(d, a, b, c, f[e + 0], 11, 3936430074), c = l(c, d, a, b, f[e + 3], 16, 3572445317), b = l(b, c, d, a, f[e + 6], 23, 76029189), a = l(a, b, c, d, f[e + 9], 4, 3654602809), d = l(d, a, b, c, f[e + 12], 11, 3873151461), c = l(c, d, a, b, f[e + 15], 16, 530742520), b = l(b, c, d, a, f[e + 2], 23, 3299628645), a = m(a, b, c, d, f[e + 0], 6, 4096336452), d = m(d, a, b, c, f[e + 7], 10, 1126891415), c = m(c, d, a, b, f[e + 14], 15, 2878612391), b = m(b, c, d, a, f[e + 5], 21, 4237533241),
        a = m(a, b, c, d, f[e + 12], 6, 1700485571), d = m(d, a, b, c, f[e + 3], 10, 2399980690), c = m(c, d, a, b, f[e + 10], 15, 4293915773), b = m(b, c, d, a, f[e + 1], 21, 2240044497), a = m(a, b, c, d, f[e + 8], 6, 1873313359), d = m(d, a, b, c, f[e + 15], 10, 4264355552), c = m(c, d, a, b, f[e + 6], 15, 2734768916), b = m(b, c, d, a, f[e + 13], 21, 1309151649), a = m(a, b, c, d, f[e + 4], 6, 4149444226), d = m(d, a, b, c, f[e + 11], 10, 3174756917), c = m(c, d, a, b, f[e + 2], 15, 718787259), b = m(b, c, d, a, f[e + 9], 21, 3951481745), a = i(a, o), b = i(b, p), c = i(c, q), d = i(d, r);
    return (n(a) + n(b) + n(c) + n(d)).toLowerCase()
};

$(function() {
    $(".postprofile > dl:first-child > dt:first-child,div.user-basic-info,span.poster-profile,#ipbwrapper dl.postprofile-details dt").filter(function(i) {
        return /^\/t[1-9][0-9]*-/.test(document.location.pathname) || i < default_avatar_first || i > default_avatar_first + default_avatar_repeat - 1;
    }).each(function() {
        if (!$(this).find("a:first img:not([src='https:/" + "/2img.net/i/fa/invision/pp-blank-thumb.png'])").length && $(this).find("a").length) {
            var e = $(this).find("a:first");
            $(e).html('<img src="http:/' + '/www.gravatar.com/avatar/' + _h("fa:/" + "/" + (default_avatar_id ? default_avatar_id : document.location.host) + $(e).attr("href").replace(/\?.*$/, "")) + '?s=' + default_avatar_size + '&d=' + default_avatar_type + '&r=pg" height="' + default_avatar_size + '" width="' + default_avatar_size + '" />')
        }
    });
});

N'oubliez pas de cliquer sur le bouton Valider pour sauvegarder les modifications.

Paramétrage du script


Il y a les 5 paramètres au début qui peuvent être modifiés :

  • default_avatar_size : exprime la taille (hauteur et largeur) en pixel, les valeurs possibles sont de 1 à 512 (mais sauf si vous surfer sur un écran de cinéma, 512 sera probablement trop grand pour votre forum) ;

  • default_avatar_type : permet de choisir le type d'avatar par défaut entre ces différentes valeurs :

    • "identicon" : des formes géométriques :

      Voir illustration :

    • "retro" : des têtes de style arcade :

      Voir illustration :

    • "wavatar" : des visages :

      Voir illustration :

    • "monsterid" : des monstres :

      Voir illustration :


  • default_avatar_id : si ce paramètre est laissé à "", tout les avatars aléatoires changeront si l'adresse du forum est changée (et en fonction du nom de domaine), en mettant quelque chose (ce qui est mis n'a pas d'importance tant que quelque chose est mis), les avatars aléatoires ne changeront pas quoi que devienne l'adresse du forum ;

  • default_avatar_repeat : permet de spécifier combien de messages sont répétés de la page précédente, suivant ce que vous avez choisi dans :

    Panneau d'administration  Général  Messages et Emails - Configuration :: Nombre de messages de la page précédente à afficher

    En effet, les messages répétés n'ont pas d'avatar (que le membre ait un avatar ou pas) pour les différencier des messages de la page.

  • default_avatar_first : permet de spécifier si le premier message du sujet est répété sur toutes les pages (car lui garde son avatar et on doit lui laisser ou bien lui mettre un avatar aléatoire si il n'en a pas), les valeurs peuvent être 0 (si le premier message n'est pas répété sur toutes les pages) ou 1 (si il l'est).


Ea

Ea
Aidactif
Aidactif

Messages : 23583
Inscrit(e) le : 04/04/2008

Ea a été remercié(e) par l'auteur de ce sujet.

Voir le sujet précédent Voir le sujet suivant Revenir en haut

- Sujets similaires

Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum