Page 1 of 1

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

Posted: Thu Feb 17, 2005 5:33 pm
by csloh
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?

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

Posted: Thu Feb 17, 2005 5:38 pm
by garvinhicking
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; ?>&type=comments&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.

Same <content:encoded issue>

Posted: Fri Mar 17, 2006 8:02 am
by vincem
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

Re: Same <content:encoded issue>

Posted: Fri Mar 17, 2006 9:57 am
by garvinhicking
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