<?php header('Content-Type: application/xml');
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"".chr(63).">\n";
echo "<?xml-stylesheet title=\"XSL_formatting\" type=\"text/xsl\" href=\"cf_news.xml\"".chr(63).">\n";


?>



<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">

<channel>

<atom:link href="http://www.citizenshipfoundation.org.uk/main/cf_newsfeedfull.xml" rel="self" type="application/rss+xml" />

<title>News from the Citizenship Foundation</title>
<description>Empowering individuals to engage in the wider community through education about the law, democracy and society</description>
<link>http://www.citizenshipfoundation.org.uk/</link>
<copyright>The Citizenship Foundation</copyright>



<?php


#feed headlines direct from database
#show all if no arg, match arg, or show none if faulty arg
$kargs=explode(";", preg_replace("/[^a-zA-Z0-9;']/","",$_SERVER['QUERY_STRING'])); #get arg to array, using ; separator

if (empty($kargs[0])) {
 $sql="SELECT nid, title, para1, body, reldate FROM news_live WHERE newspress=0 AND status=0 AND rss>0 AND (startdate<=\"".date("Y-m-d")."\" AND (stopdate>=\"".date("Y-m-d")."\" OR archived>0)) ORDER BY reldate DESC LIMIT 35;"; #NB when changing SQL see this AND line below
 }
else { #decode - using rule that kw is preceded by AND if kw is ALL CAPS else OR (added Jun07)
 $kwsql="";
 foreach ($kargs as $ind=>$kw) {
  if (strtoupper($kw)==$kw) $logsw=" AND "; else $logsw=" OR ";
  $kwsql=$kwsql."news_kw.kword=\"".strtolower($kw)."\" ".$logsw." ";
  }
 $kwsql=substr($kwsql,0,-(strlen($logsw)));
 $sql="SELECT  DISTINCTROW news_live.nid, news_live.title, news_live.para1, news_live.body, news_live.reldate FROM news_kw JOIN news_live ON (news_live.nid=news_kw.nidcode) WHERE (".$kwsql.") AND news_live.newspress=0 AND news_live.status=0 AND news_live.rss>0 AND (startdate<=\"".date("Y-m-d")."\" AND (stopdate>=\"".date("Y-m-d")."\" OR archived>0)) ORDER BY news_live.reldate DESC LIMIT 35;";  #NB when changing SQL see this AND line above

 }


include ("cf_user_functions.inc");

openme();


if($result = mysql_query($sql, $dblink)) {
 while ($irow=mysql_fetch_array($result)) {
  echo "<item>\n";
  echo "<title>".$irow["title"]."</title>\n";
  $irow["para1"]=preg_replace("/[’‘]/","'",$irow["para1"]); #remove rogue quotes L&R
  $irow["para1"] = html_entity_decode ($irow["para1"]);
  $irow["body"]=str_replace("../","http://www.citizenshipfoundation.org.uk/",$irow["body"]);
  echo "<description>".$irow["para1"]."</description>\n";
  echo "<content:encoded><![CDATA[".$irow["body"]."]]></content:encoded>\n";
  echo "<pubDate>".date("r", strtotime(substr($irow["reldate"],5,2)."/".substr($irow["reldate"],8,2)."/".substr($irow["reldate"],2,2)))."</pubDate>\n";
  echo "<link>http://www.citizenshipfoundation.org.uk/main/news.php?n".$irow["nid"]."</link>\n";
  echo "<guid isPermaLink=\"false\">citizenshipfoundation--".$irow["nid"]."</guid>\n"; #optional but Michael has a validator that says it's required (Aug 07)
  echo "</item>\n\n";
  }
 }

closeme();

#echo "<item>\n";
#echo "<title>SQL:</title>\n";
#echo "<description>".$sql."</description>\n";
#echo "<link></link>\n";
#echo "</item>\n";


#<item>
#<title>Topics of current interest...</title>
#<description>[------]</description>
#<link>http://www.citizenshipfoundation.org.uk/main/news.php</link>
#</item>

?>



</channel>
</rss>

