DotNetKicks button extension for Blogengine.NET

I was looking around for some method of easily adding an DotNetKicks button to my posts but couldn't find anything anywhere. What did I do? Good developer that I am I downloaded the Blogengine.NET source and whipped up a quick extension! I only browsed around for as long as it took for me to find what I needed but I must say that the code was really well organised and readable, there is a post on the project's wiki about creating extensions and it really was a breeze.

My extension checks the post's content for an occurance of the token "[ dotnetkicks ]" (without the spaces!) when it is saved or updated and replaces it with the friendly green button. The code really just boils down to the following:

post.Content = post.Content.Replace(dotnetkicksToken, kickItButton);

There is one class in the attached zip, DotNetKicks.cs, this needs only be uploaded to your ~/App_Code/Extensions folder and everything magically works.

Update 

In response to a comment asking about generating the correct HTML for a button when the article is not yet on DotNetKicks, here is the code to do just that! DotNetKicks works in such a way that if a button is created using a URL which it doesn't know, the "kick it" button will show 0. When the button is clicked for the first time you will be taken to the DotNetKicks submission form and just have to fill in the title and description. When you hit submit and them come back to your post, "kick it 1"! Pretty smooth..

String kickItButton = String.Format(

    @"<a href=""http://www.dotnetkicks.com/kick/?url={0}"">

        <img src=""http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url={0}""

            border=""0"" alt=""kick it on DotNetKicks.com"" />

      </a>", post.AbsoluteLink);

Update 2

Changed the code as per Chris Blankenship's comment to include the title, saves you filling it in yourself...

DotNetKicks.zip (681.00 bytes)

kick it on DotNetKicks.com    <--- Look, it works...

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList
December 18, 2007 20:52 by Sean
E-mail | Permalink | Comments (9) | Comment RSSRSS comment feed

Related posts

Comments

December 18. 2007 23:18

Trackback from DotNetKicks.com

DotNetKicks button extension for Blogengine.NET

DotNetKicks.com

December 19. 2007 14:49

I'm thinking that this assumes that you have already submitted your article to the DotNetKicks website because I'm not sure how you would go about getting the correct HTML needed to display the counter for the KicksButton. Am I correct?

I did something similar with a Windows Live Writer Plugin; but I haven't blogged about this yet though. Anyway, looging forwared to your response.

Tyrone

December 19. 2007 15:05

Hi Tyrone,

Actually it doesn't assume the article has been submitted, when the post is first created and the token is placed at the bottom it shows with 0 kicks. Clicking the "kick it 0" will take you to the DotNetKicks submission form and fill in the URL to the post, you just add the title and description.

I'll update the post with the code for generating the correct HTML. Hope this helps!

Sean

December 20. 2007 15:22

Sean,

Thanks for explaining how the image generatation works. I will use this information to complete my Windows Live Writer Plugin for this KickIt button.

Tyrone

Tyrone

January 2. 2008 10:02

Great Extension! Would be really cool if you could extend it to include Digg, Stumbleupon, facebook and so on. To get a good idea of what I mean can be viewed here: gallery.live.com/liveItemDetail.aspx

Menno

January 3. 2008 14:43

Hi Menno,

Looks good, that'll definitely be something I'll look at in the future.

Sean

February 2. 2008 03:19

One thing I noticed is that your anchor doesn't specify a target="_blank". I tend to put that on every link in my site to keep people from navigating away from my site... I have updated your version on my site but wanted to recommend you update the source code to reflect the setting.

Just a recommendation.

Chris

February 2. 2008 03:42

I also noticed that you didn't include the title field... so an updated kickItButton value would look like the following:


String kickItButton = String.Format(
@"<a target=""_blank"" href=""http://www.dotnetkicks.com/kick/?url={0}&amp;title={1}"">
<img src=""www.dotnetkicks.com/.../KickItImageGenerator.ashx{0}"" border=""0"" alt=""kick it on DotNetKicks.com"" /></a>", post.AbsoluteLink, post.Title);

Chris

February 2. 2008 11:04

Hi Chris,

Thanks for the tips, I'll update the code later today hopefully. Your target="_blank" attribute got me thinking though, will blog about my opinions shortly!

Thanks again.

Sean

Comments are closed