Fixing RSS with MT2.6

| techie stuff | | Comments (7) | TrackBacks (6)

Update: Phil Ringnalda posted a plugin that takes care of encoding CDATA tags (and some other stuff) to prevent accidental RSS feed breakage.

Update 2: Tim Appnel wrote 2 plugins to fix my issues too. The first one is mt-entrybodymore which allows you to use <MTEntryBodyMore> to display the full entry instead of using <MTEntryBody> and <MTEntryMore>. He also wrote mt-xmlencode-block which I'm using to wrap my comments feed.

I'd like to thank Phil, Ben and Tim for all of their help. My site feeds both validate as does my comments feed (I cleaned it up a little).

The first problem: There's a bug in MT2.6 (which should be fixed soon, but I can help you if you need to fix it ASAP) that causes encode_xml to be called before Sanitize. That means that all of your nicely encoded content gets a lot of tags removed from it, which makes a mess. There's an easy fix for this (see below).

Second problem: The next problem is because I have a full content RSS feed (and also a comment RSS feed). To generate the full content RSS feed, I have the following in my RSS file:

<description><$MTEntryBody encode_xml="1" resolve_urls="1"$><$MTEntryMore encode_xml="1" resolve_urls="1"$></description>

The problem is that I have 2 tags (MTEntryBody and MTEntryMore) that have encode_xml="1". Because of that, each section is wrapped with CDATA tags. This causes a problem with some newsreaders because they aren't expecting 2 CDATA tags within the description, so they'll only display the second CDATA in the reader. Unless you're using Radio and then you only get the headings. [See Brad's weblog for more info.]

To fix this, you have to put your own CDATA tags in and remove the encode_xml tags like this:

<description><![CDATA[<$MTEntryBody resolve_urls="1"$><$MTEntryMore resolve_urls="1"$>]]></description>

Fix #1 from Phil Ringnalda (taken from the MT forum):

"for a quick fix you need to edit {your MT directory}/lib/MT/Template/Context.pm, find sub post_process_handler, and move (this code is around line 240):

if ($local_args{'encode_xml'}) {
$str = encode_xml($str);
}

down below:

if (my $spec = $local_args{'sanitize'}) {
require MT::Sanitize;
if ($spec eq '1') {
$spec = $ctx->stash('blog')->sanitize_spec ||
MT::ConfigMgr->instance->GlobalSanitizeSpec;
}
$str = MT::Sanitize->sanitize($str, $spec);
}

so that sanitize runs first, and doesn't eat the opening CDATA tag that encode_xml sticks in."

7 Comments

kristine said:

Hmm, that's really weird. I'm sorry we didn't catch it BEFORE everybody got to download tongue
I wonder why Sanitize is being called where it would affect the EntryBody and EntryMore tags. Since its just for comments, that seems odd. Ahh, well, as long as it gets fixed, I should stop trying to stare at Perl code when I know almost nothing gorgeous (flips my hair like a girl who doesn't know a thing!!! )grin

Lisa said:

The EntryBody and EntryMore problem is that it creates a CDATA for each which makes newsreaders grumpy. Sanitize was the first problem only. kiss

Broken index RSS for your viewing pleasure. wink

One more thing you might want to add to your comment feed fixup, if not your main feed, just so people don't put ]]... oh, that would be cruel.

Lisa said:

All fixed up! Thanks, Phil.

Lisa said:

Testing... ]]>

kristine said:

Sorry, I was gonna email you after I got done adding those, but I went and took a nap first instead. laugh and I did take a book with me and actually got some reading done with my little conversation hearts for entertainment too . LOL, I'm silly!

Sherri said:

I followed your first tutorial to make my RSS feeds. I validated at that time.

Then I noticed I wasn't validating sometimes. I'm not sure what the pattern is for when I DO and DON'T validate, it just happens on SOME entries, while not for others.

So after researching, I find this page, and Phil's page, and after doing numerous things to my xml template, I'm still not validating.

Here's what I've done:
1. I changed my description code to this:
<description><![CDATA[]]></description>

2. When I still wouldn't validate, I uploaded Phil's SmartestXMLEncode.pm to my plugins directory (in ascii and CHMOD 755), then added this to the description code:
<description><![CDATA[]]></description>

3. When that wouldn't validate, I looked in my context.pm, and the sanitize code was already above the code:
if ($local_args{'encode_xml'}) {
$str = encode_xml($str);
}

Not sure what to try next. Thanks,
Sherri
Nothing in Particular | XML

6 TrackBacks

Listed below are links to blogs that reference this entry: Fixing RSS with MT2.6.

TrackBack URL for this entry: http://www.beantowngeek.com/cgi-bin/mt/mt-pong.cgi/144

» New Plugin: mt-entrybodymore. from tima thinking outloud.

A MovableType plugin that output both the entry body and "more" fields with one tag because you may find a need for it. Read More

» MT-EntryBodyMore from MT Plugin Directory

Lisa needed something like this for her full-text RSS feed. Read More

» RSS Feeds from The ArcterJournal

Note to self: set up nice RSS feeds.... Read More

» RSS Feeds from Thoughtprints

Thanks to Lisa, I now have a much better understanding of RSS feeds and what they're used for. And also... Read More

» RSS Feeds Done! from The ArcterJournal

Finally got around to doing what I promised ages ago. It was simple, just copy the .pl plugin that Unix-Gal... Read More

» RSS Feeds Done! from The ArcterJournal

Finally got around to doing what I promised ages ago. It was simple, just copy the .pl plugin that Unix-Gal... Read More

About this Entry

This page contains a single entry by Lisa published on February 15, 2003 5:40 PM.

MT 2.6, part 2 was the previous entry in this blog.

Good weekend is the next entry in this blog.

Find recent content on the main index.

Me!

Nobody can make you feel inferior without your permission.—Eleanor Roosevelt

About me... :: memes :: My Amazon wishlist :: My LJ :: My Twitter :: My Flickr :: Photos of me

Blog reading list

Contacts
· AIM, Yahoo!, MSN, Google Talk, LJ Talk... just ask
· Email me

Good Causes

       
Love is love.
Support gay marriage.

platinum.gif
East siiiiiiiiiiiiiiiiiiiide, baby!
Click to help
sponsor mammograms
Listen to good music! Radio Paradise

Silly Stuff

blogchalk:
Lisa/Female/41-45. Lives in United States/Mass/Boston and speaks
English. Spends 80% of daytime online. Uses a Faster (1M+) connection.
The
WeatherPixie
The weather in Boston

Flickr

www.flickr.com
jasra's photos More of jasra's photos
Powered by Movable Type 4.1

Copyright

Copyright © 2001-7 Lisa K Holsberg. Unauthorized use is prohibited.