Archive for March, 2010

Improving validation for snews rss feeds (3)

A final (hopefully) third fix was necessary for snews rss_function. At my site I use links and images which use “relative” paths, e.g. <img src="uploads/images .. instead of <img src=" … This is some the w3c validator does not accept in rss feeds. So how to make sure the full path is used in links and images inside the description of rss content. Well, I came across a function in drupal which fixes this, atleast for links. I had to modify the regex a tiny bit to recognize images aswell (added a dot in the ([A-Za-z0-9) section . So here we go:

find the rss_content function and above it, add the following new function:
function rss_relative_links($description) {
// replace all links starting with '/'
$regexp = "/\b(href|src)(\s*=\s*['\"])([\/][A-Za-z0-9.\/]*)(['\"])/";
$description = preg_replace($regexp, '$1$2'. _SITE. '$3$4', $description);
// replace all relative links not starting with '/'. Absolute links are not matched,
// since ':' is not in the capture pattern.
$regexp = "/\b(href|src)(\s*=\s*['\"])([^\/][A-Za-z0-9.\/]*)(['\"])/";
$description = preg_replace($regexp, '$1$2'. _SITE. '$3$4', $description);
return $description;

Then in the function rss_content find:
$link = _SITE.$categorySEF.$articleSEF.'/'.$comment_link;

and add a new line above it with the following:
$text = rss_relative_links($text);


March 22, 2010 at 18:07 1 comment

Improving validation for snews rss feeds (2)

So now, my snews cms site uses UTF-8 charset, cause the site is in German. Now and again I used quote tags in the headlines. The get converted to &quot; in the database, which is fine. However the html entity for quotes turns up in the snews rss feed an will break validation (snews 1.7, March 2010). The fix for this is quite simple … here we go:

in the rss_contents function (near to end) find:

and replace it with:

March 22, 2010 at 16:31 Leave a comment

Improving validation for snews rss feeds (1)

While checking the validation for snews rss feeds, I came up against some problems and found some fixes, which may help others who have similar proplems. The first problems I encountered was the the w3c rss validator told me that in the link tag the rel=self was missing. This is easily fixed by adding the following lines to the rss_contents() in snews.php

echo '
<?xml version="1.0" encoding="'.s('charset').'"?>
<rss version="2.0">

and replace with:
if (substr($rss_item,-1) != '/') {
  $rss_item_link = $rss_item . '/';
} else {
  $rss_item_link = $rss_item;
echo '
<?xml version="1.0" encoding="'.s('charset').'"?>
<rss version="2.0" xmlns:atom=""&gt;
<atom:link href="'._SITE.$rss_item_link.'" rel="self" type="application/rss+xml" />

This will make the feed Atom compliant, which seems to be necessarry for the w3c Validator.

March 22, 2010 at 16:01 Leave a comment

March 2010
« Aug    


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1 other follower