<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://gekkoware.sourceforge.net
	*/

	if (!defined("IN-BLOCK")) die();

	/*
	<%%>
	<?xml version="1.0" encoding="UTF-8"?>
	<blockscript>
		<info lang="en">
			<title>News Reader</title>
			<description>Syndicates news from a feeder</description>
			<author><![CDATA[xiam &lt;<a href="mailto:xiam@users.sourceforge.net">xiam@users.sourceforge.net</a>&gt;]]></author>
			<homepage><![CDATA[<a href="http://www.gekkoware.org">http://www.gekkoware.org</a>]]></homepage>
		</info>
		<info lang="es">
			<title>Clima</title>
			<description><![CDATA[Sincroniza noticias de un alimentador]]></description>
		</info>
		<variable name="url"><![CDATA[]]></variable>
		<variable name="type"><![CDATA[rss]]></variable>
		<variable name="items"><![CDATA[8]]></variable>
		<variable name="refresh_rate"><![CDATA[8]]>1800</variable>
	</blockscript>
	<%%>
	*/

	require_once GEKKO_ROOT."lib/news_reader.lib.php";

	$cache_key = cache_assign_key($url, $items);

	// checking cache life
	if (($life = cache_check_life($cache_key)) !== false) {
		if ((time() - $life) < $refresh_rate) {
			cache_read($cache_key, $return);
		}
	}

	// downloading feed
	if (!$return) {
		if ($url && ($type == "rss" || $type == "atom")) {

			$feed = ($type == "rss") ? new rss_reader : new atom_reader;

			$feed->set_limit($items);

			$feed->sync($url);

			$return = $feed->html;

			cache_save($cache_key, $return);
		}
	}

?>