Improving validation for snews rss feeds (3)
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);
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 " 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:
<title><![CDATA['.strip($title).']]></title>
and replace it with:
<title><![CDATA['.strip(str_replace('"','\"',$title)).']]></title>
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
find:
echo '
<?xml version="1.0" encoding="'.s('charset').'"?>
<rss version="2.0">
<channel>
<title><![CDATA['.s('website_title').']]></title>
<description><![CDATA['.$heading.']]></description>
<link>'._SITE.'</link>
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="http://www.w3.org/2005/Atom">
<channel>
<title><![CDATA['.s('website_title').']]></title>
<description><![CDATA['.$heading.']]></description>
<link>'._SITE.'</link>
<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.
Festival of World Cultures
Went to visit this festival on Sunday in DΓΊn Laoghaire, Dublin. Great event with some great music. Weather could have been a bit better, but on the whole it was ok, except for the traffic. Below a small video snipplet of one of the bands playing for free in one of the side roads. The girl has a great voice, which isn’t really done justice by the video clip. Don’t remember the name of the band playing, but they are playing a well known song from the Blues Brothers. I’m sure you’ll recognize it.
Statistics for (w)rappers
Ever wondered what psychology students do in their free time between classes? Well here is the answer. Of course it’s only one answer which would be statistically irrelevant. Some psychology students at University of Oregon thought a rap video about their ordeals in learning stats would be interesting – it’s very funny if you can understand what their on about π
If you’re into stats for psychology have at Ed’s Statistics Home Page. He’s got some excellent stuff there (Answers to Questions about Statistics in Psychology).