<?php
header('Content-Type: application/rss+xml');

define('PATH_COUNTER', 2);
require_once '../../system/editorConnector.php';

function afbreken($msg, $tekens)
{
$eol = '
';
    $msg = strip_tags($msg);
    $msg = str_replace($eol,' ',$msg);
    $msg = str_replace('&nbsp;', ' ',$msg);
    if (strlen($msg) <= $tekens) {
        return $msg;
    } else {
        $woorden = explode(' ',$msg);
        $newwoorden = array();
        $length = 0;
        for($i=0; $i<count($woorden); $i++) {
            $length += strlen($woorden[$i]);
            if($length < $tekens) {
                $newwoorden[] = $woorden[$i];
            }
        }
        return implode(' ',$newwoorden);              
    }
}

$query = new query('
	SELECT
		a.Id,
		a.UserId,
		a.Datum,
		a.Kop,
		a.Bericht,
		a.Categorie,
		u.Username
	FROM
		`home-home-artikelen` a,
		`users` u
	WHERE
		a.UserId = u.Id AND
		a.Type = 1 AND
		a.Categorie != 5
	ORDER BY
		a.Datum DESC
	LIMIT 30');

if ($query->getNumRows()) {
	
	$nr2str = array(
            1 => 'basis',
            2 => 'triatlon',
            3 => 'trim',
            4 => 'waterpolo',
            5 => 'wedstrijd',
            6 => 'masters',
            7 => 'algemeen',
			8 => 'ndd75');
	
	echo
'<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
	<channel>
		<copyright>Copyright '.date('Y').' Nieuwe Doetinchemse Dolfijn</copyright>
		<pubDate>'.gmdate('D, j M Y H:i:s').' GMT</pubDate>
		<lastBuildDate>'.gmdate('D, j M Y H:i:s').' GMT</lastBuildDate>
		<description>De Nieuwe Doetinchemse Dolfijn: wedstrijdzwemmen, waterpolo, triatlon, trim &amp; recreatief zwemmen en basisopleidingen.</description>
		<language>nl-nl</language>
		<link>http://www.nieuwedoetinchemsedolfijn.nl/</link>
		<title>Nieuwe Doetinchemse Dolfijn</title>';
	
	while ($g = $query->fetchRows()) {
	
		echo '
		<item>
			<title>'.htmlentities(stripslashes($g['Kop'])).'</title>
			<link>http://www.nieuwedoetinchemsedolfijn.nl/index/'.$nr2str[$g['Categorie']].'/first/id:'.$g['Id'].'/'.urlKop($g['Kop']).'.html</link>
			<guid>http://www.nieuwedoetinchemsedolfijn.nl/index/'.$nr2str[$g['Categorie']].'/first/id:'.$g['Id'].'/'.urlKop($g['Kop']).'.html</guid>
			<description>'.stripslashes(afbreken($g['Bericht'],450)).'</description>
			<author>info@nieuwedoetinchemsedolfijn.nl ('.$g['Username'].')</author>
			<category>'.$nr2str[$g['Categorie']].'</category>
			<pubDate>'.gmdate('D, j M Y H:i:s', $g['Datum']).' GMT</pubDate>
		</item>';	
		
	}
	echo '
	</channel>
</rss>';
	
} else {
	echo '<!-- No articles -->';
}

?>