Improving validation for snews rss feeds (3)

March 22, 2010 at 18:07 1 comment

A final (hopefully) third fix was necessary for snews rss_function. At my site http://www.keramik-werkhof.de I use links and images which use “relative” paths, e.g. <img src="uploads/images .. instead of <img src="http://www.domain.de/uploads/images … 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);

Entry filed under: snews CMS. Tags: , , , .

Improving validation for snews rss feeds (2)

1 Comment Add your own

Leave a comment

Trackback this post  |  Subscribe to the comments via RSS Feed


March 2010
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  

Categories

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

Join 1 other subscriber