diff. btwn <Description> and <content:encoded>

Found a bug? Tell us!!
Post Reply
csloh
Regular
Posts: 8
Joined: Thu Feb 17, 2005 12:50 am

diff. btwn <Description> and <content:encoded>

Post by csloh » Thu Feb 17, 2005 5:33 pm

I have tried several RSS feeders, RSS 2.0 seemed to fail because there was no <description> section in my blog, because the mainBody of my blog has been placed under <content:encoded> in RSS 2.0. (RSS 1.0 does not do this, the mainBody is enclosed within <description>, no problem.)

I have traced the code to serendipity_rss_exchange.ics.php: (line 16-33:)

Code: Select all

    if ($item['content:encoded']) {
        if (!isset($entry['body']) || $bodyonly) {
            $data = &$entry['body'];
        } else {
            $data = &$entry['extended'];
        }

        // See if the 'description' element is a substring of the 'content:encoded' part. If it is,
        // we will only fetch the full 'content:encoded' part. If it's not a substring, we append
        // the 'content:encoded' part to either body or extended entry (respecting the 'bodyonly'
        // switch). We substract 4 letters because of possible '...' additions to an entry.
        $testbody = substr(trim(strip_tags($entry['body'])), 0, -4);
        if ($testbody != substr(trim(strip_tags($item['content:encoded'])), 0, strlen($testbody))) {
            $data .= utf8_decode($item['content:encoded']);
        } else {
            $data = utf8_decode($item['content:encoded']);
        }
    }


How do I swtich out the <content:encoded> back to <description>?
I don't read php very well, but I am intrigued by the similarity between the following lines:
$data .= utf8_decode($item['content:encoded']);
$data = utf8_decode($item['content:encoded']);
Could this be a problem?

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: difference btwn <Description> and <content:enco

Post by garvinhicking » Thu Feb 17, 2005 5:38 pm

I'm sorry but you traced it to the wrong file - the code there has nothing to do with the RSS code emitting.

The code you would need to modify is within serendipity_functions.inc.php, the function serendipity_printEntries_rss()

Code: Select all

                if ($version == '2.0') {
                    /*********** RSS 2.0 FEED EXTRAS *************/
                    foreach ($entry['categories'] AS $idx => $cat) {
                        ?><category><?php echo serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); ?></category><?php
                    }
?>
    <comments><?php echo $entryLink; ?>#comments</comments>
    <wfw:comment><?php echo $serendipity['baseURL']; ?>wfwcomment.php?cid=<?php echo $id; ?></wfw:comment>
<?php
                    if ($comments === false) {
?>
    <slash:comments><?php echo $entry['comments']; ?></slash:comments>
    <wfw:commentRss><?php echo $serendipity['baseURL']; ?>rss.php?version=<?php echo $version; ?>&amp;type=comments&amp;cid=<?php echo $id; ?></wfw:commentRss>
<?php
                    }
?>
    <author><?php echo serendipity_utf8_encode(htmlspecialchars($entry['email'])) . ' (' . serendipity_utf8_encode(htmlspecialchars($entry['username'])) . ')'; ?></author>
    <content:encoded>
<?php
                    echo serendipity_utf8_encode(htmlspecialchars($entry['body'].$ext));
?>
    </content:encoded>
    <pubDate><?php echo date('r', serendipity_serverOffsetHour($entry['timestamp'])); ?></pubDate>
    <guid isPermaLink="false"><?php echo $guid; ?></guid>
    <?php
      $entry['display_dat'] = '';
      serendipity_plugin_api::hook_event('frontend_display:rss-2.0:per_entry', $entry);
      echo $entry['display_dat'];
    ?>


Or something like that.

HOWEVER: You do not need to change this. Using content:encoded and no description is PERFECTLY VALID according to the specs. You need to tell the authors of your RSS Client to pay attention to the specs.

content:encoded is a drop-in alternative to the description field. Their only difference is the way of encoding information. You cannot simply exchange those two because of that, so what you're trying to do will not help, as you are not allowed to but encoded content within the description field.

Additionally, the description field does not support more than 255 characters, while content:encoded does.

The bottom line is, that the authors of the RSS reader should fix their reader. That would be something easy to accomplish. Much easier than you bending Serendipity into a way which is not better than the current one and hurting the specifications for all other RSS clients. :)

Regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

vincem
Regular
Posts: 59
Joined: Sat Mar 05, 2005 6:01 am
Contact:

Same <content:encoded issue>

Post by vincem » Fri Mar 17, 2006 8:02 am

Hello Garvin :-)

In reference to this very same issue, is there a variable attributed to an entry that would correspond to a "description" of it, in other words maybe just the few first lines, or is there a way to create one?

I'm having the same issue, the aggregator on the other end won't read the <content:encoded> tag and I'm wondering if, while I won't remove it to keep the full rss 2.0 functionality, I couldn't just add a <description> tag to would correspond to a short "preview of the entries...

Regards,
Vince

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Same <content:encoded issue>

Post by garvinhicking » Fri Mar 17, 2006 9:57 am

Hi vince!

Yes, the description variable is attached to it. But you cannot mix a "introduction" and the full body within one RSS element. Aggregators are told to only respect one of those field, so having both content:encoded AND description is not a wise thing.

The reason we use content:encoded is that by the spec, <description> is not allowed to contain HTML markup.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Post Reply