The Mighty Blog

Dec28

Written by:Will
12/28/2008  RssIcon

The core DotNetNuke Blog Module has obviously grown by leaps and bounds. However, there are a few things that I have wanted to change about it.  One thing is the social bookmarking badges.

I should clarify the opening statement I made.  The social bookmarking mechanism works great and does exactly what most of us need for it to do.  However, there are a couple of small oversights in it.  This first and foremost problem with it is that the badges right now require that someone has file access to the server.  We will move beyond that for this blog entry.  I am sure that an interface is planned in the near future to accomplish this.

Social Bookmark Badges

Right now, we can easily edit the social bookmark badges that show up at the bottom of your blog.  Here is what mine used to look like.  Note that the icon furthest to the right is for DotNetKicks.

Blog Social Bookmarking Badge Toolbar

If you go into the ~/DesktopModules/Blog/ShareBadge/js/ShareBadgeChicklets.js file, you will be looking at a JavaScript that adds a number of different social bookmark badges to the bottom of your blog.  To remove any, simply "comment out" the respective lines of JavaScript that initialize said bookmarks badges.  For instance, here is an example of commenting out the Facebook badge.

//Facebook
/*
sb_chicklets[33][0] = strImagePath + "images/i_facebook.gif";
sb_chicklets[33][1] = "Facebook";
sb_chicklets[33][2] = "facebook";
sb_chicklets[33][3] = "http://www.facebook.com/sharer.php?u={url}&t={title}";
*/

You will notice that I didn't use the double slashes for the comments.  As a practice I never do.  This is because there are many white space filters and compression tools that choke on them, causing JavaScript errors.

Adding a new badge is quite simple.  Just copy the same format, and add another instance of a badge at the bottom of the same JavaScript file.  Either that, or you can just replace the existing code for a badge you do not want.  (Just the values, not the object names or indexes.)

The Problem

The problem I had with the existing implementation is that I could not add the DotNetKicks badge the way that DotNetKicks suggests.  I wanted the badge that shows the "kick" count.  This simply was not possible with the current JavaScript code.

DotNetKicks Badge

The Solution

The badges are actually injected in the shareBadge method in the ~/DesktopModules/Blog/ShareBadge/js/ShareBadgePro.js JavaScript file.  In that method, the URL specified in the previous JavaScript file is parsed for the blog title and url tokens.  The tokens are then replaced with the respective values.

Note that there is a whole lot more plumbing than this that make the badges happen. Modifications may need to be made elsewhere as well to accomplish certain tasks.

That doesn't sound bad right?  Wrong.  DotNetKicks uses an ASP.Net Handler class to return the image used in the badge that I want to use.  The handler expects to have the blog URL passed as a query string parameter.  If you look at the default code that parses the badge values, it only replaces the URL in the link, not the URL.

function shareBadge(e) {
    var chickletId = this.id.replace(/[^0-9]/g,'');
    var sb_targetToolbarTitle = document.getElementById(this.getAttribute("rel") + '_title');
    var sb_targetToolbarUrl = document.getElementById(this.getAttribute("rel") + '_url');
   
    var actionUrl = sb_chicklets[chickletId][3];
   
    actionUrl = actionUrl.replace('{url}', escape(sb_targetToolbarUrl.innerText));
    actionUrl = actionUrl.replace('{title}', escape(sb_targetToolbarTitle.innerText));
    window.open(actionUrl);
}

In effect, the preferred DotNetKicks badge will not work with the default code in place.  With a couple of minor changes in the shareBadge method in ShareBadgePro.js, we can now replace the same values in the image path.

function shareBadge(e) {
    var chickletId = this.id.replace(/[^0-9]/g,'');
    var sb_targetToolbarTitle = document.getElementById(this.getAttribute("rel") + '_title');
    var sb_targetToolbarUrl = document.getElementById(this.getAttribute("rel") + '_url');
   
    var actionUrl = sb_chicklets[chickletId][3];
   
    actionUrl = actionUrl.replace('{url}', escape(sb_targetToolbarUrl.innerText));
    actionUrl = actionUrl.replace('{title}', escape(sb_targetToolbarTitle.innerText));

    /* MODIFICATION by Will Strohl - 20081224 */
    /*
        Want to be able to handle when images are implemented using ASPNet handlers, like DotNetKicks
    */
    var actionImg = sb_chicklets[chickletId][0];
    if(actionImg.indexOf('{url}') >= 0 || actionImg.indexOf('{title}') >= 0){
        actionImg = actionImg.replace('{url}', escape(sb_targetToolbarUrl.innerText));
        actionImg = actionImg.replace('{title}', escape(sb_targetToolbarTitle.innerText));
    }
   
    window.open(actionUrl);
}

You will notice that I didn't replace the values right away.  I first parse to see if I need to replace the values.  This saves rendering time, as the strings are not then arbitrarily thrown through the replace method when they don't need to be. 

So, what did this just do for us?  Well, it enabled us to be able to apply the default DotNetKicks code into our badge assignment.  The original looks like this:

//DotNetKicks
sb_chicklets[32][0] = strImagePath + "images/i_dotnetkicks.gif";
sb_chicklets[32][1] = "DotNetKicks";
sb_chicklets[32][2] = "dotnetkicks";
sb_chicklets[32][3] = "http://www.dotnetkicks.com/submit/?url={url}&r=inspectorit&title={title}";

After we make the intended adjustments, the badge code looks like this:

//DotNetKicks
sb_chicklets[32][0] = "http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url={url}";
sb_chicklets[32][1] = "DotNetKicks";
sb_chicklets[32][2] = "dotnetkicks";
sb_chicklets[32][3] = "http://www.dotnetkicks.com/kick/?url={url}&r=Will+Strohl&title={title}";

Once the code is placed on the server, we will have the desired effect.  See my screen shot below.  You will see the DotNetKicks badge that we're used to.

Conclusion

I hope that this tutorial helps you gain the confidence needed to explore the wide world of the DNN Blog Module.

Technorati Tags: , , , , , ,

Copyright ©2008 Will Strohl

10 comment(s) so far...


Gravatar

Great stuff, Will! Thanks for posting this how-to.

By Don Worthley on   12/30/2008
Gravatar

My pleasure! Thanks for stopping by.

By Will on   12/30/2008
Gravatar

Brilliant, Just what I was looking for. Had a looked at the java file, but got a bit lost after a while. You cleared a few things up for me.

By Robert Braver on   4/3/2009
Gravatar

One thing I noticed is that there are a whole bunch of other badges in the js file. Up to 40. What determines which badge to show and which ones not to show. Any 1 have any ideas on that?

By Robert Bravery on   4/4/2009
Gravatar

Check out the ~/DesktopModules/Blog/js/bookmarks.xml file. This is what determines which bookmarks are rendered.

By Will on   4/4/2009
Gravatar

Thanks for heading me in the right direction, but when I commented out three of badges i the chicklets file but then the menu rendred three X graphics with 'undefined'; you have to edit the blog module's viewentry.vb file also if you are removing items:

'Display the Bookmarks Toolbar
If Not Page.ClientScript.IsStartupScriptRegistered("SB_PRO_TOOLBAR") Then
Dim SbToolbar As String = "" _
& "initializeShareBadge(""ShareBadgePRO_Toolbar"",""" & Replace(EntryTitle, """", "'") & """, """ & EntryUrl & """);" _
& "addBadgeItem(7);" _
& "addBadgeItem(33);" _
& "addBadgeItem(9);" _
& "addBadgeItem(14);" _
& "addBadgeItem(17);" _
& "addBadgeItem(20);" _
& "addBadgeItem(27);" _
& "addBadgeItem(28);" _
& "addBadgeItem(31);" _
& "addBadgeItem(32);" _
& ""

Page.ClientScript.RegisterStartupScript(Me.GetType(), "SB_PRO_TOOLBAR", SbToolbar)
End If

By Richard Golko on   7/24/2009
Gravatar

Nice catch! I missed that.

By Will on   7/24/2009
Gravatar

I noticed a couple things:
Your list above does not include Twitter.
At the bottom of this page I see another section with:
Post to technorati (which is also above) and Tweet it.

Why two sections?

By Phil Speth on   3/10/2010
Gravatar

@Phil: As simple as it is, that is an outstanding question! :)

The chicklets at the bottom of the blog posts was changed mostly as a proof of concept.

The site has undergone a complete redesign everywhere except in the Blog module. The chicklets that are below each post are part of the Blog module, while the top of the page uses a (referenced) Text/HTML module. There are ways to duplicate that content more uniformly, but it hasn't been done at this time.

The main reason you see the additional section on the top of each page is because not every page has the individual blog entry. All other blog pages do not include sharing capabilities - which is the same issue with the other tabs (pages) on the site. A "word of mouth" or "marketing" mantra for web design would tell you to make every page on your site sharable. While the implementation here is not perfect, this is the end goal I am attempting to achieve.

There are several changes that I want to make the pages on my blog tab specifically, but I am waiting for the next official blog module release first. It's not that far away. :)

By Will on   3/10/2010
Gravatar

Ok, I tried every method above and haven't been successful at implementing a Twitter icon next to the DotNetKicks. Can someone help me?

By arudd on   8/27/2010

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Add to Technorati Favorites
Tweet about my blog
Will Strohl - The Mighty Blog - RSS Feed

Tag Cloud

Sort by:Tag | SizeRSS
camp   community   dnn   dotnetnuke   dotnetnuke®   event   example   free   get   group   integer   jquery   meeting   module   new   odug   orlando   search   session   think  
The opinions expressed here are the personal opinions of Will Strohl and do not necessarily represent the views and opinions of the DotNetNuke Corporation.
© Copyright 2004-2010 by Will Strohl. All rights reserved.Website Skinned By: Ralph Williams  Website Hosted By: Applied Innovations