loc['id']; } // If there's no location, include index_error.php in weather.php if ($locCount == 0 && $bypass == false) { require_once('index_error.php'); exit; } // If there is more than one location, include index_locations.php in weather.php else if ($locCount > 1) { require_once('index_locations.php'); exit; } // If there is exactly one locations, get the raw weather XML else { if(!$bypass) $code = $locId[0]; $rawFeed = file_get_contents('http://weather.yahooapis.com/forecastrss?p='.$code); } // Cheat $rawFeed = str_replace('yweather:', '', $rawFeed); $rawFeed = str_replace('geo:', '', $rawFeed); // Parse the XML into a structured object $xml = new SimpleXmlElement($rawFeed); $channel = $xml->channel; $location = $channel->location; $city = $channel->location['city']; $region = $location['region']; $country = $location['country']; if ($region == '') { $region = $country; } $item = $channel->item; $atmosphere = $channel->atmosphere; $humidity = $channel->atmosphere['humidity']; // Current conditions $condition = $item->condition; $date = $condition['date']; $temperature = $condition['temp']; $conditionCode = $condition['code']; $conditionText = $condition['text']; $conditionTextPlus = str_replace(' ', '+', $conditionText); $conditionTextQuotes = '%22'.$conditionTextPlus.'%22'; // Today's forecast $forecast = $item->forecast[0]; $day = $forecast['day']; $low = $forecast['low']; $high = $forecast['high']; $forecastCode = $forecast['code']; $forecastText = $forecast['text']; $forecastTextPlus = str_replace(' ', '+', $forecastText); $forecastTextQuotes = '%22'.$forecastTextPlus.'%22'; // Tomorrow's forecast $forecastNext = $item->forecast[1]; $dayNext = $forecastNext['day']; $lowNext = $forecastNext['low']; $highNext = $forecastNext['high']; $forecastCodeNext = $forecastNext['code']; $forecastTextNext = $forecastNext['text']; $forecastTextPlusNext = str_replace(' ', '+', $forecastTextNext); $forecastTextQuotesNext = '%22'.$forecastTextPlusNext.'%22'; // --------NEWS FOR CURRENT CONDITION-------- // News feed for the current condition $rawConditionFeed = file_get_contents('http://news.google.com/news?q='.$conditionTextQuotes.'&output=rss'); // Parse the XML into a structured object $xmlCondition = new SimpleXmlElement($rawConditionFeed); $channelCondition = $xmlCondition->channel; $itemCondition = $channelCondition->item[0]; // If there are items in the news feed if ($itemCondition) { // Extract relevant components $pubDateCondition = $itemCondition->pubDate; $titleCondition = $itemCondition->title; $linkCondition = $itemCondition->link; $descCondition = $itemCondition->description; $descCondition = str_replace('<', '<', $descCondition); $descCondition = str_replace('>', '>', $descCondition); $descCondition = split("", $descCondition); $descCondition = strip_tags($descCondition[2]); $titleCondition = str_ireplace($conditionText, ''.$conditionText.'', $titleCondition); $h3Condition = ''.$titleCondition.''; } //If there are no items in the news feed else { $conditionText = str_ireplace($conditionText, ''.$conditionText.'', $conditionText); $h3Condition = 'No news available for '.$conditionText.'.'; } // Change color of weather data text $descCondition = str_ireplace($conditionText, ''.$conditionText.'', $descCondition); // --------NEWS FOR CURRENT TEMP-------- // News feed for the current temperature $rawTempFeed = file_get_contents('http://news.google.com/news?q='.$temperature.'&output=rss'); // Parse the XML into a structured object $xmlTemp = new SimpleXmlElement($rawTempFeed); $channelTemp = $xmlTemp->channel; $itemTemp = $channelTemp->item[0]; // If there are items in the news feed if ($itemTemp) { // Extract relevant components $pubDateTemp = $itemTemp->pubDate; $titleTemp = $itemTemp->title; $linkTemp = $itemTemp->link; $descTemp = $itemTemp->description; $descTemp = str_replace('<', '<', $descTemp); $descTemp = str_replace('>', '>', $descTemp); $descTemp = split("", $descTemp); $descTemp = strip_tags($descTemp[2]); $titleTemp = str_ireplace($temperature, ''.$temperature.'', $titleTemp); $h3Temp = ''.$titleTemp.''; } // If there are no items in the news feed else { $temperature = str_ireplace($temperature, ''.$temperature.'', $temperature); $h3Temp = 'No news available for '.$temperature.'.'; } // Change color of weather data text $descTemp = str_ireplace($temperature, ''.$temperature.'', $descTemp); // --------IMAGE FOR CURRENT CONDITIONS AND TEMP-------- // Image feed for the current conditions and temperature $rawImgFeed = file_get_contents('http://news.google.com/news?q='.$conditionTextQuotes.'+OR+'.$temperature.'&imv=1&output=rss'); if ($rawImgFeed) { // Parse the XML into a structured object $xmlImg = new SimpleXmlElement($rawImgFeed); $channelImg = $xmlImg->channel; for ($i = 0; $i <= 9; $i++) { $itemImg = $channelImg->item[$i]; // Extract relevant components $pubDateImg = $itemImg->pubDate; $titleImg = $itemImg->title; $linkImg = $itemImg->link; $descImg = $itemImg->description; $descImg = str_replace('<', '<', $descImg); $descImg = str_replace('>', '>', $descImg); $photoImg = strip_tags($descImg, ''); $photoImg = str_replace('border=1', 'border=0', $photoImg); $photoImg = split('', $photoImg); $photoImg = str_replace('">', '" target="_blank">', $photoImg); $photoImg = str_replace('border=0>', 'border=0>

', $photoImg); $photoImg = $photoImg[0]; $photoImgItem[$i] = $photoImg; } } // --------NEWS FOR TODAY'S FORECASTED CONDITION-------- // News feed for the current condition $rawTodayCondFeed = file_get_contents('http://news.google.com/news?q='.$forecastTextQuotes.'&output=rss'); // Parse the XML into a structured object $xmlTodayCond = new SimpleXmlElement($rawTodayCondFeed); $channelTodayCond = $xmlTodayCond->channel; $itemTodayCond = $channelTodayCond->item[0]; // If there are items in the news feed if ($itemTodayCond) { // Extract relevant components $pubDateTodayCond = $itemTodayCond->pubDate; $titleTodayCond = $itemTodayCond->title; $linkTodayCond = $itemTodayCond->link; $descTodayCond = $itemTodayCond->description; $descTodayCond = str_replace('<', '<', $descTodayCond); $descTodayCond = str_replace('>', '>', $descTodayCond); $descTodayCond = split("", $descTodayCond); $descTodayCond = strip_tags($descTodayCond[2]); $titleTodayCond = str_ireplace($forecastText, ''.$forecastText.'', $titleTodayCond); $h3TodayCond = ''.$titleTodayCond.''; } // If there are no items in the news feed else { $forecastText = str_ireplace($forecastText, ''.$forecastText.'', $forecastText); $h3TodayCond = 'No news available for '.$forecastText.'.'; } // Change color of weather data text $descTodayCond = str_ireplace($forecastText, ''.$forecastText.'', $descTodayCond); // --------NEWS FOR TODAY'S FORECASTED HIGH-------- // News feed for the current condition $rawTodayHighFeed = file_get_contents('http://news.google.com/news?q='.$high.'&output=rss'); // Parse the XML into a structured object $xmlTodayHigh = new SimpleXmlElement($rawTodayHighFeed); $channelTodayHigh = $xmlTodayHigh->channel; $itemTodayHigh = $channelTodayHigh->item[0]; // If there are items in the news feed if ($itemTodayHigh) { // Extract relevant components $pubDateTodayHigh = $itemTodayHigh->pubDate; $titleTodayHigh = $itemTodayHigh->title; $linkTodayHigh = $itemTodayHigh->link; $descTodayHigh = $itemTodayHigh->description; $descTodayHigh = str_replace('<', '<', $descTodayHigh); $descTodayHigh = str_replace('>', '>', $descTodayHigh); $descTodayHigh = split("", $descTodayHigh); $descTodayHigh = strip_tags($descTodayHigh[2]); $titleTodayHigh = str_ireplace($high, ''.$high.'', $titleTodayHigh); $h3TodayHigh = ''.$titleTodayHigh.''; } // If there are no items in the news feed else { $high = str_ireplace($high, ''.$high.'', $high); $h3TodayHigh = 'No news available for '.$high.'.'; } // Change color of weather data text $descTodayHigh = str_ireplace($high, ''.$high.'', $descTodayHigh); // --------NEWS FOR TODAY'S FORECASTED LOW-------- // News feed for the current condition $rawTodayLowFeed = file_get_contents('http://news.google.com/news?q='.$low.'&output=rss'); // Parse the XML into a structured object $xmlTodayLow = new SimpleXmlElement($rawTodayLowFeed); $channelTodayLow = $xmlTodayLow->channel; $itemTodayLow = $channelTodayLow->item[0]; // If there are items in the news feed if ($itemTodayLow) { // Extract relevant components $pubDateTodayLow = $itemTodayLow->pubDate; $titleTodayLow = $itemTodayLow->title; $linkTodayLow = $itemTodayLow->link; $descTodayLow = $itemTodayLow->description; $descTodayLow = str_replace('<', '<', $descTodayLow); $descTodayLow = str_replace('>', '>', $descTodayLow); $descTodayLow = split("", $descTodayLow); $descTodayLow = strip_tags($descTodayLow[2]); $titleTodayLow = str_ireplace($low, ''.$low.'', $titleTodayLow); $h3TodayLow = ''.$titleTodayLow.''; } // If there are no items in the news feed else { $low = str_ireplace($low, ''.$low.'', $low); $h3TodayLow = 'No news available for '.$low.'.'; } // Change color of weather data text $descTodayLow = str_ireplace($low, ''.$low.'', $descTodayLow); // --------NEWS FOR TOMORROW'S FORECASTED CONDITION-------- // News feed for the current condition $rawTomCondFeed = file_get_contents('http://news.google.com/news?q='.$forecastTextQuotesNext.'&output=rss'); // Parse the XML into a structured object $xmlTomCond = new SimpleXmlElement($rawTomCondFeed); $channelTomCond = $xmlTomCond->channel; $itemTomCond = $channelTomCond->item[0]; // If there are items in the news feed if ($itemTomCond) { // Extract relevant components $pubDateTomCond = $itemTomCond->pubDate; $titleTomCond = $itemTomCond->title; $linkTomCond = $itemTomCond->link; $descTomCond = $itemTomCond->description; $descTomCond = str_replace('<', '<', $descTomCond); $descTomCond = str_replace('>', '>', $descTomCond); $descTomCond = split("", $descTomCond); $descTomCond = strip_tags($descTomCond[2]); $titleTomCond = str_ireplace($forecastTextNext, ''.$forecastTextNext.'', $titleTomCond); $h3TomCond = ''.$titleTomCond.''; } // If there are no items in the news feed else { $forecastTextNext = str_ireplace($forecastTextNext, ''.$forecastTextNext.'', $forecastTextNext); $h3TomCond = 'No news available for '.$forecastTextNext.'.'; } // Change color of weather data text $descTomCond = str_ireplace($forecastTextNext, ''.$forecastTextNext.'', $descTomCond); // --------NEWS FOR TOMORROW'S FORECASTED HIGH-------- // News feed for the current condition $rawTomHighFeed = file_get_contents('http://news.google.com/news?q='.$highNext.'&output=rss'); // Parse the XML into a structured object $xmlTomHigh = new SimpleXmlElement($rawTomHighFeed); $channelTomHigh = $xmlTomHigh->channel; $itemTomHigh = $channelTomHigh->item[0]; // If there are items in the news feed if ($itemTomHigh) { // Extract relevant components $pubDateTomHigh = $itemTomHigh->pubDate; $titleTomHigh = $itemTomHigh->title; $linkTomHigh = $itemTomHigh->link; $descTomHigh = $itemTomHigh->description; $descTomHigh = str_replace('<', '<', $descTomHigh); $descTomHigh = str_replace('>', '>', $descTomHigh); $descTomHigh = split("", $descTomHigh); $descTomHigh = strip_tags($descTomHigh[2]); $titleTomHigh = str_ireplace($highNext, ''.$highNext.'', $titleTomHigh); $h3TomHigh = ''.$titleTomHigh.''; } // If there are no items in the news feed else { $highNext = str_ireplace($highNext, ''.$highNext.'', $highNext); $h3TomHigh = 'No news available for '.$highNext.'.'; } // Change color of weather data text $descTomHigh = str_ireplace($highNext, ''.$highNext.'', $descTomHigh); // --------NEWS FOR TOMORROW'S FORECASTED LOW-------- // News feed for the current condition $rawTomLowFeed = file_get_contents('http://news.google.com/news?q='.$lowNext.'&output=rss'); // Parse the XML into a structured object $xmlTomLow = new SimpleXmlElement($rawTomLowFeed); $channelTomLow = $xmlTomLow->channel; $itemTomLow = $channelTomLow->item[0]; // If there are items in the news feed if ($itemTomLow) { // Extract relevant components $pubDateTomLow = $itemTomLow->pubDate; $titleTomLow = $itemTomLow->title; $linkTomLow = $itemTomLow->link; $descTomLow = $itemTomLow->description; $descTomLow = str_replace('<', '<', $descTomLow); $descTomLow = str_replace('>', '>', $descTomLow); $descTomLow = split("", $descTomLow); $descTomLow = strip_tags($descTomLow[2]); $titleTomLow = str_ireplace($lowNext, ''.$lowNext.'', $titleTomLow); $h3TomLow = ''.$titleTomLow.''; } // If there are no items in the news feed else { $lowNext = str_ireplace($lowNext, ''.$lowNext.'', $lowNext); $h3TomLow = 'No news available for '.$lowNext.'.'; } // Change color of weather data text $descTomLow = str_ireplace($lowNext, ''.$lowNext.'', $descTomLow); // --------PHP SmartyPants, for good typography-------- include_once "smartypants.php"; $h3Condition = html_entity_decode($h3Condition, ENT_QUOTES); $h3Condition = str_ireplace(' - ', ' — ', $h3Condition); $h3Condition = SmartyPants($h3Condition); $descCondition = html_entity_decode($descCondition, ENT_QUOTES); $descCondition = str_ireplace(' - ', ' — ', $descCondition); $descCondition = SmartyPants($descCondition); $h3Temp = html_entity_decode($h3Temp, ENT_QUOTES); $h3Temp = str_ireplace(' - ', ' — ', $h3Temp); $h3Temp = SmartyPants($h3Temp); $descTemp = html_entity_decode($descTemp, ENT_QUOTES); $descTemp = str_ireplace(' - ', ' — ', $descTemp); $descTemp = SmartyPants($descTemp); $h3TodayCond = html_entity_decode($h3TodayCond, ENT_QUOTES); $h3TodayCond = str_ireplace(' - ', ' — ', $h3TodayCond); $h3TodayCond = SmartyPants($h3TodayCond); $descTodayCond = html_entity_decode($descTodayCond, ENT_QUOTES); $descTodayCond = str_ireplace(' - ', ' — ', $descTodayCond); $descTodayCond = SmartyPants($descTodayCond); $h3TodayHigh = html_entity_decode($h3TodayHigh, ENT_QUOTES); $h3TodayHigh = str_ireplace(' - ', ' — ', $h3TodayHigh); $h3TodayHigh = SmartyPants($h3TodayHigh); $descTodayHigh = html_entity_decode($descTodayHigh, ENT_QUOTES); $descTodayHigh = str_ireplace(' - ', ' — ', $descTodayHigh); $descTodayHigh = SmartyPants($descTodayHigh); $h3TodayLow = html_entity_decode($h3TodayLow, ENT_QUOTES); $h3TodayLow = str_ireplace(' - ', ' — ', $h3TodayLow); $h3TodayLow = SmartyPants($h3TodayLow); $descTodayLow = html_entity_decode($descTodayLow, ENT_QUOTES); $descTodayLow = str_ireplace(' - ', ' — ', $descTodayLow); $descTodayLow = SmartyPants($descTodayLow); $h3TomCond = html_entity_decode($h3TomCond, ENT_QUOTES); $h3TomCond = str_ireplace(' - ', ' — ', $h3TomCond); $h3TomCond = SmartyPants($h3TomCond); $descTomCond = html_entity_decode($descTomCond, ENT_QUOTES); $descTomCond = str_ireplace(' - ', ' — ', $descTomCond); $descTomCond = SmartyPants($descTomCond); $h3TomHigh = html_entity_decode($h3TomHigh, ENT_QUOTES); $h3TomHigh = str_ireplace(' - ', ' — ', $h3TomHigh); $h3TomHigh = SmartyPants($h3TomHigh); $descTomHigh = html_entity_decode($descTomHigh, ENT_QUOTES); $descTomHigh = str_ireplace(' - ', ' — ', $descTomHigh); $descTomHigh = SmartyPants($descTomHigh); $h3TomLow = html_entity_decode($h3TomLow, ENT_QUOTES); $h3TomLow = str_ireplace(' - ', ' — ', $h3TomLow); $h3TomLow = SmartyPants($h3TomLow); $descTomLow = html_entity_decode($descTomLow, ENT_QUOTES); $descTomLow = str_ireplace(' - ', ' — ', $descTomLow); $descTomLow = SmartyPants($descTomLow); // Assign colors to each condition code $conditionStory = array(); $conditionStory[0] = 'color: #636363; background: transparent;'; $conditionStory[1] = 'color: #5f9399; background: transparent;'; $conditionStory[2] = 'color: #6b80a8; background: transparent;'; $conditionStory[3] = 'color: #929292; background: transparent;'; $conditionStory[4] = 'color: #a4a4a4; background: transparent;'; $conditionStory[5] = 'color: #d7d7d7; background: transparent;'; $conditionStory[6] = 'color: #cdcdcd; background: transparent;'; $conditionStory[7] = 'color: #e4e4e4; background: transparent;'; $conditionStory[8] = 'color: #dcdcdc; background: transparent;'; $conditionStory[9] = 'color: #dadada; background: transparent;'; $conditionStory[10] = 'color: #e7e7e7; background: transparent;'; $conditionStory[11] = 'color: #d5d5d5; background: transparent;'; $conditionStory[12] = 'color: #d5d5d5; background: transparent;'; $conditionStory[13] = 'color: #fff; background: #ccc;'; $conditionStory[14] = 'color: #fff; background: #d8d8d8;'; $conditionStory[15] = 'color: #fff; background: #dcdcdc;'; $conditionStory[16] = 'color: #fff; background: #e5e5e5;'; $conditionStory[17] = 'color: #fff; background: #b0b0b0;'; $conditionStory[18] = 'color: #fff; background: #b8b8b8;'; $conditionStory[19] = 'color: #d5c384; background: transparent;'; $conditionStory[20] = 'color: #e9e9e9; background: transparent;'; $conditionStory[21] = 'color: #ded99d; background: transparent;'; $conditionStory[22] = 'color: #726f55; background: transparent;'; $conditionStory[23] = 'color: #a4e4e7; background: transparent;'; $conditionStory[24] = 'color: #dfdfdf; background: transparent;'; $conditionStory[25] = 'color: #8cdcee; background: transparent;'; $conditionStory[26] = 'color: #e1e1e1; background: transparent;'; $conditionStory[27] = 'color: #d3d3d3; background: #000;'; $conditionStory[28] = 'color: #d3d3d3; background: transparent;'; $conditionStory[29] = 'color: #dedede; background: #000;'; $conditionStory[30] = 'color: #dedede; background: transparent;'; $conditionStory[31] = 'color: #140776; background: transparent;'; $conditionStory[32] = 'color: #f2bc00; background: transparent;'; $conditionStory[33] = 'color: #003770; background: transparent;'; $conditionStory[34] = 'color: #0084d7; background: transparent;'; $conditionStory[35] = 'color: #fff; background: #a6a6a6;'; $conditionStory[36] = 'color: #e10000; background: transparent;'; $conditionStory[37] = 'color: #b1b1b1; background: transparent;'; $conditionStory[38] = 'color: #ababab; background: transparent;'; $conditionStory[39] = 'color: #ababab; background: transparent;'; $conditionStory[40] = 'color: #d4d4d4; background: transparent;'; $conditionStory[41] = 'color: #d5d5d5; background: transparent;'; $conditionStory[42] = 'color: #d5d5d5; background: transparent;'; $conditionStory[43] = 'color: #fff; background: #ececec;'; $conditionStory[44] = 'color: #dedede; background: transparent;'; $conditionStory[45] = 'color: #a4a4a4; background: transparent;'; $conditionStory[46] = 'color: #fff; background: #dfdfdf;'; $conditionStory[47] = 'color: #acacac; background: transparent;'; $conditionStory[48] = 'color: #fff; background: #000;'; $conditionCode = (int) $conditionCode; $forecastCode = (int) $forecastCode; $forecastCodeNext = (int) $forecastCodeNext; //Convert hsv to rgb function hsv2rgb($hsv) { list($h, $s, $v) = $hsv; $h = $h / 360; $s = $s / 100; $v = $v / 100; if($s == 0) { $r = $v * 255; $g = $v * 255; $b = $v * 255; } else { $h = $h * 6; $i = floor($h); $v1 = $v * (1 - $s); $v2 = $v * (1 - $s * ($h - $i)); $v3 = $v * (1 - $s * (1 - ($h - $i))); if($i == 0) { $r = $v; $g = $v3; $b = $v1; } elseif($i == 1) { $r = $v2; $g = $v; $b = $v1; } elseif($i == 2) { $r = $v1; $g = $v; $b = $v3; } elseif($i == 3) { $r = $v1; $g = $v2; $b = $v; } elseif($i == 4) { $r = $v3; $g = $v1; $b = $v; } else { $r = $v; $g = $v1; $b = $v2; } $r = $r * 255; $g = $g * 255; $b = $b * 255; } return(array($r, $g, $b)); } // converts array($r, $g, $b) to "#HTML" function array2html($clr) { return strtoupper("#" . substr("00" . dechex($clr[0]), -2, 2) . substr("00" . dechex($clr[1]), -2, 2) . substr("00" . dechex($clr[2]), -2, 2)); } // converts from the RGB color scheme to HSV color scheme // http://www.easyrgb.com/math.php?MATH=M21#text21 // $hsv = array($hue [0..360], $saturation [0..100], $value [0..100]) // $rgb = array($red [0..255], $green [0..255], $blue [0..255]) // Make white = 0% humidity, black = 100% humidity $humidityInvert = 100 - $humidity; $hsv = array(0, 0, $humidityInvert); $rgb = hsv2rgb($hsv); $hex = array2html($rgb); ?> Talk About the Weather: <?= $city ?>, <?= $region ?>

Breaking News

News Photos of '.$conditionText.' or '.$temperature.'' ?>

'.$photoImgItem[$j].'

'); } } else { echo ('

No photos available.

'); } ?>

Today’s Top Stories

A Look at Tomorrow