Format and Sort your DNN Events RSS feed results with the DNN NewsFeed module

Location: BlogsAll BlogsDNN Tips    
Posted by: mamlin 9/4/2008 11:45 AM

(Updated 1-29-2009) If you like to stick to using the core DotNetNuke modules as much as possible (hey, they're free!) and you use or have thought about using the DNN NewsFeed module, you'll likely appreciate this post.  Specifically, we're going to look at using the NewsFeed module to list calendar entries from the DNN Events module.  By default, the results of mating these two modules is not impressive, so we're going to tweak and improve upon the original using nothing but Notepad and without changing any core DNN code...


DNN NewsFeed Module
NOTE:  The latest available NewsFeed version (4.00.00) has many added features but also introduces several issues, some critical.  This article deals with DNN NewsFeed module version 3.01.01.
The NewsFeed module performs one simple, basic function:  retrieve XML data from a specified newsfeed, process those results using XSLT and display the results.  There are no frills such as user-driven options for sorting, searching or filtering the results.  While this might be considered a deal-breaker by many, there is one redeeming feature:  the ability to upload your own XSL transformation definition file.  More on that in a bit.


DNN Events Module
This is DNN's "calendar" module.  Besides displaying a calendar, the module provides the ability to set up "events" on particular dates.  Users can "register" for events, get notifications, etc.  Admins can set registration limits, charge registration fees (payable via PayPal) and more.  All in all it's a nifty module that the DNN core team was fortunate enough to inherit from Alan Vance (today's core Events module was formerly Alan's "AVCalendar" module).

All that aside, we are simply using the Events module as our RSS feed data source.  When it comes to the Events module, DNN's generic "Syndicate" RSS feature is quite limited in what it provides, resulting in a few issues for the RSS end-user.  The aim of this posting is to identify and overcome some of those issues using nothing but Notepad.


RSS Your Event Info and Share with the World
Every DNN module has a generic option to provide that module's contents as an RSS feed.  This option is the "Allow Syndication" option found under the module's SETTINGS -> PAGE SETTINGS section.  Turning on this option enables DNN Search to provide an XML version of the module's contents (as you might imagine, this generic feature produces mixed results based on the type and implementation of module).  A module with "Syndication" turned on will display the little RSS icon:  .  Clicking on this icon will bring up a new window with the contents of that feed.  (You'll need to click the icon in order to discover the URL for that feed.)  Once you've enabled the "Syndication" feature, your module's info is ready to be shared with the world via RSS.


Setting Things Up
For this post's examples, go ahead and drop an EVENTS module onto a test page.  Click the "Add Event" option and set up an event for December 25, 2015 (hey, we're planning way ahead).  Add a description for that event in the "Notes" section.  This is a happy event so be sure to bold a few words or add a little color to your fonts.  Click "Update" to save the event.

Next, set up a second event, this time for January 1, 2020.  Add some notes for this one, too, then save it.  Now we have some Events content to feed to our RSS news reader (DNN module "NewsFeed").  Click the RSS icon  at the bottom-right of your events calendar.  This will bring up a new window showing our two events -- cool!  Find the URL for your feed and copy it for the next step.

Now, drop a NEWSFEED module on a test page (it can be on the same page as the EVENTS module if you like).  Go into the NEWSFEED module's "Edit Newsfeed" option.  There are only three options to set:  (1) the news feed source URL, (2) an optional style sheet file and (3) optional login settings for use with secure RSS feeds.  

Go ahead and set the news feed source URL to the URL of your news feed.  Click UPDATE to save your settings.  You should now see your two events listed in your NewsFeed module.  Sweet!  That was almost too easy.  Of course, nothing really worth having is ever easy...


Issue #1:  HTML tags in my results!
If all worked as intended you should see both events listed in the NewsFeed module.  You should also see the notes you typed under each event.  If you followed directions and added some bold and color to your fonts, your newsfeed should display plaintext with HTML tags instead of the actual HTML.  Well, that bites:  we want our notes to appear the way we entered them, not as source HTML code.

This problem is a result of the module's default "style sheet" (actually an XSL transformation file rather than a CSS style sheet).  To fix this problem (and others), we need to create our own XSL file and use that, instead.  To make things easy, we'll start with the existing file the NewsFeed module uses.  It is named "RSS91.xsl" and it is found in the "DesktopModules/News" directory.  To make things easy, here's a link to a copy of the file:  RSS91.xsl

You can edit the file using NotePad (or your favorite text editor).  Open it up, find line 14 and replace the following:

   < xsl:value-of select="description"/ >

with this:

   < xsl:value-of disable-output-escaping="yes" select="description"/ >

Save the file.  Now go into the NewsFeed module's "Edit NewsFeed" option and find the "News Feed Style Sheet" settings.  Select "Upload New File" then browse for and upload your edited version of "RSS91.xsl".  Don't worry about overwriting the original -- you cannot upload into the "DesktopModules" directory so there's no chance of overwriting the original file.

Now your NewsFeed will display the intended HTML output of your events' notes rather than the HTML source code.


Issue #2:  Events are listed in the wrong order.
A second major issue you may have noticed is that the events are listed in the reverse order that you added them.  That is, the actual date of the event is totally ignored.  This is no big deal for our list of two events but it could be a deal-breaker when listing many events.  We want our events to be listed in order by date!

Unfortunately, the DNN syndicate feature does not provide a RSS tag with just the date.  Sure, the date is there, but it is provided at the end of the TITLE tag.  The TITLE tag is a single string of text resulting from the concatenation of the Event module title, the event name, the event date and the event start time.  Sorting by this string won't do because we'd end up sorting by event title rather than by date.

To fix this, we go back to our new best friend: the XSL file.  There are a host of functions we can use in our XSL.  These are part of something called "XPATH".  A full discussion is beyond the scope of this posting, but you can see a list of XPATH functions here:  http://www.w3schools.com/xpath/xpath_functions.asp

Ok, go back to your edited file "RSS91.xsl".  Find line 8.  It should be:

   < xsl:for-each select="channel/item" >

Immediately after this line, insert the following very long line:

    < xsl:sort order="descending" select="(1000 * number(substring-after(substring-after(substring-before(substring-after( title,', '),' '),'/'),'/'))) + (100 * number(substring-before(substring-before(substring-after( title,', '),' '),'/'))) + number(substring-before(substring-after(substring-before(substring-after( title,', '),' '),'/'),'/'))"/ >

Save the file and upload it as before.

(The above code and following highlighted portion added on 1-29-2009)
What the heck is that loooong line of code?

The lengthy line of XSL code does three things:  First, it employs the XPATH functions "substring-after" and "substring-before" to cut the TITLE string down to just the date portion.  Second, it further breaks the date into YEAR, MONTH and DAY and converts the strings into integer values using the "number" function.  Third, it applies the formula (YEAR*1000 + MONTH*100 + DAY) to get a simple, easily sortable numerical representation of the date.  This value is sorted via the XSL:SORT tag resulting in our EVENT entries being sorted in order by date.
 
Why not just use XSL's "format:dateTime" function?
Because "format:dateTime" is an XSLT version 2.0 function.  Though 2.0 has been standardized for years, we're STILL waiting for everyone to catch up!  The "substring / integer value" method I included, though cumbersome, works for everyone ... that is, as long as you only want to sort rather than display reformatted dates...



This example along with the list of XPATH functions should enable you to manipulate the basic EVENTS feed data to meet your needs.  Mixing in additional HTML in your XSL file can result in some pretty nice events listings.  For instance:  you could create a second version of the XSL file specifically tailored to display a mini-version of events in a sidebar (hey, that sounds lie a good topic for a future blog post).


Future Improvements to EVENTS
At the time of this posting, the DNN Events module is at version 4.0.2.  Details have already been released regarding the next version, 4.1.0, and part of the upcoming enhancements include an Events-module-specific RSS feed generator.  That generator will provide additional options for controlling what event information gets into the feed.  If you like the idea of feeding Events info via RSS, you'll certainly want to watch for the release of Events 4.1.0. 
 
 
What Next with RSS?
In a future post we'll look at using DNN's "XML" module to revamp our EVENTS feed.  More specifically, we're going to use the "XML" module to highjack our own EVENTS module RSS feed, reformat its contents to our liking, add some new content and then publish the results as a brand new RSS feed.  Stay tuned!

Permalink |  Trackback

Comments (3)   Add Comment
Re: Format and Sort your DNN Events RSS feed results with the DNN NewsFeed module    By BarryZ on 11/9/2008 10:16 PM
I need the DNN Events module to also sort by State, County, City. Is that possible?

Re: Format and Sort your DNN Events RSS feed results with the DNN NewsFeed module    By mamlin on 11/9/2008 10:35 PM
Hi, BarryZ. Do you need a sortable event list BY ANY MEANS (i.e., using the EVENTS module PLUS other means) or do you need the EVENTS module itself to provide such a list? It IS possible (via "any means") to provide a multi-field sortable list of events from the EVENTS module by using a free third-party data query module as long as you can write the needed SQL query (it's pretty easy for what you've mentioned). As far as using ONLY the Events module itself, you're currently limited to using the module's "list" view -- the module has an "event calendar" view and an "event list" view. Unfortunately the "list" view is not very configurable. I think your case would probably make a great blog entry -- give me a little more detail of exactly what you're after and I'll see about posting the solution as a new blog post.

Re: Sort EVENTS by city, county, state    By mamlin on 11/10/2008 1:54 PM
BarryZ: I posted a new blog outlining one way to display EVENT module event name, time, city, county and state info in a sortable-table using the free SQL module "SQLView" from DNNStuff: http://eguanasolutions.com/Blog/tabid/54/EntryID/15/Default.aspx


Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
You are here:  
 
>> Back to the top of the blog list...

 
        account   advanced   blog   click   cloud   code   content   create   data   different   events   example   feature   file   files   free   function   good   google   just   line   list   module   modules   need   option   page   pages   query   results   role   roles   script   search   select   settings   simple   site   skin   solution   step   tags   terms   time   user   users   value   version   want  
Minimize Google AJAX Search
 
Search ES:  
This is an example of a Google AJAX Search with asynchronous search execution for two searches.  See our blog series, 'Add Google AJAX Search to your DNN skin' for info and sample code.
 
     
Minimize Get the T-Shirt
 
Shirts by Eguana Solutions
(Be cool like us!)
 
     
Minimize Most-Commented Blogs
 
 
     

Minimize Looking for more info?
 

There are tons of helpful
posts from Eguana Solutions 
on the DotNetNuke.com forums.
  
 
Click HERE to see our posts.

 
     
Minimize Modules for Sale
 

Looking for Eguana's modules? 
We're still working on them!
  

Until ours are ready to dazzle and
amaze, you'll have to make do with
the thousands of modules already
available on SnowCovered.

 
     
Minimize Favorite Modules
 

There are many great DNN modules.
A few we highly recommend are:
 
Dynamic Registration
Total control over the user signup process.  Create custom forms, execute your own SQL, use the integrated payment processing features to assign user roles, validate USERNAMEs via AJAX and much more.  Very cool.
 
URL Master
Change to friendly URLs that really ARE friendly.  Add keywords into your page URLs for better SEO.  Create 301 redirects for individual pages.  Force visitors (and search bots) to a single domain (i.e., make everyone use the "www" version of your site's URL or vice versa).  One of the single best upgrades for any DNN site.
 
Document Exchange 5 (DMX5)
Drag-and-drop from Windows Explorer directly into the DMX file manager!  File versioning, file and folder moderation, extend user permissions down to the file level (for user groups and even for individual users).  Infinite file and file info presentation options via custom display templates.  Store files locally or remotely via UNC (i.e., can securely store files somewhere besides your web server).  Much more.
 
XMOD by DNNDev
Rock-solid form module for data collection.  From simple feedback / email forms to complex, multi-part tabbed forms.  XMOD is different from other form modules because XMOD does not create a new database table for every new form definition -- an important feature if you plan to create dozens or hundreds of forms over the life of your DNN instance!  Excellent support from the developer and an active community around this module.
 
If you desire your form module to create a new DB table for each new form definition, a great alternative to XMOD is the Dynamic Forms module from DataSprings.  Dynamic Forms offers direct DB access beyond that found in XMOD as well as an easy drag-and-drop form builder option to help you get up and running very quickly.

 
     

Login