<?php
/*******************************************************************************
 * Copyright (c) 2006 Eclipse Foundation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Wayne Beaton (Eclipse Foundation)- initial API and implementation
 *******************************************************************************/

	#*****************************************************************************
	#
	# articles.rss
	#
	# Author: 		Wayne Beaton
	# Date:			2006-07-18
	#
	# Description: This page generates an RSS feed containing resources. 
	#   Optional filter parameters can be provided (see scripts/filter_core.php
    #   for information) to prune the list.
	#****************************************************************************
	header('Content-type: application/rss+xml;charset=UTF-8');
	
	// The next line needs to occur first in the file.
	echo "<?xml version=\"1.0\"?>\n";
	echo "<!DOCTYPE doc [";
	echo "<!ENTITY trade \"TM\">\n";
	echo "]>";
	
	require_once("scripts/resources.php");
	
	$resources_mgr = new Resources();
	
	$filter = new Filter();	
	$filter->populate_from_html_request_header();
	$resources = $resources_mgr->get_resources($filter);
	
	$resources_mgr->dispose();	
	
	$filter_summary = $filter->get_summary();
	$filter_string = $filter->get_url_parameters();	
	if ($filter_string) $filter_string = '?'.$filter_string;
	
	$count = 10; // maximum number of entries in the result.
	$host = $_SERVER['HTTP_HOST'];
	$resources_root = "http://$host/resources";
	if (array_key_exists('title', $_GET)) {
		$title = $_GET['title'];
	} else {
		$title = "Eclipse Resources";
	}
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <atom:link href="http://www.eclipse.org/resources/resources.rss" rel="self" type="application/rss+xml" />
    <title><?= $title ?></title>
    <description><?= "$filter_summary" ?></description>
    <link><![CDATA[<?=$resources_root?>]]></link>
    <image>
      <url><?= $resources_root ?>/images/eclipse.png</url>
      <title><?= $title ?></title>
      <link><?=$resources_root?></link>
    </image>
<?php
	foreach ($resources as $resource) {
		if ($count-- == 0) break;
		echo "\n\t<item>";
		echo "\n\t<guid>$resources_root/resource.php?id=$resource->id</guid>";
		echo "\n\t\t<title><![CDATA[$resource->title]]></title>";
		echo "\n\t\t<link>$resources_root/resource.php?id=$resource->id</link>";
		echo "\n\t\t<description><![CDATA[$resource->description]]></description>";
		$date = date("D, j M Y 12:00:00 \G\M\T", $resource->get_date());
		echo "\n\t\t<pubDate>$date</pubDate>";
		echo "\n\t</item>";
	}
?>
	</channel>
</rss>
