Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Patrique

Gravatar em ASP

Recommended Posts

Fala ae galera, precisei utilizar o gravatar em um projeto ASP, pesquisei e achei um script prontinho em ASP, por isso estarei disponibilizando ele aqui para quem vier a precisar.

 

arquivo _gravatar.asp

FUNCTION grAvatar(ByVal strEmail,ByVal intSize,ByVal intBorder,ByVal strRating,ByVal strDefault)
  DIM strTempText,objMd5
 
  SELECT CASE Request.ServerVariables("HTTP_HOST")
 
    CASE "127.0.0.1","localhost"
      IF strDefault<>"" THEN
        strTempText = strDefault
      ELSE
        strTempText = "images/avatar.png"
      END IF
    CASE ELSE
 
      SET objMd5 = NEW MD5
      objMd5.Text = strEmail
 
      strTempText = "http://www.gravatar.com/avatar.php"
 
      strTempText = strTempText & "?gravatar_id=" & objMD5.HEXMD5
 
      IF strRating<>"" THEN
        strTempText = strTempText & "&rating=" & strRating
      END IF
 
      IF intSize<>"" THEN
        strTempText = strTempText & "&size=" & intSize
      END IF
 
      IF intBorder<>"" THEN
        strTempText = strTempText & "&border=" & intBorder
      END IF
 
      IF strDefault<>"" THEN
        strTempText = strTempText & "&default=" & Server.UrlEncode(strDefault)
      END IF
 
  END SELECT
 
  grAvatar = strTempText
 
  SET objMd5 = NOTHING
  SET strTempText = NOTHING
END FUNCTION

arquivo _md5.asp

 

<%
'
' ASP MD5 implementation by Chris Read, version 1.0.1 (14th April 2003)
' Slightly modified (mostly to save space), see above URI for original version (inc comments!)
' Copyright(c)2003, Chris Read. All rights reserved.
'
Class MD5
Public Text
Public Property Get HEXMD5()
Dim lArray,lIndex,AA,BB,CC,DD,lStatus0,lStatus1,lStatus2,lStatus3
lArray=ConvertToWordArray(Text)
lStatus0=&H67452301
lStatus1=&HEFCDAB89
lStatus2=&H98BADCFE
lStatus3=&H10325476
For lIndex=0 To UBound(lArray) Step 16
AA=lStatus0
BB=lStatus1
CC=lStatus2
DD=lStatus3
FF lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+0),&H007,&HD76AA478
FF lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+1),&H00C,&HE8C7B756
FF lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+2),&H011,&H242070DB
FF lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+3),&H016,&HC1BDCEEE
FF lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+4),&H007,&HF57C0FAF
FF lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+5),&H00C,&H4787C62A
FF lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+6),&H011,&HA8304613
FF lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+7),&H016,&HFD469501
FF lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+8),&H007,&H698098D8
FF lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+9),&H00C,&H8B44F7AF
FF lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+10),&H011,&HFFFF5BB1
FF lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+11),&H016,&H895CD7BE
FF lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+12),&H007,&H6B901122
FF lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+13),&H00C,&HFD987193
FF lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+14),&H011,&HA679438E
FF lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+15),&H016,&H49B40821
GG lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+1),&H005,&HF61E2562
GG lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+6),&H009,&HC040B340
GG lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+11),&H00E,&H265E5A51
GG lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+0),&H014,&HE9B6C7AA
GG lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+5),&H005,&HD62F105D
GG lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+10),&H009,&H2441453
GG lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+15),&H00E,&HD8A1E681
GG lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+4),&H014,&HE7D3FBC8
GG lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+9),&H005,&H21E1CDE6
GG lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+14),&H009,&HC33707D6
GG lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+3),&H00E,&HF4D50D87
GG lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+8),&H014,&H455A14ED
GG lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+13),&H005,&HA9E3E905
GG lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+2),&H009,&HFCEFA3F8
GG lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+7),&H00E,&H676F02D9
GG lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+12),&H014,&H8D2A4C8A
HH lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+5),&H004,&HFFFA3942
HH lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+8),&H00B,&H8771F681
HH lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+11),&H010,&H6D9D6122
HH lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+14),&H017,&HFDE5380C
HH lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+1),&H004,&HA4BEEA44
HH lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+4),&H00B,&H4BDECFA9
HH lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+7),&H010,&HF6BB4B60
HH lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+10),&H017,&HBEBFBC70
HH lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+13),&H004,&H289B7EC6
HH lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+0),&H00B,&HEAA127FA
HH lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+3),&H010,&HD4EF3085
HH lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+6),&H017,&H4881D05
HH lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+9),&H004,&HD9D4D039
HH lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+12),&H00B,&HE6DB99E5
HH lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+15),&H010,&H1FA27CF8
HH lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+2),&H017,&HC4AC5665
II lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+0),&H006,&HF4292244
II lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+7),&H00A,&H432AFF97
II lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+14),&H00F,&HAB9423A7
II lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+5),&H015,&HFC93A039
II lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+12),&H006,&H655B59C3
II lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+3),&H00A,&H8F0CCC92
II lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+10),&H00F,&HFFEFF47D
II lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+1),&H015,&H85845DD1
II lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+8),&H006,&H6FA87E4F
II lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+15),&H00A,&HFE2CE6E0
II lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+6),&H00F,&HA3014314
II lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+13),&H015,&H4E0811A1
II lStatus0,lStatus1,lStatus2,lStatus3,lArray(lIndex+4),&H006,&HF7537E82
II lStatus3,lStatus0,lStatus1,lStatus2,lArray(lIndex+11),&H00A,&HBD3AF235
II lStatus2,lStatus3,lStatus0,lStatus1,lArray(lIndex+2),&H00F,&H2AD7D2BB
II lStatus1,lStatus2,lStatus3,lStatus0,lArray(lIndex+9),&H015,&HEB86D391
lStatus0=Add32(lStatus0,AA)
lStatus1=Add32(lStatus1,BB)
lStatus2=Add32(lStatus2,CC)
lStatus3=Add32(lStatus3,DD)
Next
HEXMD5=LCase(WordToHex(lStatus0) & WordToHex(lStatus1) & WordToHex(lStatus2) & WordToHex(lStatus3))
End Property
Private m_lMask()
Private m_lPow()
Private Function F(lX,lY,lZ)
F=(lX And lY) Or ((Not lX) And lZ)
End Function
Private Function G(lX,lY,lZ)
G=(lX And lZ) Or (lY And (Not lZ))
End Function
Private Function H(lX,lY,lZ)
H=lX Xor lY Xor lZ
End Function
Private Function I(lX,lY,lZ)
I=lY Xor (lX Or (Not lZ))
End Function
Private Sub FF(lA,lB,lC,lD,lX,lS,lAC)
lA=Add32(lA,Add32(Add32(F(lB,lC,lD),lX),lAC))
lA=RotateLeft32(lA,lS)
lA=Add32(lA,lB)
End Sub
Private Sub GG(lA,lB,lC,lD,lX,lS,lAC)
lA=Add32(lA,Add32(Add32(G(lB,lC,lD),lX),lAC))
lA=RotateLeft32(lA,lS)
lA=Add32(lA,lB)
End Sub
Private Sub HH(lA,lB,lC,lD,lX,lS,lAC)
lA=Add32(lA,Add32(Add32(H(lB,lC,lD),lX),lAC))
lA=RotateLeft32(lA,lS)
lA=Add32(lA,lB)
End Sub
Private Sub II(lA,lB,lC,lD,lX,lS,lAC)
lA=Add32(lA,Add32(Add32(I(lB,lC,lD),lX),lAC))
lA=RotateLeft32(lA,lS)
lA=Add32(lA,lB)
End Sub
Private Function ConvertToWordArray(sText)
Dim lTextLength,lNumberOfWords,lWordArray(),lBytePosition,lByteCount,lWordCount
lTextLength=Len(sText)
lNumberOfWords=(((lTextLength+8)\64)+1)*16
ReDim lWordArray(lNumberOfWords-1)
lBytePosition=0
lByteCount=0
Do Until lByteCount >= lTextLength
lWordCount=lByteCount\4
lBytePosition=(lByteCount Mod 4)*8
lWordArray(lWordCount)=lWordArray(lWordCount) Or ShiftLeft(Asc(Mid(sText,lByteCount+1,1)),lBytePosition)
lByteCount=lByteCount+1
Loop
lWordCount=lByteCount\4
lBytePosition=(lByteCount Mod 4)*8
lWordArray(lWordCount)=lWordArray(lWordCount) Or ShiftLeft(&H80,lBytePosition)
lWordArray(lNumberOfWords-2)=ShiftLeft(lTextLength,3)
lWordArray(lNumberOfWords-1)=ShiftRight(lTextLength,29)
ConvertToWordArray=lWordArray
End Function
Private Function WordToHex(lValue)
Dim lTemp
For lTemp=0 To 3
WordToHex=WordToHex & Right("00" & Hex(ShiftRight(lValue,lTemp*8) And m_lMask(7)),2)
Next
End Function
Private Function ShiftLeft(lValue,iBits)
ShiftLeft=0
If iBits=0 then
ShiftLeft=lValue
ElseIf iBits=31 Then
If lValue And 1 Then
ShiftLeft=&H80000000
End If
Else
If (lValue And m_lPow(31-iBits)) Then
ShiftLeft=((lValue And m_lMask(31-(iBits+1)))*m_lPow(iBits)) Or &H80000000
Else
ShiftLeft=((lValue And m_lMask(31-iBits))*m_lPow(iBits))
End If
End If
End Function
Private Function ShiftRight(lValue,iBits)
ShiftRight=0
If iBits=0 then
ShiftRight=lValue
ElseIf iBits=31 Then
If lValue And &H80000000 Then
ShiftRight=1
End If
Else
ShiftRight=(lValue And &H7FFFFFFE)\m_lPow(iBits)
If (lValue And &H80000000) Then
ShiftRight=(ShiftRight Or (&H40000000\m_lPow(iBits-1)))
End If
End If
End Function
Private Function RotateLeft32(lValue,iBits)
RotateLeft32=ShiftLeft(lValue,iBits) Or ShiftRight(lValue,(32-iBits))
End Function
Private Function Add32(lA,lB)
Dim lA4,lB4,lA8,lB8,lA32,lB32,lA31,lB31,lTemp
lA32=lA And &H80000000
lB32=lB And &H80000000
lA31=lA And &H40000000
lB31=lB And &H40000000
lTemp=(lA And &H3FFFFFFF)+(lB And &H3FFFFFFF)
If lA31 And lB31 Then
lTemp=lTemp Xor &H80000000 Xor lA32 Xor lB32
ElseIf lA31 Or lB31 Then
If lTemp And &H40000000 Then
lTemp=lTemp Xor &HC0000000 Xor lA32 Xor lB32
Else
lTemp=lTemp Xor &H40000000 Xor lA32 Xor lB32
End If
Else
lTemp=lTemp Xor lA32 Xor lB32
End If
Add32=lTemp
End Function
Private Sub Class_Initialize()
Text=""
Redim m_lMask(30)
Redim m_lPow(30)
m_lMask(0)=CLng(&H00000001&)
m_lMask(1)=CLng(&H00000003&)
m_lMask(2)=CLng(&H00000007&)
m_lMask(3)=CLng(&H0000000F&)
m_lMask(4)=CLng(&H0000001F&)
m_lMask(5)=CLng(&H0000003F&)
m_lMask(6)=CLng(&H0000007F&)
m_lMask(7)=CLng(&H000000FF&)
m_lMask(8)=CLng(&H000001FF&)
m_lMask(9)=CLng(&H000003FF&)
m_lMask(10)=CLng(&H000007FF&)
m_lMask(11)=CLng(&H00000FFF&)
m_lMask(12)=CLng(&H00001FFF&)
m_lMask(13)=CLng(&H00003FFF&)
m_lMask(14)=CLng(&H00007FFF&)
m_lMask(15)=CLng(&H0000FFFF&)
m_lMask(16)=CLng(&H0001FFFF&)
m_lMask(17)=CLng(&H0003FFFF&)
m_lMask(18)=CLng(&H0007FFFF&)
m_lMask(19)=CLng(&H000FFFFF&)
m_lMask(20)=CLng(&H001FFFFF&)
m_lMask(21)=CLng(&H003FFFFF&)
m_lMask(22)=CLng(&H007FFFFF&)
m_lMask(23)=CLng(&H00FFFFFF&)
m_lMask(24)=CLng(&H01FFFFFF&)
m_lMask(25)=CLng(&H03FFFFFF&)
m_lMask(26)=CLng(&H07FFFFFF&)
m_lMask(27)=CLng(&H0FFFFFFF&)
m_lMask(28)=CLng(&H1FFFFFFF&)
m_lMask(29)=CLng(&H3FFFFFFF&)
m_lMask(30)=CLng(&H7FFFFFFF&)
m_lPow(0)=CLng(&H00000001&)
m_lPow(1)=CLng(&H00000002&)
m_lPow(2)=CLng(&H00000004&)
m_lPow(3)=CLng(&H00000008&)
m_lPow(4)=CLng(&H00000010&)
m_lPow(5)=CLng(&H00000020&)
m_lPow(6)=CLng(&H00000040&)
m_lPow(7)=CLng(&H00000080&)
m_lPow(8)=CLng(&H00000100&)
m_lPow(9)=CLng(&H00000200&)
m_lPow(10)=CLng(&H00000400&)
m_lPow(11)=CLng(&H00000800&)
m_lPow(12)=CLng(&H00001000&)
m_lPow(13)=CLng(&H00002000&)
m_lPow(14)=CLng(&H00004000&)
m_lPow(15)=CLng(&H00008000&)
m_lPow(16)=CLng(&H00010000&)
m_lPow(17)=CLng(&H00020000&)
m_lPow(18)=CLng(&H00040000&)
m_lPow(19)=CLng(&H00080000&)
m_lPow(20)=CLng(&H00100000&)
m_lPow(21)=CLng(&H00200000&)
m_lPow(22)=CLng(&H00400000&)
m_lPow(23)=CLng(&H00800000&)
m_lPow(24)=CLng(&H01000000&)
m_lPow(25)=CLng(&H02000000&)
m_lPow(26)=CLng(&H04000000&)
m_lPow(27)=CLng(&H08000000&)
m_lPow(28)=CLng(&H10000000&)
m_lPow(29)=CLng(&H20000000&)
m_lPow(30)=CLng(&H40000000&)
End Sub
End Class
%>

arquivo exemplo.asp

<!--#include file="_gravatar.asp"-->
<!--#include file="_md5.asp"-->
 
<body>
<%
Response.Write "<img" _
    & " src=""" & grAvatar("example@example.com",40,0,"R","") & """>" _
    & " alt=""avatar""" _
    & ">"
%>
</body>

Vai precisar o md5, bas

Compartilhar este post


Link para o post
Compartilhar em outros sites

Mas qual o objetivo dele? Lendo o código e pelo nome da a entender que é gravar avatar.

 

Seria isso mesmo?

 

Obs. não conhecia esse site Gravatar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Aqui no brasil ele ainda não é tãooooooooo conhecido, mais o objetivo dele é criar um avatar único e ao entrar em um blog por exemplo e comentar o sistema automaticamente irá identificar e mostrar o avatar que estiver cadastrado neste site http://en.gravatar.com/site/signup/

 

Como a maioria dos blogs abrem a postagem dos comentários sem a necessidade de se cadastrar este site é uma mão na roda, pois assim o usuário cadastra o seu avatar no sistema deles e quando jogar o email lá no comentário o sistema do blog irá buscar o avatar do usuário neste outro serviço.

 

Para saber mais veja aqui

 

http://blog.agenciaduca.com.br/suporte/gravatar-o-que-e-como-criar-um-e-como-colocar-em-seu-blog/

 

[]'s

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ele é bem interessante para blogs, este sistema se tornou famoso pois a maioria dos blogs em wordpress ativam este recurso.

 

[]'s

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.