<?
include "mysqlcon.php";
include "functions.php";
$admin_info = mysql_fetch_assoc(mysql_query("SELECT url FROM bhost_admin"));

// FOR BACKWARDS COMPATIBILITY:
if(isset($_GET['u'])) { $_GET['w'] = $_GET['u']; }
if(isset($_GET['w'])) { $w = $_GET['w']; } else { exit(); }

$getweblog = mysql_query("SELECT * FROM bhost_weblogs WHERE weblog='$w'");
if(mysql_num_rows($getweblog) == 0) { exit(); }
$weblog = mysql_fetch_assoc($getweblog);
$owner = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_users WHERE u_id='$weblog[u_id]'"));

// CHECK IF ADMIN HAS TURNED RSS OFF
$owner_group = mysql_fetch_assoc(mysql_query("SELECT allow_rss FROM bhost_groups WHERE g_id='$owner[g_id]'"));
if($owner_group[allow_rss] != "1") { exit(); }

// CHECK IF USER HAS TURNED RSS OFF
if($weblog[rss_on] != 1) { exit(); }

$basepath1 = url("index", "$weblog[weblog]");

header("Content-Type: text/xml");
header("Pragma: no-cache");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<rss version=\"2.0\">
<channel>
<title>$weblog[title]</title>
<description>$weblog[description]</description>
<link>$basepath1</link>
<language>en-us</language>
<generator>Webligo BlogHoster</generator>
";

$entries = mysql_query("SELECT * FROM bhost_entries WHERE w_id='$weblog[w_id]' AND privacy='3' AND draft='0' ORDER BY e_id DESC LIMIT $weblog[rss_entries]");
while($entry = mysql_fetch_assoc($entries)) {
$basepath2 = url("entry_rss", "$weblog[weblog]", "", "$entry[e_id]");
$content = str_replace("&#39;", "'", $entry['contents']);
$title = str_replace("&#39;", "'", $entry['title']);
  if($weblog[rss_html] == "0") {
  $content = strip_tags($content);
  $title = strip_tags($title);
  }
$content = htmlspecialchars($content);
$title = htmlspecialchars($title);
echo "
<item>
<title>$title</title>
<description>$content</description>
<link>$basepath2</link>
</item>
";
}

echo "
</channel>
</rss>";

?>