New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: FoxPro

Using Akismet with Visual Foxpro

99 Views
Copy Code Show/Hide Line Numbers
*** Setup Transaction
lcAkismetKey = "" &&Get your API key at http://wordpress.com/signup/ and click "Just a username, please."
lcBlogURL = Alltrim(Request.Form("BlogURL")) &&Blog URL
lcUserIP = Alltrim(Request.GetIPAddress())
lcUserAgent = Alltrim(Request.GetBrowser())
lcCommentType = Alltrim(Request.Form("UserType")) &&Choices: blank, comment, trackback, pingback, or a made up value like "registrant".
lcCommentAuthor = Alltrim(Request.Form("UserName")) &&FYI: 'viagra-test-123' forces true a.k.a. "spam"
lcAuthorEmail = Alltrim(Request.Form("UserEmail"))
lcAuthorUrl = Alltrim(Request.Form("UserWebsite"))
lcComment = URLEncode(Alltrim(Request.Form("UserComment")))
 
*** Authenticate Key
oHTTP=Createobject("wwHttp")
oHTTP.AddPostKey("key",lcAkismetKey)
oHTTP.AddPostKey("blog",lcBlogURL)
oHTTP.cExtraHeaders = oHTTP.cExtraHeaders + "User-Agent: West Wind Web Connection/4.68 | Akismet/1.11" + Chr(13) + Chr(10)
lcHTML = oHTTP.HTTPGet("http://rest.akismet.com/1.1/verify-key","","")
oHTTP.HTTPClose()
oHTTP = Null
***
 
If Alltrim(Lower(lcHTML)) = "valid" &&Key Authenticates 'valid', check comment.
    oHTTP=Createobject("wwHttp")
    oHTTP.AddPostKey("blog", lcBlogURL)
    oHTTP.AddPostKey("user_ip", lcUserIP)
    oHTTP.AddPostKey("user_agent", lcUserAgent)
    oHTTP.AddPostKey("comment_type", lcCommentType)
    oHTTP.AddPostKey("comment_author", lcCommentAuthor)
    oHTTP.AddPostKey("comment_author_email", lcAuthorEmail)
    oHTTP.AddPostKey("comment_author_url", lcAuthorUrl)
    oHTTP.AddPostKey("comment_content", lcComment)
*** Returns 'true' if spam, 'false' if not spam.
    lcHTML = oHTTP.HTTPGet("http://"+lcAkismetKey+".rest.akismet.com/1.1/comment-check","","")
    oHTTP.HTTPClose()
    oHTTP = Null
    Do Case
    Case lcHTML = "true"
        Response.WriteLn(["Key Authenticated. Comment is Spam."])
    Case lcHTML = "false"
        Response.WriteLn(["Key Authenticated. Comment is NOT Spam."])
    Otherwise
        Response.WriteLn(["Key Authenticated. Spam Status Unknown."])
    Endcase
Else &&Key Authenticates 'invalid', comment NOT checked
    Response.WriteLn(["Key NOT Authenticated. Spam Status Unknown."])
Endif
by Shaun Kester
  October 18, 2009 @ 10:59pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate