vForums Support Banner



 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Database of Codes/Hacks/Mods :: Gravatar Integration - View Topic
Topic Rating: *****
Printable View
Paddy
Full Member
***
Insane Clown

[Avatar]

Posts: 288
Status: Offline
Gender: Male
Location: Buffalo, New York
Age: 34
Joined:  
Reputation: 7%  


pmwwwtwitterskypeaimgtalk
Gravatar Integration (28th Mar 08 at 8:25pm UTC)
Allow users to have Gravatars displayed
This lets the user specify their Gravatar email address, and it will over-ride their avatar with their gravatar, if they have one.

Made over the course of three hours, with significant help from Wrighty. I used code from PHP.js and a couple of Wrighty's to hack this together...

Enough babbling, here's the good stuff.

Global Headers

Code:
 
  1. <script>
  2. function md5 ( str ) {
  3.     // http://kevin.vanzonneveld.net
  4.     // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
  5.     // + namespaced by: Michael White (http://crestidg.com)
  6.     // -    depends on: utf8_encode
  7.     // *     example 1: md5('Kevin van Zonneveld');
  8.     // *     returns 1: '6e658d4bfcb59cc13f96c14450ac40b9'
  9.  
  10.     var RotateLeft = function(lValue, iShiftBits) {
  11.             return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
  12.         };
  13.  
  14.     var AddUnsigned = function(lX,lY) {
  15.             var lX4,lY4,lX8,lY8,lResult;
  16.             lX8 = (lX & 0x80000000);
  17.             lY8 = (lY & 0x80000000);
  18.             lX4 = (lX & 0x40000000);
  19.             lY4 = (lY & 0x40000000);
  20.             lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
  21.             if (lX4 & lY4) {
  22.                 return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
  23.             }
  24.             if (lX4 | lY4) {
  25.                 if (lResult & 0x40000000) {
  26.                     return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
  27.                 } else {
  28.                     return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
  29.                 }
  30.             } else {
  31.                 return (lResult ^ lX8 ^ lY8);
  32.             }
  33.         };
  34.  
  35.     var F = function(x,y,z) { return (x & y) | ((~x) & z); };
  36.     var G = function(x,y,z) { return (x & z) | (y & (~z)); };
  37.     var H = function(x,y,z) { return (x ^ y ^ z); };
  38.     var I = function(x,y,z) { return (y ^ (x | (~z))); };
  39.  
  40.     var FF = function(a,b,c,d,x,s,ac) {
  41.             a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
  42.             return AddUnsigned(RotateLeft(a, s), b);
  43.         };
  44.  
  45.     var GG = function(a,b,c,d,x,s,ac) {
  46.             a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
  47.             return AddUnsigned(RotateLeft(a, s), b);
  48.         };
  49.  
  50.     var HH = function(a,b,c,d,x,s,ac) {
  51.             a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
  52.             return AddUnsigned(RotateLeft(a, s), b);
  53.         };
  54.  
  55.     var II = function(a,b,c,d,x,s,ac) {
  56.             a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
  57.             return AddUnsigned(RotateLeft(a, s), b);
  58.         };
  59.  
  60.     var ConvertToWordArray = function(str) {
  61.             var lWordCount;
  62.             var lMessageLength = str.length;
  63.             var lNumberOfWords_temp1=lMessageLength + 8;
  64.             var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
  65.             var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
  66.             var lWordArray=Array(lNumberOfWords-1);
  67.             var lBytePosition = 0;
  68.             var lByteCount = 0;
  69.             while ( lByteCount < lMessageLength ) {
  70.                 lWordCount = (lByteCount-(lByteCount % 4))/4;
  71.                 lBytePosition = (lByteCount % 4)*8;
  72.                 lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount)<<lBytePosition));
  73.                 lByteCount++;
  74.             }
  75.             lWordCount = (lByteCount-(lByteCount % 4))/4;
  76.             lBytePosition = (lByteCount % 4)*8;
  77.             lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
  78.             lWordArray[lNumberOfWords-2] = lMessageLength<<3;
  79.             lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
  80.             return lWordArray;
  81.         };
  82.  
  83.     var WordToHex = function(lValue) {
  84.             var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
  85.             for (lCount = 0;lCount<=3;lCount++) {
  86.                 lByte = (lValue>>>(lCount*8)) & 255;
  87.                 WordToHexValue_temp = "0" + lByte.toString(16);
  88.                 WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
  89.             }
  90.             return WordToHexValue;
  91.         };
  92.  
  93.     var x=Array();
  94.     var k,AA,BB,CC,DD,a,b,c,d;
  95.     var S11=7, S12=12, S13=17, S14=22;
  96.     var S21=5, S22=9 , S23=14, S24=20;
  97.     var S31=4, S32=11, S33=16, S34=23;
  98.     var S41=6, S42=10, S43=15, S44=21;
  99.  
  100.     str = utf8_encode(str);
  101.     x = ConvertToWordArray(str);
  102.     a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
  103.  
  104.     for (k=0;k<x.length;k+=16) {
  105.         AA=a; BB=b; CC=c; DD=d;
  106.         a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
  107.         d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
  108.         c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
  109.         b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
  110.         a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
  111.         d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
  112.         c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
  113.         b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
  114.         a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
  115.         d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
  116.         c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
  117.         b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
  118.         a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
  119.         d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
  120.         c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
  121.         b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
  122.         a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
  123.         d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
  124.         c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
  125.         b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
  126.         a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
  127.         d=GG(d,a,b,c,x[k+10],S22,0x2441453);
  128.         c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
  129.         b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
  130.         a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
  131.         d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
  132.         c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
  133.         b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
  134.         a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
  135.         d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
  136.         c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
  137.         b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
  138.         a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
  139.         d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
  140.         c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
  141.         b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
  142.         a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
  143.         d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
  144.         c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
  145.         b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
  146.         a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
  147.         d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
  148.         c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
  149.         b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
  150.         a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
  151.         d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
  152.         c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
  153.         b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
  154.         a=II(a,b,c,d,x[k+0], S41,0xF4292244);
  155.         d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
  156.         c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
  157.         b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
  158.         a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
  159.         d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
  160.         c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
  161.         b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
  162.         a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
  163.         d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
  164.         c=II(c,d,a,b,x[k+6], S43,0xA3014314);
  165.         b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
  166.         a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
  167.         d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
  168.         c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
  169.         b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
  170.         a=AddUnsigned(a,AA);
  171.         b=AddUnsigned(b,BB);
  172.         c=AddUnsigned(c,CC);
  173.         d=AddUnsigned(d,DD);
  174.     }
  175.  
  176.     var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
  177.  
  178.     return temp.toLowerCase();
  179. }
  180. </script>
  181.  
  182. <script>
  183. function utf8_encode ( str_data ) {
  184.     // http://kevin.vanzonneveld.net
  185.     // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
  186.     // *     example 1: utf8_encode('Kevin van Zonneveld');
  187.     // *     returns 1: 'Kevin van Zonneveld'
  188.  
  189.     str_data = str_data.replace(/\r\n/g,"\n");
  190.     var utftext = "";
  191.  
  192.     for (var n = 0; n < str_data.length; n++) {
  193.         var c = str_data.charCodeAt(n);
  194.         if (c < 128) {
  195.             utftext += String.fromCharCode(c);
  196.         } else if((c > 127) && (c < 2048)) {
  197.             utftext += String.fromCharCode((c >> 6) | 192);
  198.             utftext += String.fromCharCode((c & 63) | 128);
  199.         } else {
  200.             utftext += String.fromCharCode((c >> 12) | 224);
  201.             utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  202.             utftext += String.fromCharCode((c & 63) | 128);
  203.         }
  204.     }
  205.  
  206.     return utftext;
  207. }
  208. </script>
  209.  
  210. <script>
  211. function URLEncode (clearString) {
  212.   var output = '';
  213.   var x = 0;
  214.   clearString = clearString.toString();
  215.   var regex = /(^[a-zA-Z0-9_.]*)/;
  216.   while (x < clearString.length) {
  217.     var match = regex.exec(clearString.substr(x));
  218.     if (match != null && match.length > 1 && match[1] != '') {
  219.         output += match[1];
  220.       x += match[1].length;
  221.     } else {
  222.       if (clearString[x] == ' ')
  223.         output += '+';
  224.       else {
  225.         var charCode = clearString.charCodeAt(x);
  226.         var hexVal = charCode.toString(16);
  227.         output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
  228.       }
  229.       x++;
  230.     }
  231.   }
  232.   return output;
  233. }
  234. </script>
  235.  
 


Global Footers

Code:
 
  1. <script>
  2. var default_avatar = "http://virtualforums.co.uk/images/smiley.gif";// change to your own default avatar
  3.  
  4. function grav_extract_email(txt){
  5.  
  6. var email_regex = new RegExp(/<gravatar:(.+?)>/);
  7.  
  8. var email_address = txt;
  9. var result = email_address.match(/<gravatar:(.+?)>/)
  10. var email = RegExp.$1
  11. return email;
  12. }
  13.  
  14. function grav_make(email){
  15. return "<gravatar:"+email+">";
  16. }
  17.  
  18.  
  19. function grav_load(default_av){
  20. f.hidden.value = f.hidden.value.replace('<gravatar:>', '');
  21. var email_regex = new RegExp(/<gravatar:(.+?)>/);
  22. f.gravatar.value=(f.hidden.value.match(email_regex)?grav_extract_email(RegExp.$1):'');
  23. f.hidden.value = f.hidden.value.replace(email_regex, '');
  24. if(f.avatar_url.value == default_av){
  25. f.avatar_url.value = "";
  26. f.avatar_height.value = '';
  27. f.avatar_width.value = '';
  28. }
  29. }
  30.  
  31.  
  32. function grav_save(default_av){
  33. f.hidden.value += grav_make(f.gravatar.value);
  34. if(f.avatar_url.value == "" && f.gravatar.value != ''){
  35. f.avatar_url.value = default_av;
  36. f.avatar_width.value = 100; // change these to match the default avatar's size
  37. f.avatar_height.value = 100;
  38. }
  39. }
  40.  
  41. if(document.profile_form && document.profile_form.signature){
  42. var f=document.profile_form;
  43. var insert_after=f.signature.parentNode.parentNode.parentNode;
  44. var insert=insert_after.cloneNode(true);
  45. insert.childNodes[0].firstChild.innerHTML='Gravatar Email:';
  46. insert.childNodes[1].innerHTML='<input name="gravatar" />';
  47. insert.childNodes[2].firstChild.innerHTML='Enter the email address associated with your <a href="http://gravatar.com">Gravatar</a> to use that instead of the avatar you have selected.';
  48. insert_after.parentNode.insertBefore(insert, insert_after.nextSibling);
  49. grav_load(default_avatar);
  50. if(document.addEventListener){
  51. f.addEventListener('submit', function(){grav_save(default_avatar)},false);
  52. }else{
  53. f.attachEvent('onsubmit', function(){grav_save(default_avatar)});
  54. }
  55. }
  56.  
  57. for(i=0;i<get('img','tag').length;i++){
  58.     if(get('img','tag')[i].alt == '[Avatar]'){
  59.         avatar = get('img','tag')[i];
  60.         avatar_def = avatar.src;
  61.         var email_regex = new RegExp(/<gravatar:(.+?)>/);
  62.         gravatar_mail=(vf_hiddenvars.match(email_regex)?grav_extract_email(RegExp.$1):'');
  63.         if(gravatar_mail != ''){
  64.         avatar.src = 'http://www.gravatar.com/avatar.php?gravatar_id='+md5(gravatar_mail)+'&default='+URLEncode(avatar_def)+'&size=100';
  65.         }
  66.     }
  67. }
  68.  
  69. </script>
  70.  
 


Please PM me with any problems, or post in the Requests/Support board.

~Artemis
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Re: Gravatar Integration (28th Mar 08 at 8:29pm UTC)
so many script tags! {Tongue Out}
Paddy
Full Member
***
Insane Clown

[Avatar]

Posts: 288
Status: Offline
Gender: Male
Location: Buffalo, New York
Age: 34
Joined:  
Reputation: 7%  


pmwwwtwitterskypeaimgtalk
Re: Gravatar Integration (6th Apr 08 at 5:33pm UTC)
Leave me 'lone.

If I have to put up with your grammatical syntax, you have to put up with my coding syntax.

~Artemis
ajay
Guest
Re: Gravatar Integration (7th Apr 08 at 1:36pm UTC)
 
so many script tags! {Tongue Out}


Lol, this is true {Tongue Out} .
 Printable View

All times are GMT+0 :: The current time is 2:11am
Page generated in 0.7913 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums