<?php

header('Content-type: text/xml');
$base_url = get_base_url();

?>
<rss version="2.0">
  <channel>
    <title>OneMoreLevel.com</title>
    <link>http://www.onemorelevel.com/</link>
    <description>Productivity killing, carpal tunnel inducing, addictive flash games</description>
    <language>en-us</language>
    <managingEditor>feed@onemorelevel.com</managingEditor>
<?php

  // Include DB info
  require_once('../OMLpasses/access.inc');

  // Connect to DB
  @mysql_connect($mysqlhost, $mysqlviewer, $mysqlviewpass);
  @mysql_select_db($mysqldb);

  // Grab last 7 games
  $query = "SELECT title, url_title, type, location, id, description, showdate
            FROM games
            WHERE showdate < DATE_ADD(now(),INTERVAL 1 DAY)
            ORDER BY showdate DESC
            LIMIT 7";
  $result = mysql_query($query);
  
  // Cycle through results
  while ($thisEntry = mysql_fetch_array($result))
  {
    // Extract current entry data
    $thisTitle = stripslashes($thisEntry['title']);
	$thisURLTitle = $thisEntry['url_title'];
    $thisType = $thisEntry['type'];
    $thisID = $thisEntry['id'];
    if ($thisType == 'external')
    {
      $thisLink = $thisEntry['location'];
    }
    else
    {
      $thisLink = "$base_url/game/$thisURLTitle";
    }
    $thisDesc = stripslashes($thisEntry['description']);
    $thisDate = strtotime($thisEntry['showdate']);
    $thisDate = date('D, d M Y', $thisDate);
    echo<<<EOSTRING
    <item>
      <title>$thisTitle</title>
      <link>
      $thisLink
      </link>
      <description>
      $thisDesc
      </description>
      <pubDate>$thisDate 00:00:00 PST</pubDate>
      <guid>
      $thisLink
      </guid>
    </item>

EOSTRING;
  }

	function get_base_url()
	{
		if (isset($_SERVER['HTTPS']) AND $_SERVER['HTTPS'] == 'on')
			$url = 'https://';
		else
			$url = 'http://';
		$url .= $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
		return trim($url, '/');
	}

?>
  </channel>
</rss>
