<?php
	require_once 'config.php5';

	$zodiac_sign = strtolower( $_GET['sign'] );
	$zodiac_sign_caps = ucfirst($zodiac_sign);

	$base_url = "https://www.ask-oracle.com/";

	$url_path = 'horoscope/' . $zodiac_sign . '/';
	$analytics = "";

	$url = $base_url . $url_path . $analytics;
	$url_comments = $base_url . $url_path . '#comments';

	$img_url = $base_url . 'mail/' . $zodiac_sign . '.jpg';

header('Content-Type: text/xml; charset=UTF-8', true);
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
>

<channel>
	<title><?php echo 'Ask-Oracle.com Horoscopes for ' . $zodiac_sign_caps; ?></title>
	<atom:link href="<?php echo $base_url . 'charts/feed.php5?sign=' . $zodiac_sign; ?>" rel="self" type="application/rss+xml" />
	<link><?php echo $url; ?></link>
	<description>Daily, Weekly, Monthly and Yearly Horoscopes for <?php echo $zodiac_sign_caps; ?> Zodiac Sign. Accurate and Reliable.</description>
	<pubDate><?php echo date("r"); ?></pubDate>
	<lastBuildDate><?php echo date("r"); ?></lastBuildDate>
	<copyright>Copyright &#xA9; 2010 Ask Oracle. All rights reserved.</copyright>
	<language>en</language>
	<category><![CDATA[<?php echo $zodiac_sign_caps; ?>]]></category>
	<ttl>120</ttl>
	<image>
		<url><?php echo $img_url; ?></url>
		<link><?php echo $url; ?></link>
		<description>Daily, Weekly, Monthly and Yearly Horoscopes for <?php echo $zodiac_sign_caps; ?></description>
    </image>
	<sy:updatePeriod>daily</sy:updatePeriod>
	<sy:updateFrequency>2</sy:updateFrequency>

<?php

$getOption = mysql_query("SELECT option_name, option_value FROM ask_options WHERE option_name = 'daily' OR option_name = 'weekly' OR option_name = 'monthly';",$link);
while( $option = mysql_fetch_array($getOption, MYSQL_ASSOC) )
 {
	$header = array();
	$body = array();
	$footer = array();

	$type = $option['option_name'];
	$date = $option['option_value'];
	$date_formatted = date( "r", strtotime( $date ) ) ;
	list($month, $numday, $year, $fullmonth, $dow) = split('[/.-]', date("m.d.Y.F.w", strtotime( $date ) ) );

	//Select Horoscope Content
	$getContent = mysql_query("SELECT content FROM horoscope WHERE zodiac_sign='$zodiac_sign' AND type='$type' AND start_date='$date'", $link);
	$content = mysql_fetch_array($getContent, MYSQL_ASSOC);

	$item_title = $fullmonth . ' ' . $numday . ', ' . $year . ' - ' . $zodiac_sign_caps . ' ' . ucfirst($type) . ' Horoscope';	
	$item_url = $base_url . 'horoscope/' . $type . '/' . $zodiac_sign . '/';
	$item_desc = ucfirst($type) . ' Horoscope for ' . $zodiac_sign_caps . ' Zodiac Sign';
	$item_comment_feed = $item_url . 'feed/';

	$guid = $item_url . '#d' . $date;

	$h2 = '';

	if( $type == 'weekly' )
	{
		$h1 = 'Your Weekly Horoscope';
		$h2 = date("F j, Y", strtotime( $date )) . ' to ' . date("F j, Y", strtotime( $date ) + 6*86400) . ' | ';
	}
	else if( $type == 'monthly' )
	{
		$h1 = 'Your Monthly Horoscope for ' . date("F Y", strtotime( $date ));
	}
	else if( $type == 'daily' )
	{
		$h1 = 'Your Daily Horoscope for ' . date("F d, Y", strtotime( $date ) );
	}

	$h2 .= 'Provided by <a href="' . $base_url . '">Ask-Oracle.com</a>';

	if( $content )
	{
		$body[] = '<h1 style="font-size:16px">' . $h1 . '</h1>';
		$body[] = '<h2 style="font-size:14px">' . $h2 . '</h2>';
		$body[] = '<a href="' . $url . '"><img src="' . $img_url . '" alt="' . $item_desc . '" style="float: right; border: none;" /></a>';
		$body[] = mb_convert_encoding(nl2br( $content['content'] ), 'ISO-8859-15', 'UTF-8');
		$body[] = '<strong>See Next</strong> - <a title="100% Risk Free" href="http://www.ask-oracle.com/your-future-forecast-report/">Get your detailed personalized horoscope</a> and find out what\'s stored in your future and things that life has to offer. - Accurate and Helpful.';
	}
	else $body [] = "There was an ERROR retrieving the RSS content.";

	$content = implode( array_merge( $header, $body, $footer ) );?>

	<item>
		<title><?php echo $item_title; ?></title>
		<link><?php echo $item_url; ?></link>
		<comments><?php echo $item_comment_feed; ?></comments>
		<category><![CDATA[<?php echo $zodiac_sign . ', ' . $type; ?>, horoscope]]></category>
		<pubDate><?php echo $date_formatted; ?></pubDate>
		<dc:creator>Ask-Oracle.com</dc:creator>
		<guid isPermaLink="true"><?php echo $guid; ?></guid>
		<description><![CDATA[<?php echo $item_desc; ?>]]></description>
		<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
		<wfw:commentRss><?php echo $item_comment_feed; ?></wfw:commentRss>
	</item>

<?php

 }
?>
</channel>
</rss>
