Apr
4
Written by:
Andy Hock
4/4/2008 3:03 PM
We had been considering a move to another blog engine for our website, mainly because the DotNetNuke Blog module doesn't have some features we consider critical to a working blog--the most important of which are social links. I mean, what's the point of having a blog in a vacuum, right? The whole trackback thing is okay, but in the web 2.0 world, it's all about social links.
No matter what our decision is on a blog engine, we needed a fix, in the interim, to allow us to continue (er, actuall 'start again'--I've been remiss in updating my blog for almost a year. Shame on me!) blogging, I decided to add a 'KickIt' icon to the DotNetNuke Blog module.
It's easy to accomplish, even if you're not an expert programmer, but before you do anything specified below, make sure you backup all your files in the DesktopModules\Blog folder!
First of all, I discovered that DotNetKicks sure likes to hide where they discuss the 'adding a KickIt' icon. Finding the image, and instructions was non-trivial. After googling for a while, I discovered an article DotNetKicks KickIt Plugin For Windows Live Writer. It wasn't exactly what I wanted, but I decided to just examine the KickIt URL at the bottom of the article as shown:

If you right-click on the KickIt image, and select 'Properties' from the menu, you can examine the image location:

Aha. Now we're getting someplace. The URL used to generate the KickIt image, including the number of times the article has been kicked, is as follows (see the Image Properties: Location):
http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www....
Where the 'http://www...' references the URL of the article page. Now we can formulate a plan to implement adding the KickIt icon to DotNetNuke Blog entries:
- Find the .ascx control that displays a specific blog entry.
- Look at the .ascx page which displays a specific entry and find where we would want to add the KickIt icon.
- Examine the code in the blog code-behind for this page (and others, if necessary), and discover an already exposed function which allows us to retrieve the current page URL.
- Add the KickIt icon URL programmatically to the .ascx file.
Step 1 requires finding the ascx control that displays a blog entry. With decent naming conventions, we shouldn't find this too difficult, and it is so. If we navigate to the DesktopModules folder, find the Blog directory, we see an ascx file called ViewEntry.ascx. Sounds reasonable. So, where do we want to add the URL? If we look at a Blog Entry page, it looks like this:

It might not be the best place for you, but it seems there is room next to the 'Print' icon to display our KickIt icon. If we examine the ViewEntry.ascx page:
Specifically, we find, in lines (if you are using the latest version of Blog) 37-40:
So what we want to do is add our ashx link below the 'cmdPrint' URL. Now we need to check out the code-behind, to find out how to retrieve the full url (remember, in DotNetNuke, Friendly URLs can be on or off, so we can't just use the Page Request info--we need to find the DotNetNuke manner of building an URL).
In the ViewEntry.ascx.vb file there is a Blog.Business.Utility library which is imported;
Imports System
Imports DotNetNuke.Modules.Blog.Business
Imports DotNetNuke.Security
Imports DotNetNuke.UI.WebControls
Imports DotNetNuke
This Common library contains a method which will do what we want. Specifically:
Public Shared Function AddTOQueryString(ByVal URL As String, ByVal Key As String, ByVal Value As String) As String
Dim RegExp As New System.Text.RegularExpressions.Regex(Key & "=.*?(&|$)")
Dim Match As System.Text.RegularExpressions.Match = RegExp.Match(URL)
If Match.Success Then
Return RegExp.Replace(URL, Key & "=" & Value & Match.Groups(1).ToString)
ElseIf URL.IndexOf("?") > 0 Then
Return URL & "&" & Key & "=" & Value
Else
Return URL & "?" & Key & "=" & Value
End If
End Function
Before we add the URL, we have to build it. The KickIt URL expects the page URL. The AddToQueryString function expects a base URL, a keyword, and a raw URL. To get the page URL, we use the 'NavigateURL() function in DotNetNuke.
To create a DotNetNuke Friendly URL, we need to know the Blog EntryID, so we pass in the keyword, 'EntryID'. Finally, to create a raw URL, we retrieve the cached EntryID URL from the Request object, using Request.QueryString('EntryID').ToString(). Adding the 'ToString() is important, since we need to ensure we have a String, and not an Object.
To finally add the KickIt url, we add the following line of code after the 'cmdPrint' line in the ViewEntry.ascx file:
Unfortunately, there may be some escape characters in the line above. For this reason, we've zipped the ViewEntry.ascx file and you can download the file, including the changes for implementing the KickIt icon
here (Scroll to the bottom of the page). Hope this helps all those who are using the DotNetNuke Blog module to add a KickIt icon to their blog. You can use the exact same logic to add a DiggIt, or any other social link icon to your blog. If you accomplish this, please post your solution in the comments below.
Tags: