<? include("phpincludes/connect.php"); ?>
<? function trimtekst($text,$maxchar){
  $split=explode(" ",$text);
  $i=0;
  while(TRUE){
	$len=(strlen($newtext)+strlen($split[$i]));
	if($len>$maxchar){
		break;
	}else{
		$newtext=$newtext." ".$split[$i];
		$i++;
	}
  }

$newtext = $newtext . "...";

	//put all opened tags into an array
	preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $newtext, $result);
	$openedtags = $result[1];
	
	//put all closed tags into an array
	preg_match_all('#</([a-z]+)>#iU', $newtext, $result);
	$closedtags = $result[1];
	$len_opened = count($openedtags);
	
	//all tags are closed
	if (count($closedtags) == $len_opened) {
		return $newtext;
	}
	$openedtags = array_reverse($openedtags);
	
	//close tags
	for ($i=0; $i < $len_opened; $i++) {
		if (!in_array($openedtags[$i], $closedtags)){
			$newtext .= '</'.$openedtags[$i].'>';
		} else {
			unset($closedtags[array_search($openedtags[$i], $closedtags)]);
		}
	}
	return $newtext;
}?>
<? echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";?>

<rss version="2.0">
   <channel>
      <title>Reisblog waarslaapje.nl</title>
      <link>http://www.waarslaapje.nl/reisblog</link>
      <description>Reisblog van Anne, over de unieke locaties van waarslaapje.nl, de bijzondere mensen die zij ontmoet, de bijzaken, kortom over alles wat zij onderweg op haar pad tegenkomt! </description>
		<? $query = "SELECT *,
		DATE_FORMAT(datum, '%a') AS dag, 
		DATE_FORMAT(datum, '%d') AS dagnr, 
		DATE_FORMAT(datum, '%b') AS maand, 
		DATE_FORMAT(datum, '%Y') AS jaar, 
		DATE_FORMAT(datum, '%H:%i:%s') AS tijd	
		FROM updates";   
		$resultaat = mysql_query($query) or die (mysql_error());    
		while($data = mysql_fetch_object($resultaat)){ ?>
	      <pubDate><? echo $data->dag . ", " . $data->dagnr . " " . $data->maand . " " . $data->jaar . " " . $data->tijd;?> +0100</pubDate>
		<? } ?>
		<language>NL</language>
		<image>
			<url>http://www.waarslaapje.nl/images/waarslaapje.jpg</url>
			<title>Reisblog waarslaapje.nl</title>
			<link>http://www.waarslaapje.nl/reisblog</link>
		</image>
		
		<? include("phpincludes/connect.php");
		$query = "SELECT weblog.*,
		DATE_FORMAT(datum, '%a') AS dag, 
		DATE_FORMAT(datum, '%d') AS dagnr, 
		DATE_FORMAT(datum, '%b') AS maand, 
		DATE_FORMAT(datum, '%Y') AS jaar, 
		DATE_FORMAT(datum, '%H:%i:%s') AS tijd,
		weblog_categorie.categorie
		FROM weblog
		INNER JOIN weblog_categorie ON weblog.categorieid = weblog_categorie.id
		ORDER BY datum DESC";   
		$resultaat = mysql_query($query) or die (mysql_error());    
		while($data = mysql_fetch_object($resultaat)){ 
		$tekst = $data->tekst;
		$text = trimtekst($tekst,700); 
$titel1 = htmlentities($data->titel);
$titel = str_replace("&euml;", "e", $titel1);
$titel_UTF8 = $titel;
$description = iconv("ISO-8859-1", "utf-8", "$text");

$text1 = htmlentities($text); 
$text2 = str_replace("&Atilde;", "e", $text1);
$text3 = str_replace("&Acirc;", "", $text2);
$text4 = str_replace("&copy;", "", $text3);
$text5 = str_replace("", "", $text4);
$text6 = str_replace("", "", $text5);

$description_UTF8 = $text6; 
?>	
		  <item>
			 <title><? echo $titel_UTF8;?></title>
			 <link>http://www.waarslaapje.nl/reisblog.htm?id=<? echo $data->id;?></link>
			 <description><? echo $description_UTF8;?><? echo htmlentities(" <a href=\"http://www.waarslaapje.nl/reisblog.htm?id=$data->id\">Lees verder &raquo;</a><br /><hr />");?></description>
			 <pubDate><? echo $data->dag . ", " . $data->dagnr . " " . $data->maand . " " . $data->jaar . " " . $data->tijd;?> +0100</pubDate>
			 <guid>http://www.waarslaapje.nl/reisblog.htm?id=<? echo $data->id;?></guid>
			 <category domain="http://www.waarslaapje.nl?categorie=<? echo $data->categorieid;?>"><? echo $data->categorie;?></category>
		  </item>
		<? } ?>
	
   </channel>
</rss>
