I added keywordLuv and CommentLuv to this website

by Jeff 18. May 2009 09:42

Still not ready for release but here is the experamental code I'm using to enable CommentLuv, I installed it with the new website look.

Here is the script for enabling CommentLuv there are still a few features that need to be added.

Once I'm done I'll upload all the code changes with instructions on how to implement the new code

var commentLuv = {
    enabled: true,
    message: "CommentLuv enabled",
    link: "<!--commentLuvStart--><p class=\"commentLuv\"><abbr><em>{0}'s last blog post.. <a href=\"{1}\" target=\"_blank\">{2}</a></em></abbr></p>",
    //link: "<!--commentLuvStart--><br/><br/>{0}'s last blog post.. <a href=\"{1}\" target=\"_blank\">{2}</a>",
    init: function() {
        try {
            var websiteBox = BlogEngine.comments.websiteBox;

            if (websiteBox == null) return;

            // attach UI elements: checkbox and label
            commentLuv.appendElements();

            // keep ref for old addComment to be used later
            BlogEngine.addComment_Old = BlogEngine.addComment;

            // create a new addComment function that support commentLuv
            BlogEngine.addComment = function(preview) {
                // if no data was found or commentluv is disabled by the user exit, use addComment_Old and exit
                if (commentLuv.data == null || !commentLuv.enabled) {
                    BlogEngine.addComment_Old(preview);

                    return;
                };

                // check for html injection
                if (BlogEngine.comments.contentBox.value.indexOf("<!--commentLuvStart-->") > -1) return false;
               
                try {
                    // process data from commentLuv web service, service is called in websitebox.onchange and when posibly during init
                    var title = commentLuv.data.links[0].title;
                    var url = commentLuv.data.links[0].url;
                    var content = BlogEngine.comments.contentBox.value;
                    var author = commentLuv.getAuthor();

                    if (preview) {
                        // commentLuv ref for preview, used to revert back to comment without latest post
                        commentLuv.comments = BlogEngine.comments.contentBox.value;
                    };

                    var link = commentLuv.link;

                    // replace comment contents with content and latest post
                    BlogEngine.comments.contentBox.value = BlogEngine.comments.contentBox.value + link.replace("{0}", author).replace("{1}", url).replace("{2}", title);
                }
                catch (errObj) {
                    // unknown error, just use old addComment_Old and exit, not critical that commentluv works
                    BlogEngine.addComment_Old(preview);

                    return;
                };

                // prep work done add comment
                BlogEngine.addComment_Old(preview);

                if (preview) {
                    // the user requested a preview revert back to original comments
                    BlogEngine.comments.contentBox.value = commentLuv.comments;
                }
                else {
                    // clear
                    BlogEngine.comments.contentBox.value = "";
                    commentLuv.comments = "";
                };
            }; // BlogEngine.addComment end

            // add onchange handler to websitebox to capture url changes
            $addHandler(websiteBox, "change", commentLuv.website_onChange);

            // test if url was cached
            if (websiteBox.value.length == 0) return;

            // url was cached contact server to get latest post
            var url = "commentLuv.axd?website=" + websiteBox.value;

            BlogEngine.createCallback(url, function(response) {
                commentLuv.data = eval(response);

                commentLuv.updateLastPostMessage();
            });
        }
        catch (errObj) {
            alert("Unknown javascript error in CommentLuv:init, error: " + errObj.description);
        };
    },
    clearLastPostElement: function() {
        var lastPostElement = commentLuv.lastPostElement;

        if (lastPostElement == null) return;

        try {
            while (lastPostElement.firstChild != null) {
                lastPostElement.removeChild(lastPostElement.firstChild);
            };
        }
        catch (ignorErr) {
            // do nothing
        };
    },
    updateLastPostMessage: function() {
        try {
            var lastPostElement = commentLuv.lastPostElement;

            if (lastPostElement == null) return;

            commentLuv.clearLastPostElement();

            var title = commentLuv.data.links[0].title;
            var url = commentLuv.data.links[0].url;
            var author = commentLuv.getAuthor();

            lastPostElement.appendChild(document.createTextNode(author + "'s last blog post.. "));

            var link = document.createElement("a");

            lastPostElement.appendChild(link);

            link.target = "_blank";
            link.href = url;

            link.appendChild(document.createTextNode(title));
        }
        catch (errObj) {
            window.setTimeout(1000, commentLuv.updateLastPostMessage);

            alert("Unknown javascript error in CommentLuv:updateLastPostMessage. Error: " + errObj.description);
        };
    },
    appendElements: function() {
        // this function contains basic javascrit not going to document
        try {
            var cbNotify = $("cbNotify");

            if (cbNotify == null) {
                alert("cbNotify not found");

                return;
            };

            var parent = cbNotify.parentNode;

            var lastPostElement = commentLuv.lastPostElement = document.createElement("p");

            lastPostElement.id = "lastPostMessage";

            parent.insertBefore(lastPostElement, cbNotify);

            var enabledCheckbox = document.createElement("input");

            enabledCheckbox.type = "checkbox";
            parent.insertBefore(enabledCheckbox, cbNotify);

            $addHandler(enabledCheckbox, "change", function() {
                commentLuv.enabled = !commentLuv.enabled;
            });

            enabledCheckbox.checked = true;
            enabledCheckbox.id = "commentLuvCheckbox";
            enabledCheckbox.style.width = "auto";
            enabledCheckbox.style.display = "inline";

            // using a label element wouldn't display properly, moving on by using span
            var label = document.createElement("span");

            label.appendChild(document.createTextNode(commentLuv.message));

            parent.insertBefore(label, cbNotify);

            //label.htmlFor = enabledCheckbox.id;
            label.style.width = "auto";
            label.style.display = "inline";
            label.style.cssFloat = "none";

            enabledCheckbox.setAttribute("tabindex", 7);
            cbNotify.setAttribute("tabindex", 8);

            //width:auto;float:none;display:inline
            parent.insertBefore(document.createElement("br"), cbNotify);
            parent.insertBefore(document.createElement("br"), cbNotify);
        }
        catch (errObj) {
            alert("Unknow javascript error in commentLuv:appendElements. Error, " + errObj.description);
        };
    },
    getAuthor: function() {
        // if keyword is passed in with the author name parse out the keywords and return the author name
        var author = BlogEngine.comments.nameBox.value;
        var keywordStartIndex = author.indexOf("@");

        if (keywordStartIndex < 0)
            return author;

        return author = author.substring(0, keywordStartIndex)
    },
    addHandler: function(element, eventName, handler) {
        // basic add handler function
        if (element.attachEvent)
            element.attachEvent('on' + eventName, handler);
        else if (element.addEventListener)
            element.addEventListener(eventName, handler, false);
        else
            throw "browser not supported";
    },
    website_onChange: function() {
        try {
            // if the websitetextbox changes we call the server to get the latest post here
            if (!commentLuv.enabled) return;

            commentLuv.data = null;
            commentLuv.clearLastPostElement();

            if (BlogEngine.comments.websiteBox.value.length == 0) return;

            var url = "commentLuv.axd?website=" + BlogEngine.comments.websiteBox.value;

            BlogEngine.createCallback(url, function(response) {
                commentLuv.data = eval(response);

                commentLuv.updateLastPostMessage();
            });
        }
        catch (errObj) {
            alert("Unknown javascript error in CommentLuv:website_onChange. Error: " + errObj.description);
        };
    }
};

//create a global addHandler function
if (typeof ($addHandler) == "undefined")
    window.$addHandler = commentLuv.addHandler;

// hook into the app load event so that commentLuv can attach to the elements
BlogEngine.addLoadEvent(commentLuv.init);

 

here is the CommentLuv HTTPHandler code

[code]

#region Using

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Web;
using System.Web.Security;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Net;

#endregion

namespace BlogEngine.Web.HttpHandlers
{
    /// <summary>
    /// CommentLuv handler used to get the commentors latest post
    /// </summary>
    public class CommentLuv : IHttpHandler
    {

        public CommentLuv()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        #region IHttpHandler Members

        /// <summary>
        /// Gets a value indicating whether another request can use the <see cref="T:System.Web.IHttpHandler"></see> instance.
        /// </summary>
        /// <value></value>
        /// <returns>true if the <see cref="T:System.Web.IHttpHandler"></see> instance is reusable; otherwise, false.</returns>
        public bool IsReusable
        {
            get { return false; }
        }

        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            WriteCommentLuvInfo(context, context.Response.OutputStream);
        }

        #endregion
       
        internal void WriteCommentLuvInfo(HttpContext context, Stream stream)
        {
            try
            {
                // ref http://msmvps.com/blogs/coad/archive/2004/04/14/5013.aspx
                string website = context.Request.QueryString["website"]; // "http://www.ScamResearchCenter.com/";

                if (string.IsNullOrEmpty(website)) return;

                int cl_version = 2;
                string url = "http://www.commentluv.com/commentluvinc/ajaxcl8254.php?url=" + website + "&version=" + cl_version + "&callback=?";

                WebClient c = new WebClient();

                StreamWriter writer = new StreamWriter(stream);

                // Download the XML into a string
                writer.Write(ASCIIEncoding.Default.GetString(c.DownloadData(url)).Substring(1));
                writer.Flush();
                writer.Close();
            }
            catch
            {
                // do nothing, if it fails it's not critical just move on
                return;
            }
        }
    }

[/code]

Once I have finished my theme I'll upload a complete code example

Bookmark and Share

Tags:

Asp.net | BlogEngine.net | Extensions | Widgets

Comments

7/14/2009 5:11:24 AM #

Jack

Welcome to the dofollow community!!
Do follow and comment luv are win win scenarios for the blogger and poster. I know there are drawbacks due to spam but hopefully the benefits outweigh the drawbacks.

Jack United States

7/14/2009 10:42:48 AM #

Alex Sysoef

DoFollow and CommentLuv is a killer combination and I'm sure you will find it beneficial to your blog!

Welcome!

Alex Sysoef's last blog post.. How To Get Paid Blogging About Your Hobby

Alex Sysoef United States

7/15/2009 6:27:30 AM #

Webdesign ny

Hi, getting backlinks or inbound links from dofollow blog is very easy. But getting quality backlinks or inbound links is a difficult task.

Webdesign ny's last blog post.. A feed could not be found at http://www.webdatamation.com

Webdesign ny India

7/15/2009 8:15:11 AM #

Webdevelopment ny

Hi, your site back link structure is an important aspect of your search engine optimization and relates to the number and quality of the sites that link to your site.

Webdevelopment ny's last blog post.. A feed could not be found at http://www.webdatamation.com

Webdevelopment ny India

7/19/2009 11:30:13 AM #

saurabh@Webinar services

thanks for adding these wonderful plug ins in your blog. its great for getting back links and increase traffic.

saurabh's last blog post.. A feed could not be found at http://www.videoseminarlive.com

saurabh From Webinar services India

7/20/2009 6:48:10 AM #

sulumits retsambew

nice tips thanks

sulumits retsambew's last blog post.. Mengembalikan jati Diri bangsa Do you know what is it ?

sulumits retsambew United States

8/30/2009 6:08:40 PM #

 online watch hollywood movies

commentluv is the best serves for us and i love it

online watch hollywood movies United States

9/5/2009 2:14:40 AM #

Professional SEO Company

Hello.

I would Like to read more on this from you.

Thanks for such a nice post.

Regards.....

Professional SEO Company United States

9/24/2009 12:38:33 AM #

kang badot

commentluv is a good strategies to link building, thanks for enable commentluv on this site

kang badot Indonesia

10/3/2009 8:06:24 AM #

Oes Tsetnoc

Comluv is a Blogging Network now...

Oes Tsetnoc United States

10/8/2009 8:20:16 PM #

Jesse @ Peter Pan costumes

I am interested in sharing this information with my readers. I'm glad I that I had a chance to read this.

Jesse From Peter Pan costumes United States

10/9/2009 4:30:00 AM #

sts

Interesting read, bookmarked for future referrence  http://www.i-bukmacher.pl">sts

sts Poland

10/21/2009 5:28:57 AM #

download hollywood movies

commentluv is a good job keep it up and thanks for sharing with us.

download hollywood movies United States

10/21/2009 3:03:39 PM #

hire seo expert

I always install the keyword luv plug-in directly on my blog. But i never used such code in my site.

hire seo expert United States

11/3/2009 2:03:10 PM #

mobile phone reviews

Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such information which I was searching for a long time.This made very glad Smile

mobile phone reviews United States

11/7/2009 7:47:50 AM #

Topsoil

I was wondering what is up with that weird gravatar??? I know 5am is early and I'm not looking my best at that hour, but I hope I don't look like this! I might however make that face if I'm asked to do 100 pushups. lol

Topsoil United States

12/5/2009 8:34:15 AM #

honda dealer nj

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.



Regards
Neel

honda dealer nj United States

12/5/2009 8:58:24 AM #

lexus dealer in westchester

I want to express my admiration of your writing skill and ability to make reader to read the while thing to the end

Regards
Dock


lexus dealer in westchester United States

12/6/2009 11:49:10 PM #

seoul girls

nice template and great article.thanks this is great information

seoul girls United States

12/12/2009 11:56:16 AM #

Darren@Call Center Services Outsourcing

KeywordLuv is one of the best things to ever come out of the internet.

Darren From Call Center Services Outsourcing Republic of the Philippines

1/12/2010 12:11:29 AM #

Clint Maher

I use Commentluv on all my blogs and have done so for the last couple of years. It’s a great way to encourage others to leave a comment, and at the same time they will get a link back to their site.

Clint Maher Australia

2/13/2010 5:10:08 PM #

Mishimoto Radiator

We also add comment luv to our blogs, encouraging other users to post on our blog.  Good stuff, and great plugin!

Mishimoto Radiator United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET

Code Research Center

©2009 CodeResearchCenter.com. All Rights Reserved

About Me

I'm a 30 year old browser based software developer who has just started to research the various ways to make money online. My current interests are software development, online marketing, social networking and blogging.

Disclaimer

These postings are provided "AS IS" with no warranties, use at your own risk

Page List

Poll

What blog platform do you use?



Show Results