The tags and tag cloud you see on this blog are from the iFinity Tagger module. This module works by running a Page Tag cloud module on the same page as the blog module, and when I post a blog entry, I manually add the tags to the Tagger module. The Tagger module knows that each blog entry is indexed by the Url value of 'EntryId', so it stores the relevant tags against that module id/page id/entry id combination. This module has been out for about 12 months so far, and people use it to tag Blog entries, product catalogs and plain old DotNetNuke pages. So far so good.
Occasionally, I get requests to integrate the Tagger module into other pieces of software, so I point the person in the direction of the Tagger API and IntermoduleCommunication (IMC) interface. If you didn't know, the IMC interface is a programming device in DNN that allows you to pass information between two modules on the same page.
One of the more common requests is to integrate the Tagger module directly into the DNN Blog module. Now I don't distribute modified versions of the Core code, because it would be too hard to keep up, but I'm happy to point people in the right direction.
Modify the DotNetNuke Blog Module to Tag Blog Entries
One of those intrepid custom coders was Randy Hall, who was kind enough to share with me (and allow me to share with the internet) the code for integrating the Tagger module directly into the Blog module, so that you can enter tags at the same time as creating the blog entry. You can't use IMC in this case because the Blog module goes into 'edit' mode to create a new entry, and when in edit mode there is only one module shown on the page.
The solution Randy and I worked out was to call the Tagger API directly, instead of going through the IMC interface. Here's his solution in code, for anyone who want's to crack open their blog code and integrate tagging directly into Blog entry screen.
Step 0 : Download the blog module source code (it's in the resources file) and get it open in Visual Studio. Add a reference to your blog project for the iFinity.Tagger.DLL. You'll find this in your \bin directory after you've installed the module.
Step 1 : Edit the EditEntry.ascx file to add the Page Tag Cloud controls.
The new controls have been highlighted in red. You can copy the relevant controls from the ModuleTagsEdit.ascx file installed in your desktopModules\iFinity.Tagger directory. Randy has added in a checkbox to copy the blog's title into the tag header.
Step 2 : Hook up the Tagger Save to the Blog Update
Private Function SaveTags() AsBoolean
Dim b As Boolean = False
If txtTagCloudHeader.Text.Trim.Length > 0 Then
Try
Dim header As String = String.Empty
Dim line1 As String = String.Empty
Dim line2 As String = String.Empty
Dim tc As New TaggerController
Dim tags As String() = tc.ParseTags(txtTagList.Text)
tags = tc.CleanTags(tags)
header = txtTagCloudHeader.Text
line1 = txtTagCloudLine1.Text
line2 = txtTagCloudLine2.Text
Dim options As New TaggerModuleOptions( _
tags, _
Me.PortalId, _
True, _
EntryIDCol, _
TagSummaryDataAction.ForceOverwrite, _
header, _
line1, _
line2)
options.ReplaceTags = True
Dim args As New TaggerModuleCommunicationEventArgs(options, Me.GetType.ToString, TagTarget.ModuleTags)
b = APIController.ProcessCommunicationEvent(args, TaggerModuleID, GetType(iFinity.DNN.Modules.Tagger.ViewModuleTags))
Catch ex As Exception
b = False
End Try
End If
Return b
End Function
You'll need to hook this code up to the 'update' linkbutton event code in the EditEvent.ascx.vb file, so that it is fired after the blog entry is saved. What this code does is construct an 'options' value, which is then passed directly into the Tagger Module APIController class. Note the options being used here are 'force overwrite', which means all of the tags are replaced each time. You could also change the value to send in for the 'header', 'line1' and 'line2' variables. These values are used to show on the list of tags that match when you click on a tag in the Tag Cloud.
Step 3 : Populate the Tags into the TagList control when the Entry Control is loaded.
Private Sub FetchTags(ByVal EntryID As Integer)
Dim nv As Specialized.NameValueCollection = EntryIDCol
Dim TagModID As Integer = TaggerModuleID
'Get tags:
Dim oTags As New iFinity.DNN.Modules.Tagger.TaggerController
Dim sa As String() = oTags.GetTags(PortalId, TagModID, True, nv)
txtTagList.Text = String.Join(",", sa)
Dim sql As New DotNetNuke.Modules.Blog.Business.EntryController
Dim EntryInfo As EntryInfo
EntryInfo = sql.GetTagInstanceLink(PortalId, TagModID, nv.Keys(0).ToString & "/" & nv.Item(0).ToString, "/", ";")
If Not IsNothing(EntryInfo) Then
txtTagCloudHeader.Text = EntryInfo.Header
txtTagCloudLine1.Text = EntryInfo.Line1
txtTagCloudLine2.Text = EntryInfo.Line2
End If
End Sub
Private ReadOnly Property TaggerModuleID() As Integer
Get
Dim _Modules As New ModuleController
Dim _ModuleInfo As ModuleInfo = _Modules.GetModuleByDefinition(PortalId, "Page Tag Cloud")
Return _ModuleInfo.TabModuleID
End Get
End Property
Private ReadOnly Property EntryIDCol() As Specialized.NameValueCollection
Get
Dim nv As New Specialized.NameValueCollection
Dim result As Integer = 0
If Array.IndexOf(nv.AllKeys, "EntryID") <= 0 Then
If EntryID = 0 AndAlso Integer.TryParse(Request.QueryString.Item("EntryID").ToString, result) Then
EntryID = result
End If
End If
nv.Add("EntryID", EntryID.ToString)
Return nv
End Get
End Property
This piece of code retrieves the current list of tags from the tag list for this module/blog entry, and puts them into the Tag Text box. This means the tags can be edited, removed or left as-is next when the blog entry is saved. Accordingly, you need to hook up the 'FetchTags' call to the page_load event of the EditControl, or somewhere similar. You should probably only run the FetchTags call on Get requests ; in otherwords, don't run it on postback.
Step 4 : Compile and run!
Try it out, and see if it is working OK. You can also check that your tags are being entered correctly by running the 'ifty_GetTagsForPortal' stored procedure. This will return all tags for your chosen portal, and you can see if your new tags are in the list.
Wrapping Up
Of course, you'll need to compile your new Blog module DLL and copy up your modified EditEntry.ascx control file to the server. This will ensure that all of your new code runs when you run your blog module.
Getting the Tagger Module
If you haven't already done so, you can download a fully-functional trial of the Tagger module from the
Tagger Product Page. This runs with all features on your development machine. You can also request a free 10 day trial licence to remove the licensing messages that you get when running in 'Demo' mode.
Did you try it?
If you've managed to get this working on your site, please let me know via the comments, and feel free to link to your tagged blog page.