making rss validate with html payload.
-
could the wp-rss.php, wp-rss2.php and wp-atom.php scripts be changed to the payload sections are contained in CDATA tags by default?
if my summary includes html (which every post does) the rss feed wont validate unless I add CDATA tags to the scripts.
wp-rss.php<?php
if (!isset($feed) || !$feed) {
$blog = 1;
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
$more = 1;
?>
<?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?>
<!-- generator="wordpress/<?php echo $wp_version ?>" -->
<rss version="0.92">
<channel>
<title><![CDATA[<?php bloginfo_rss('name') ?>]]></title>
<link><?php bloginfo_rss('url') ?></link>
<description><![CDATA[<?php bloginfo_rss('description') ?>]]></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), 0); ?></lastBuildDate>
<docs>http://backend.userland.com/rss092</docs>
<?php $items_count = 0; if ($posts) { foreach ($posts as $post) { start_wp(); ?>
<item>
<title><![CDATA[<?php the_title_rss() ?>]]></title>
<?php
if (get_settings('rss_use_excerpt')) {
?>
<description><![CDATA[<?php the_excerpt_rss(get_settings('rss_excerpt_length'), 2) ?>]]></description>
<?php
} else { // use content
?>
<description><![CDATA[<?php the_content_rss('', 0, '', get_settings('rss_excerpt_length')) ?>]]></description>
<?php
} // end else use content
?>
<link><?php permalink_single_rss() ?></link>
</item>
<?php $items_count++; if (($items_count == get_settings('posts_per_rss')) && empty($m)) { break; } } } ?>
</channel>
</rss>wp-rss2.php
<?php
if (!isset($feed) || !$feed) {
$blog = 1;
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
$more = 1;
?>
<?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?>
<!-- generator="wordpress/<?php echo $wp_version ?>" -->
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
>
<channel>
<title><![CDATA[<?php bloginfo_rss('name') ?>]]></title>
<link><?php bloginfo_rss('url') ?></link>
<description><![CDATA[<?php bloginfo_rss("description") ?>]]></description>
<copyright>Copyright <?php echo mysql2date('Y', get_lastpostdate()); ?></copyright>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), 0); ?></pubDate>
<generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator>
<?php $items_count = 0; if ($posts) { foreach ($posts as $post) { start_wp(); ?>
<item>
<title><![CDATA[<?php the_title_rss() ?>]]></title>
<link><?php permalink_single_rss() ?></link>
<comments><?php comments_link(); ?></comments>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', $post->post_date_gmt, 0); ?></pubDate>
<?php the_category_rss() ?>
<guid><?php the_permalink($id); ?></guid>
<?php if (get_settings('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss('', 2) ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss(get_settings('rss_excerpt_length'), 2) ?>]]></description>
<content:encoded><![CDATA[<?php the_content('', 0, '') ?>]]></content:encoded>
<?php endif; ?>
<wfw:commentRSS><?php echo comments_rss(); ?></wfw:commentRSS>
</item>
<?php $items_count++; if (($items_count == get_settings('posts_per_rss')) && empty($m)) { break; } } } ?>
</channel>
</rss>wp-atom.php
<?php
if (!isset($feed) || !$feed) {
$blog = 1;
$doing_rss = 1;
require('wp-blog-header.php');
}
header('Content-type: application/atom+xml; charset=' . get_settings('blog_charset'), true);
$more = 1;
?>
<?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?>
<feed version="0.3"
xmlns="http://purl.org/atom/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<title><![CDATA[<?php bloginfo_rss('name') ?>]]></title>
<link rel="alternate" type="text/html" href="<?php bloginfo_rss('url') ?>" />
<tagline><![CDATA[<?php bloginfo_rss("description") ?>]]></tagline>
<modified><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></modified>
<copyright>Copyright <?php echo mysql2date('Y', get_lastpostdate('blog')); ?></copyright>
<generator url="http://wordpress.org/" version="<?php echo $wp_version ?>">WordPress</generator>
<?php $items_count = 0; if ($posts) { foreach ($posts as $post) { start_wp(); ?>
<entry>
<name><?php the_author() ?></name>
<title><![CDATA[<?php the_title_rss() ?>]]></title>
<link rel="alternate" type="text/html" href="<?php permalink_single_rss() ?>" />
<id><?php bloginfo_rss("url") ?>?p=<?php echo $id; ?></id>
<modified><?php echo mysql2date('Y-m-d\TH:i:s\Z', $post->post_modified_gmt); ?></modified>
<issued><?php echo mysql2date('Y-m-d\TH:i:s\Z', $post->post_date_gmt); ?></issued>
<?php the_category_rss('rdf') ?>
<summary type="text/html" mode="escaped"><![CDATA[<?php the_excerpt_rss(get_settings('rss_excerpt_length'), 2) ?>]]></summary>
<?php if (!get_settings('rss_use_excerpt')) { ?>
<content type="text/html" mode="escaped" xml:base="<?php permalink_single_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content>
<?php } ?>
</entry>
<?php $items_count++; if (($items_count == get_settings('posts_per_rss')) && empty($m)) { break; } } } ?>
</feed>I have added more CDATA tags than is strictly necessary, wrapping titles as well as bodys but the feed validates and if somebody wants to have bold tags in there titles (dont ask me why) it should still validate.
thankyou for reading this far.
The topic ‘making rss validate with html payload.’ is closed to new replies.