<?php
 

session_start();
include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

$getfilter = htmlentities(strip_tags($_REQUEST[filter]));
$filter = escape($getfilter);
$gettitle = htmlentities(strip_tags($_REQUEST[title]));
$gettitle = escape($gettitle);
$showmax = $config['max_syndicate_results'];

if (is_numeric($filter))
{
	$query="SELECT * FROM categories_channels WHERE CATID='".mysql_real_escape_string($filter)."'";
  	$executequery=$conn->execute($query);
  	$categoryname = $executequery->fields[name];
	$categorydetails = $executequery->fields[details];
	
	$query = "SELECT * from channels where category='".mysql_real_escape_string($filter)."' order by time_added desc limit $showmax";
	$link   = $config['baseurl']."/syndicate/categorychannels/$filter/$gettitle"; 
}


header("Content-Type: text/xml"); 
header("Expires: 0"); 
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; 
print "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\">\n"; 
print "<channel>\n"; 
print "<title>".$categoryname." $lang[37] - ".$config['site_name']."</title>\n"; 
print "<link>$link</link>\n"; 
print "<description>".$categorydetails."</description>\n"; 

$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME); 
  
$result = mysql_query($query) or die ('Query Error: ' . mysql_error()); 
while ($results = mysql_fetch_array($result)) 
{ 
  $thumbnail       = $config['cthumburl']."/".$results['photo']; 
  $video       = $config['baseurl']."/channels/".$results['CID']."/".seo_clean_titles_sendmail($results['name']); 
  $description = str_replace ("&amp","",htmlspecialchars(stripslashes($results['details']))); 
  
  $query="SELECT username FROM members WHERE USERID='".mysql_real_escape_string($results[MID])."'";
  $executequery=$conn->execute($query);
  $getusername = $executequery->fields[username];
		
	print "<item>\n"; 
	print "  <title>".$results['name']."</title>\n";
	print "  <link>".$video."</link>\n"; 
	print "  <description>\n"; 
	print "    <![CDATA["; 
	print "<img src=\"$thumbnail\" align=\"right\" border=\"0\" width=\"170\" height=\"120\" vspace=\"5\" hspace=\"5\"/>".$description."<br><br>$lang[672]: <a href=\"$config[baseurl]/members/profile/$results[MID]/$getusername\">$getusername</a>"; 
  		
	$query = "select name from categories_channels WHERE CATID='".mysql_real_escape_string($results['category'])."' limit 1"; 
	$executequery = $conn->execute($query);
	$category = $executequery->fields[name];
	
	print "<br>$lang[218]: $category"; 	
	print "<br>$lang[671]: $results[subscriptions]"; 
	print "<br>$lang[60]: $results[viewcount] | $lang[63]: $results[commentcount]";
	print "<br/><br/><br/><br/><br /><hr>"; 
	print "    ]]>\n"; 
	print "  </description>\n"; 
	print "  <author>".$getusername."</author>\n"; 
	print "</item>\n"; 
} 
mysql_close(); 
print "</channel>\n"; 
print "</rss>"; 
?> 