Horoscopes

//horoscope type (daily, weekly, monthly) and sign
$horoscope_t = strtolower($_GET['type']); $horoscope_s = strtolower($_GET['sign']);
if ($horoscope_t == "" && $horoscope_s == ""){
$horoscope_t = "daily"; $horoscope_s = "aries";
$horoscope_t = "daily"; // FORCE DAILY HOROSCOPES ONLY.
}
$result = horoscope_get($horoscope_t, $horoscope_s);
function horoscope_get($type, $sign){
if ($type == "profile"){
$thefeed = get_feed($type, $sign);
$xml = simplexml_load_file($thefeed);
$profile = "

" . $xml->$sign->description . "

";
$profile .= "

Symbol

" . $xml->$sign->symbol . "

";
$profile .= "

Element

" . $xml->$sign->element . "

";
$profile .= "

Ruling Planet

" . $xml->$sign->rulingplanet . "

";
$profile .= "

Body Part

" . $xml->$sign->bodypart . "

";
$profile .= "

Good Day

" . $xml->aries->goodday . "

";
$profile .= "

Bad Day

" . $xml->$sign->badday . "

";
$profile .= "

Favorite Things

" . $xml->$sign->favoritethings . "

";
$profile .= "

Can't Stand

" . $xml->$sign->cantstand . "

";
$profile .= "

Secret Wish

" . $xml->$sign->secretwish . "

";
$profile .= "

How to Spot Them

" . $xml->$sign->howtospot . "

";
$profile .= "

Where to Find Them

" . $xml->$sign->wheretofind . "

";
return $profile;
}
else{
$ns = array(
"content" => "http://purl.org/rss/1.0/modules/content/",
"wfw" => "http://wellformedweb.org/CommentAPI/",
"dc" => "http://purl.org/dc/elements/1.1/"
);
$thefeed = get_feed($type, $sign);
if ($thefeed == ""){
return "";
}else{
$xml = simplexml_load_file($thefeed);
$entries = $xml->channel->item[0]->children($ns["content"])->encoded; //woah. smart.
switch ($type){
case "daily":
//ORIGINAL PARSING
//$tmpresult = get_string_between($entries, "<" . $sign . ">", "</" . $sign . ">");
//NEW PARSING
$tmpresult = get_string_between($entries, "<p>&lt;" . $sign . "&gt;<br />", "<br />");
$tmpresult = str_replace("
", "", $tmpresult);
$tmpresult = str_replace('Times-Roman;">', "", $tmpresult);
$tmpresult = substr($tmpresult, strpos($tmpresult, ":")+1,strlen($tmpresult)-(strpos($tmpresult, ":")+1));
return $tmpresult;
break;
case "weekly": case "monthly":
$tmpresult = get_string_between($entries, "

", "</" . $sign . "

");
if ($type == "weekly"){ //remove unwanted text and html markup.
$tmpresult = str_replace("

", "", $tmpresult);
$locator = strpos($tmpresult, "
");
$tmpresult = substr($tmpresult, 0, $locator);
}else{
$locator = strpos($tmpresult, "
Filed under:");
$tmpresult = substr($tmpresult, 0, $locator);
$tmpresult = str_replace("MONTHLY OVERVIEW:","Monthly Overview", $tmpresult);
$tmpresult = str_replace("LOVE & ROMANCE:","Love & Romance", $tmpresult);
$tmpresult = str_replace("MONEY & CAREER:","Money & Career", $tmpresult);
$tmpresult = str_replace("HEALTH: MIND, BODY & SOUL:","Health: Mind, Body & Soul", $tmpresult);
}
return $tmpresult;
break;
default:
return "";
break;
}
}
}
}
function get_string_between($string, $start, $end){ //retrieves data contained within 2 strings.
$string = " " . $string;
$ini = strpos($string,$start);
if ($ini == 0){
return "";
}
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
function get_feed($type, $sign){
switch ($type){
case "profile":
$feed = "http://www.latina.com/sites/all/themes/latina_six/astrology/astrologypro...";
break;
case "daily":
$feed = "http://astrotwinsdaily.wordpress.com/category/daily-horoscope/feed/";
break;
case "weekly": case "monthly":
switch ($sign){
case "aquarius": case "aries": case "cancer": case "capricorn": case "gemini": case "leo":
case "libra": case "pisces": case "sagittarius": case "scorpio": case "taurus": case "virgo":
$feed = "http://ophitali.wordpress.com/category/" . $type . "-horoscopes/" . $sign . "-" . $type . "/feed";
break;
default: // invalid sign
$feed = "";
break;
}
break;
default: //invalid feed type
$feed = "";
break;
}
return $feed;
}

function horoscope_getactive($sign, $s_link){
if ($sign == $s_link){
return " selected-sign";
}
}

function horoscope_getactivetype($type, $t_link){
if ($type == $t_link){
return "selected";
}
}

function horoscope_name($sign){
$sign = strtolower($sign);
$sign = substr_replace($sign, strtoupper(substr($sign, 0, 1)), 0, 1);
return $sign;
}
function horoscope_date($sign){
switch ($sign){
case "aries":
$dateinfo = "March 21 - April 19";
break;
case "taurus":
$dateinfo = "April 20 - May 20";
break;
case "gemini":
$dateinfo = "May 21 - June 20";
break;
case "cancer":
$dateinfo = "June 21- July 22";
break;
case "leo":
$dateinfo = "July 23 - August 22";
break;
case "virgo":
$dateinfo = "August 23 - September 22";
break;
case "libra":
$dateinfo = "September 23 - October 22";
break;
case "scorpio":
$dateinfo = "October 23 - November 21";
break;
case "sagittarius":
$dateinfo = "November 22 - December 21";
break;
case "capricorn":
$dateinfo = "December 22 - January 19";
break;
case "aquarius":
$dateinfo = "January 20 - February 18";
break;
case "pisces":
$dateinfo = "February 19 - March 20";
break;
}
return $dateinfo;
}
?>

 

if (trim($result) == ""){
print "You have entered an invalid zodiac sign. Please try again.";
}else{
print $result;
}
?>

Horoscopes by The AstroTwins