<?  
include ("login/includes/connection.php");
putenv("TZ=US/Eastern");

echo '<?xml version="1.0" encoding="iso-8859-1"?>'; 
echo "\n<rss version='2.0'>";
echo "<channel>";
echo "<title>30 Extra Lives</title>";
echo "<description> Webcomic, Comic and Game Reviews.  Your one stop shop for time wasting brought to you by Tom Lynch and Jon Rivers. </description>";
echo "<link>http://30extralives.com</link>";

$count = 0;
$currdate = date("Y-m-d",time());
$currdatepost = date("Y-m-d H:i:s",time());

$result = mysql_query("select ID,thedate,thetable from RSSFeed where thedate <= '".$currdatepost."' order by thedate DESC LIMIT 5;");
while($row = mysql_fetch_array($result))
{
  $id = $row['ID'];
  $date = $row['thedate'];
  $thetable = $row['thetable'];

  if($thetable == 'Posts')
  {
    $result2 = mysql_query("select pid,Text,Date,Writer,Title,tags from Posts where Date <= '".$currdatepost."' and pid = ".$id.";");
    while($row2 = mysql_fetch_array($result2))
    {
      $date = $row2['Date'];
      $pubDate = date("D, d M Y H:i", strtotime($row2['Date']));
      $pid = $row2['pid'];
      $url = "http://30extralives.com/postarchive.php?id=".$pid;
      $text = $row2['Text'];
      $title = $row2['Title'];
      $writer = $row2['Writer'];
      $tags = $row2['tags'] . ",";

	$offset = 0;
      if(strpos($tags,'1,') !== false)
	{
	  $offset = 250;
	}
    echo "<item>";
    echo "<pubDate>".$pubDate."</pubDate>";
    echo "<title>News: ".$title."</title>";
    echo "<author>".$writer."</author>";
    echo "<link>".$url."</link>";
    echo "<description><![CDATA[".substr($text,0,strpos($text,"</p>")+$offset)."<BR>...<BR><BR><a href='".$url."'>Continue Reading ".$title."...</a>]]></description>";
    echo "</item>";
    }
  }
  if($thetable == 'SubPosts')
  {
    $result2 = mysql_query("select pid,sid,Text,Date,Writer,Title from SubPosts where sid = ".$id.";");
    while($row2 = mysql_fetch_array($result2))
    {
      $pubDate = date("D, d M Y H:i", strtotime($row2['Date']));
      $sid = $row2['sid'];
      $pid = $row2['pid'];
      $url = "http://30extralives.com/postarchive.php?id=".$pid;
      $text = $row2['Text'];
      $title = $row2['Title'];
      $writer = $row2['Writer'];
      $date2 = strtotime($row2['Date']);
    echo "<item>";
    echo "<pubDate>".$pubDate."</pubDate>";
    echo "<title>News: ".$title."</title>";
    echo "<author>".$writer."</author>";
    echo "<link>".$url."#".$date2."</link>";
    echo "<description><![CDATA[".substr($text,0,strpos($text,"<BR><BR>"))."<BR>...<BR><BR><a href='".$url."'>Continue Reading ".$title."...</a>]]></description>";
    echo "</item>";
    }
  }
  if($thetable == 'Reviews')
  {
    $result2 = mysql_query("select rid,text,Date,Writer,Title,description from Reviews where rid = ".$id.";");
    while($row2 = mysql_fetch_array($result2))
    {
      $pubDate = date("D, d M Y H:i", strtotime($row2['Date']));
      $rid = $row2['rid'];
      $url = "http://30extralives.com/reviews.php?id=".$rid;
      $text = $row2['text'];
      $title = $row2['Title'];
      $writer = $row2['Writer'];
      $desc = $row2['description'];

      $result3 = mysql_query("select username from members where id = ".$writer);
      while($row3 = mysql_fetch_array($result3))
      {
        $writer = $row3['username'];
      }

      if(strchr($text,"www.cincity2000.com"))
      {
      $url = "http://30extralives.com/reviews.php#CC2K";
    echo "<item>";
    echo "<pubDate>".$pubDate."</pubDate>";
    echo "<title>Review: ".$title."</title>";
    echo "<author>".$writer."</author>";
    echo "<link>".$url."</link>";
    echo "<description>Reviews for other people! \n\r <![CDATA[".$desc."]]></description>";
    echo "</item>";
      }
	else if(strchr($text,"www.captainbluehen.com"))
      {
      $url = "http://30extralives.com/reviews.php#CBH";
    echo "<item>";
    echo "<pubDate>".$pubDate."</pubDate>";
    echo "<title>Review: ".$title."</title>";
    echo "<author>".$writer."</author>";
    echo "<link>".$url."</link>";
    echo "<description>Reviews for other people! \n\r <![CDATA[".$desc."]]></description>";
    echo "</item>";
      }
	else
      {
    echo "<item>";
    echo "<pubDate>".$pubDate."</pubDate>";
    echo "<title>Review: ".$title."</title>";
    echo "<author>".$writer."</author>";
    echo "<link>".$url."</link>";
    echo "<description><![CDATA[".substr($text,0,strpos($text,"</p>"))."<BR>...<BR><BR><a href='".$url."'>Continue Reading ".$title."...</a>]]></description>";
    echo "</item>";
      }
    }
  }
  if($thetable == 'Comic30EL')
  {
    $result2 = mysql_query("select cid,Date,Title,notes from Comic30EL where Date <= '".$currdate."' and cid = ".$id.";");
    while($row2 = mysql_fetch_array($result2))
    {
      $pubDate = date("D, d M Y H:i", strtotime($row2['Date']));
      $cid = $row2['cid'];
      $url = "http://30extralives.com/comicarchive.php?cid=".$cid;
      $title = $row2['Title'];
      $notes = $row2['notes'];

    echo "<item>";
    echo "<pubDate>".$pubDate."</pubDate>";
    echo "<title>Comic: ".$title."</title>";
    echo "<author>Tom</author>";
    echo "<link>".$url."</link>";
    echo "<description><![CDATA[New Comic!<BR><BR><a href='".$url."'>Click to read ".$title."!</a><BR><BR>".$notes."<BR>]]></description>";
    echo "</item>";
    }
  }

}

mysql_close($con);
?>
</channel>
</rss>