{"id":59,"date":"2010-02-21T00:00:00","date_gmt":"2010-02-21T00:00:00","guid":{"rendered":"http:\/\/bloodforge.com\/?p=59"},"modified":"2020-02-20T02:30:17","modified_gmt":"2020-02-20T02:30:17","slug":"blogengine-net-recaptcha-0-91-installation-instructions","status":"publish","type":"post","link":"https:\/\/bloodforge.azurewebsites.net\/index.php\/2010\/02\/21\/blogengine-net-recaptcha-0-91-installation-instructions\/","title":{"rendered":"Blogengine.NET Recaptcha 0.91 Installation Instructions"},"content":{"rendered":"\n<p><strong>NOTE: THESE INSTALLATION INSTRUCTIONS HAVE BEEN UPDATED:<\/strong>\u00a0To get the latest version, follow the instructions located at: <em><strong>NO LONGER AVAILABLE<\/strong><\/em><\/p>\n\n\n\n<p>First, the\u00a0linked ZIP file\u00a0contains the updated files for installing the Recaptcha control.<\/p>\n\n\n\n<p>UPDATES:<\/p>\n\n\n\n<ul><li>Version 0.92 &#8211; The recaptcha will no longer get focus after it has been loaded. Install procedure is unchanged from version 0.91.<\/li><li>Version 0.91 &#8211; Changed the way that Recaptcha is verified.&nbsp; It should no longer be possible to bypass the recaptcha by manually executing JavaScript on the page.<\/li><li>Version 0.9 &#8211; Initial Version<\/li><\/ul>\n\n\n\n<p><strong>Quick Installation<\/strong><\/p>\n\n\n\n<p>First, back up your files in case you need to revert for any reason. If you have not modified any of the BlogEngine files, you can extract the ZIP linked to above and place all of the files into their proper locations ( the unzipped files should contain a folder structure ). There is no need to recompile.<\/p>\n\n\n\n<p>You may need to force a refresh of your browser on the site, since there is a JavaScript file updated, and most browsers like to cache these files.<\/p>\n\n\n\n<p><strong>Manual Installation<\/strong><\/p>\n\n\n\n<p>Below is a complete summary of what needs to be altered to make the Recaptcha control work.&nbsp; You\u2019ll need to do this for any files manually modified in your BlogEngine.NET instance.<\/p>\n\n\n\n<p><strong>\/App_Code\/Controls\/Recaptcha.cs<\/strong><\/p>\n\n\n\n<p>This file was not included in the BlogEngine.NET installation, and should be placed in the \u2018\/App_Code\/Controls\/\u2019 folder.<\/p>\n\n\n\n<p><strong>\/blog.js<\/strong><\/p>\n\n\n\n<p>There are three functions in this file that need to be updated to the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>onCommentError: function(error, context) {\n    BlogEngine.toggleCommentSavingIndicators(false);\n    error = error || \"Unknown error occurred.\";\n    var iDelimiterPos = error.indexOf(\"|\");\n    if (iDelimiterPos > 0) {\n        error = error.substr(0, iDelimiterPos);\n        \/\/ Remove numbers from end of error message.\n        while (error.length > 0 &amp;&amp; error.substr(error.length - 1, 1).match(\/\\d\/)) {\n            error = error.substr(0, error.length - 1);\n        }\n    }\n    \n    if( document.getElementById('recaptcha_response_field') )\n    {\n       Recaptcha.reload();\n    }\n    alert(\"Sorry, the following error occurred while processing your comment:\\n\\n\" + error);\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>addComment: function(preview) {\n    var isPreview = preview == true;\n    if (!isPreview) {\n        BlogEngine.toggleCommentSavingIndicators(true);\n        this.$(\"status\").innerHTML = BlogEngine.i18n.savingTheComment;\n    }\n    var author = BlogEngine.comments.nameBox.value;\n    var email = BlogEngine.comments.emailBox.value;\n    var website = BlogEngine.comments.websiteBox.value;\n    var country = BlogEngine.comments.countryDropDown ? BlogEngine.comments.countryDropDown.value : \"\";\n    var content = BlogEngine.comments.contentBox.value;\n    var notify = BlogEngine.$(\"cbNotify\").checked;\n    var captcha = BlogEngine.comments.captchaField.value;\n    var replyToId = BlogEngine.comments.replyToId ? BlogEngine.comments.replyToId.value : \"\";\n    \n    var recaptchaResponseField = document.getElementById('recaptcha_response_field');        \n    var recaptchaResponse = recaptchaResponseField ? recaptchaResponseField.value : \"\";\n    \n    var recaptchaChallengeField = document.getElementById('recaptcha_challenge_field');\n    var recaptchaChallenge = recaptchaChallengeField ? recaptchaChallengeField.value : \"\";\n    var avatarInput = BlogEngine.$(\"avatarImgSrc\");\n    var avatar = (avatarInput &amp;&amp; avatarInput.value) ? avatarInput.value : \"\";\n    var callback = isPreview ? BlogEngine.endShowPreview : BlogEngine.appendComment;\n    var argument = author + \"-|-\" + email + \"-|-\" + website + \"-|-\" + country + \"-|-\" + content + \"-|-\" + notify + \"-|-\" + isPreview + \"-|-\" + captcha + \"-|-\" + replyToId + \"-|-\" + avatar + \"-|-\" + recaptchaResponse + \"-|-\" + recaptchaChallenge;\n    WebForm_DoCallback(BlogEngine.comments.controlId, argument, callback, 'comment', BlogEngine.onCommentError, false);\n    if (!isPreview &amp;&amp; typeof (OnComment) != \"undefined\")\n        OnComment(author, email, website, country, content);\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>appendComment: function(args, context) {\n    if (context == \"comment\") {\n    \n        if( document.getElementById('recaptcha_response_field') )\n        {\n           Recaptcha.reload();\n        }\n    \n        if( args == \"RecaptchaIncorrect\" )\n        {\n           if( document.getElementById(\"spnCaptchaIncorrect\") ) document.getElementById(\"spnCaptchaIncorrect\").style.display = \"\";\n           BlogEngine.toggleCommentSavingIndicators(false);\n        }\n        else\n        {\n        \n            if( document.getElementById(\"spnCaptchaIncorrect\") ) document.getElementById(\"spnCaptchaIncorrect\").style.display = \"none\";\n            var commentList = BlogEngine.$(\"commentlist\");\n            if (commentList.innerHTML.length &lt; 10)\n                commentList.innerHTML = \"&lt;h1 id='comment'>\" + BlogEngine.i18n.comments + \"&lt;\/h1>\"\n            \/\/ add comment html to the right place\n            var id = BlogEngine.comments.replyToId ? BlogEngine.comments.replyToId.value : '';\n            if (id != '') {\n                var replies = BlogEngine.$('replies_' + id);\n                replies.innerHTML += args;\n            } else {\n                commentList.innerHTML += args;\n                commentList.style.display = 'block';\n            }\n            \/\/ reset form values\n            BlogEngine.comments.contentBox.value = \"\";\n            BlogEngine.comments.contentBox = BlogEngine.$(BlogEngine.comments.contentBox.id);\n            BlogEngine.toggleCommentSavingIndicators(false);\n            BlogEngine.$(\"status\").className = \"success\";\n            if (!BlogEngine.comments.moderation)\n                BlogEngine.$(\"status\").innerHTML = BlogEngine.i18n.commentWasSaved;\n            else\n                BlogEngine.$(\"status\").innerHTML = BlogEngine.i18n.commentWaitingModeration;\n            \/\/ move form back to bottom\n            var commentForm = BlogEngine.$('comment-form');\n            commentList.appendChild(commentForm);\n            \/\/ reset reply to\n            if (BlogEngine.comments.replyToId) BlogEngine.comments.replyToId.value = '';\n            if (BlogEngine.$('cancelReply')) BlogEngine.$('cancelReply').style.display = 'none';\n        \n        }\n    }\n    BlogEngine.$(\"btnSaveAjax\").disabled = false;\n}<\/code><\/pre>\n\n\n\n<p><strong>\/User controls\/CommentView.ascx.cs<\/strong><\/p>\n\n\n\n<p>One method in this file needs to be updated:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\/ &lt;summary>\n\/\/\/ Processes a callback event that targets a control.\n\/\/\/ &lt;\/summary>\n\/\/\/ &lt;param name=\"eventArgument\">A string that represents an event argument to pass to the event handler.&lt;\/param>\npublic void RaiseCallbackEvent(string eventArgument)\n{\n    if (!BlogSettings.Instance.IsCommentsEnabled)\n        return;\n    string&#91;] args = eventArgument.Split(new string&#91;] { \"-|-\" }, StringSplitOptions.None);\n    string author = args&#91;0];\n    string email = args&#91;1];\n    string website = args&#91;2];\n    string country = args&#91;3];\n    string content = args&#91;4];\n    bool notify = bool.Parse(args&#91;5]);\n    bool isPreview = bool.Parse(args&#91;6]);\n    string sentCaptcha = args&#91;7];\n    \/\/If there is no \"reply to\" comment, args&#91;8] is empty\n    Guid replyToCommentID = String.IsNullOrEmpty(args&#91;8]) ? Guid.Empty : new Guid(args&#91;8]);\n    string avatar = args&#91;9];\n    string recaptchaResponse = args&#91;10];\n    string recaptchaChallenge = args&#91;11];\n    if (!isPreview &amp;&amp; recaptcha.RecaptchaEnabled &amp;&amp; recaptcha.RecaptchaNecessary)\n    {\n        if (!recaptcha.ValidateAsync(recaptchaResponse, recaptchaChallenge))\n        {\n            _Callback = \"RecaptchaIncorrect\";\n            return;\n        }\n    }\n    string storedCaptcha = hfCaptcha.Value;\n    if (sentCaptcha != storedCaptcha)\n        return;\n    Comment comment = new Comment();\n    comment.Id = Guid.NewGuid();\n    comment.ParentId = replyToCommentID;\n    comment.Author = Server.HtmlEncode(author);\n    comment.Email = email;\n    comment.Content = Server.HtmlEncode(content);\n    comment.IP = Request.UserHostAddress;\n    comment.Country = country;\n    comment.DateCreated = DateTime.Now;\n    comment.Parent = Post;\n    comment.IsApproved = !BlogSettings.Instance.EnableCommentsModeration;\n    comment.Avatar = avatar.Trim();\n    if (Page.User.Identity.IsAuthenticated)\n        comment.IsApproved = true;\n    if (website.Trim().Length > 0)\n    {\n        if (!website.ToLowerInvariant().Contains(\":\/\/\"))\n            website = \"http:\/\/\" + website;\n        Uri url;\n        if (Uri.TryCreate(website, UriKind.Absolute, out url))\n            comment.Website = url;\n    }\n    if (!isPreview)\n    {\n        if (notify &amp;&amp; !Post.NotificationEmails.Contains(email))\n            Post.NotificationEmails.Add(email);\n        else if (!notify &amp;&amp; Post.NotificationEmails.Contains(email))\n            Post.NotificationEmails.Remove(email);\n        Post.AddComment(comment);\n        SetCookie(author, email, website, country);\n    }\n    string path = Utils.RelativeWebRoot + \"themes\/\" + BlogSettings.Instance.Theme + \"\/CommentView.ascx\";\n    CommentViewBase control = (CommentViewBase)LoadControl(path);\n    control.Comment = comment;\n    control.Post = Post;\n    using (StringWriter sw = new StringWriter())\n    {\n        control.RenderControl(new HtmlTextWriter(sw));\n        _Callback = sw.ToString();\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>\/User controls\/CommentView.ascx<\/strong><\/p>\n\n\n\n<p>Finally, the following line needs to be added to this file, at the location you would like the Recaptcha control to appear. Remember to update your TabIndexes for proper tab button navigation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;blog:RecaptchaControl ID=\"recaptcha\" runat=\"server\" TabIndex=\"8\" \/><\/code><\/pre>\n\n\n\n<p><strong>Recaptcha Settings<\/strong><\/p>\n\n\n\n<p>You can edit the Recaptcha settings via the Extension Manager. You probably should enter in your own Public and Private keys, as the provided keys are for this site ( they are global, so they will work on other sites ).<\/p>\n\n\n\n<p><strong>Recaptcha Theming<\/strong><\/p>\n\n\n\n<p>There are 4 built-in themes that you can change via the ExtensionManager. You can also create your own theme by adding it in the following way to the Recaptcha control:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;blog:RecaptchaControl ID=\"recaptcha\" runat=\"server\" TabIndex=\"8\" Theme=\"MyCustomTheme\" \/><\/code><\/pre>\n\n\n\n<p> For detailed instructions on what your theme needs to look like, visit the\u00a0<a href=\"http:\/\/www.recaptcha.net\/\">Recaptcha site<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>NOTE: THESE INSTALLATION INSTRUCTIONS HAVE BEEN UPDATED:\u00a0To get the latest version, follow the instructions located at: NO LONGER AVAILABLE First, the\u00a0linked ZIP file\u00a0contains the updated files for installing the Recaptcha control. UPDATES: Version 0.92 &#8211; The recaptcha will no longer get focus after it has been loaded. Install procedure is unchanged from version 0.91. Version [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":1,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":60,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/59\/revisions\/60"}],"wp:attachment":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}