Fix for Disqus COMMENT COUNT problem

Topics: Business Logic Layer
Jun 26, 2015 at 11:28 AM
Hi,

These is a file "BlogEngine\BlogEngine.Core\Web\Scripting\Helpers.cs" at line 117 including a code snippet for Disqus. But it's been changed for a long time.

The code:

            if (BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus)
            {
                sb.Append("<script type=\"text/javascript\"> \n");
                sb.Append("//<![CDATA[ \n");
                sb.Append("(function() { ");
                sb.Append("var links = document.getElementsByTagName('a'); ");
                sb.Append("var query = '?'; ");
                sb.Append("for(var i = 0; i < links.length; i++) { ");
                sb.Append("if(links[i].href.indexOf('#disqus_thread') >= 0) { ");
                sb.Append("query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&'; ");
                sb.Append("}}");
                sb.Append("document.write('<script charset=\"utf-8\" type=\"text/javascript\" src=\"http://disqus.com/forums/");
                sb.Append(BlogSettings.Instance.DisqusWebsiteName);
                sb.Append("/get_num_replies.js' + query + '\"></' + 'script>'); ");
                sb.Append("})(); \n");
                sb.Append("//]]> \n");
                sb.Append("</script> \n");
            }
should change to:
            if (BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus)
            {
                sb.Append("<script type=\"text/javascript\">");
                sb.Append("    var disqus_shortname = '" + BlogSettings.Instance.DisqusWebsiteName + "';");
                sb.Append("    (function () {");
                sb.Append("        var s = document.createElement('script'); s.async = true;");
                sb.Append("        s.type = 'text/javascript';");
                sb.Append("        s.src = '//' + disqus_shortname + '.disqus.com/count.js';");
                sb.Append("        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);");
                sb.Append("    }());");
                sb.Append("</script>");
            }