Thursday, October 15, 2009

DIY Dilbert RSS Reader for SharePoint 2007


 

Everyone seems to be jumping on the "Here's my custom web part to do this…" band-wagon, so here's my "Here's how to do it out of the box…"

Everyone loves Dilbert, and Scott Adams has been on the money for so long, it's a wonder he isn't a gazillionaire…

Various people have posted ways to get around the fact that the out-of-the-box RSS Reader in WSS 3.0/MOSS2007 doesn't display the images from the Dilbert.com
RSS feeds, unless you expand the item. Their primary solutions are based around new web parts, or worse. But why bother? Most of them aren't packaged up properly, so require a skilled and privileged user to set them up.

Here's my solution, all it requires is the ability to add the built-in RSS Reader to a page and that SharePoint can already access, external to your organisation, RSS feeds (usually requires some proxy details in the web.config).

Steps:

  1. Create a new blank web part page or edit an existing one (e.g. the default page on your MySite).
  2. Add a Web Part to the appropriate zone (preferably a wide zone)
  3. Tick the RSS Viewer Web Part, click Add.
  4. On the newly inserted Web Part, click edit | Modify Shared Web Part (or click Open the Tool Pane)
  5. Type the feed URL (e.g. http://feeds2.feedburner.com/DilbertDailyStrip )
  6. Limit the feed to how ever many strips you want to display at once (e.g. 1)
  7. Click the XSL Editor button
  8. Copy and paste the XSL into something useful (at worst, there's always notepad)
  9. Search for: toggleitemdescription
  10. And replace:

    <div class="item link-item" >
    <a href="{concat(&quot;javascript:ToggleItemDescription('&quot;,$CurrentElement,&quot;')&quot;)}" >
    <xsl:value-of select="rss1:title"/>
    </a>
    <xsl:if test="$rss_ExpandFeed = true()">
    <xsl:call-template name="RSSMainTemplate.description">
    <xsl:with-param name="DescriptionStyle" select="string('display:block;')"/>
    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
    </xsl:call-template>
    </xsl:if>
    <xsl:if test="$rss_ExpandFeed = false()">
    <xsl:call-template name="RSSMainTemplate.description">
    <xsl:with-param name="DescriptionStyle" select="string('display:none;')"/>
    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
    </xsl:call-template>
    </xsl:if>
    </div>

    With:

    <div class="item link-item" >
    <xsl:call-template name="RSSMainTemplate.description">
    <xsl:with-param name="DescriptionStyle" select="string('display:block;')"/>
    <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
    </xsl:call-template>
    </div>

  11. At this point, you could also do the same for the RDF and ATOM sections (keep searching for toggleitemdescription), just for the sake of completeness.
  12. Copy and paste the XSL code from your editor, back into the XSL Editor (in SharePoint)
  13. Click Save
  14. You can now make any other changes to the Web Part (say restricting the chrome) and click OK
  15. Check-in/publish/Exit Edit Mode and you're done

All this does is stops the Web Part from collapsing the RSS items, which in Dilbert's case, means you get to see the images. The down side, is that it still ends up displaying the date to the left of the image. So not clean, but it works and it's out-of-the-box.

You could dig around in the XSL a bit more and probably find a way to get rid of the date.

If you want to use this over and over again, just export the web part, and import it again, giving it a unique name and next time just use your new one. No special privileges required (at least not on your MySite) and no DLLs, no config editing, just nice and easy.

I really should look into how XKCD.com does their feeds, as the RSS Viewer web part has no problems at all with displaying the images.