< back to main page

>see the POWERPOINT

>see the FINISHED SITE

Project 2 Code
Amateur Astronomer* Widget using 2+ data sources   

Main Code

<?php
if(isset($_GET['zip'])) {
$zipcode = $_GET['zip'];
} else {
$zipcode = "30341";
}
$surl = "http://xml.weather.yahoo.com/forecastrss?p=" . $zipcode;
$c = curl_init($surl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$yxml = curl_exec($c);
curl_close($c);
$dom = domxml_open_mem($yxml);
$droot = $dom->document_element();
$dtitle = $droot->get_elements_by_tagname("title");
$cityname = preg_replace("|Yahoo! Weather - |", "", $dtitle[0]->get_content());
$dlat = $droot->get_elements_by_tagname("lat");
$dlon = $droot->get_elements_by_tagname("long");
$ourlat = $dlat[0]->get_content();
$ourlon = $dlon[0]->get_content();
$dconditions = $droot->get_elements_by_tagname("condition");
$ourcondition = $dconditions[0]->get_attribute("text");
$dtemp = $droot->get_elements_by_tagname("condition");
$ourtemp = $dtemp[0]->get_attribute("temp");
?>
<html>
<head>
<title>
Amateur Astronomer
for <?php echo $cityname; ?>
</title>
<script language="JavaScript">
function newimg(img) {
document.images[1].src = "imagefixsat.php?url=" + escape(img);
}
</script>
<style>
#container {
width: 800px;
color: #fff;
background-color: #000;

}
.sattable {
color: #Ff6;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
margin-left: auto;
margin-right: auto;
}
.sattable th {
color: #f36;
font-weight: bold;
text-align: center;
}
.sattable td {
padding: 5px;
}
.moondata {
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
margin-left: auto;
margin-right: auto;
}
.titletext {
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
text-align: center;
font-size: 24px;
margin-right: 200px;
}
.submittext {
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
margin-left: auto;
margin-right: auto;
font-size: 13px;
}
.skychart {
color: #fff;
font-family: Arial, Helvetica, sans-serif;

font-weight: normal;
margin-left: auto;
margin-right: auto;
}

</style>
</head>
<body link="#2FD3D4">
<div id="container">
<table width="800px">
<tr style="width:800px">
<td class="moondata" style="padding-left: .5em;">
<?php
$surl = "http://feeds.almanac.com/almanac-moon";
$c = curl_init($surl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$yxml = curl_exec($c);
curl_close($c);
$dom = domxml_open_mem($yxml);
$droot = $dom->document_element();
$ddescription = $droot->get_elements_by_tagname("description");
$ourmoon = preg_replace("|&.+;|isU", "", $ddescription[1]->get_content());
echo preg_replace("|>.+$|isU","><p style=\"margin-bottom: 0;\">", $ourmoon);
echo $ourcondition ."</p><p style=\"margin-top: 0;\">";
echo $ourtemp. "&#176; Fahrenheit". "</p>";

?>
</td>
<td class="titletext">
Amateur Astronomer
for <?php echo $cityname?>
</td>
<td class="submittext">
<form method="get" action="">
<input type="text" name="zip" value="<?php echo $_GET['zip']; ?>" style="background-color:#f36; colo$
width:50px; font-family:"helvitica"; border: 1px solid #999; text-align: right; tabindex="1""> &nbsp$
<p>
<input type="submit" value="Change Location"
style="background-color:#F5F682; font-weight:bold; tabindex="2"">
</p>
</form>
</td>
</tr>


<tr class="skychart">
<td colspan="3" align="center">
<?php
$surl = "http://heavens-above.com/skychart.asp?lat=" . $ourlat . "&lng=" . $ourlon .$
$c = curl_init($surl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);
preg_match_all("|<img.*>|isU", $page, $tables);
foreach ($tables[0] as $table) {
if (strpos($table, "600")>0) {
$table = preg_replace("|src=\"|isU", "http://www.heavens-above.com/"$
$table = preg_replace("|.*http|isU", "http", $table);
$table = preg_replace("|\".*$|isU", "", $table);
echo "<img src=\"imagefix.php?oldimg=" . urlencode($table) . "\"/>";
}
}
?>
<?php
$surl = "http://heavens-above.com/allsats.asp?lat=" . $ourlat . "&lng=" . $ourlon . $
$c = curl_init($surl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);
preg_match_all("|\"PassDetails.*\"|isU", $page, $tables);
foreach ($tables[0] as $table) {
$table = preg_replace("|^\"|isU", "http://www.heavens-above.com/", $$
$table = preg_replace("|\"$|isU", "", $table);
$sats[] = urlencode($table);
}
?>
</td>
</tr>
</table>
<table class="sattable">
<?php
$surl = "http://heavens-above.com/allsats.asp?lat=" . $ourlat . "&lng=" . $ourlon . "&alt=305&loc=Atlanta&TZ$
$c = curl_init($surl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);
preg_match_all("|<table border cellpadding.*>(.*)</table>|isU", $page, $tables);
foreach ($tables[0] as $table) {
$table = preg_replace("|<[/]*table.*>|isU", "", $table);
preg_match_all("|<tr.*>(.*)</tr>|isU", $table, $trs);
foreach ($trs[0] as $tr) {
$tr = preg_replace("|<[/]*table.*>|isU", "", $tr);
$tr = preg_replace("|<[/]*a.*>|isU", "", $tr);
if (strpos($tr, "Az.")) {
$tr = preg_replace("|<th.*>|isU", "<th style=\"color: #6a6b89\">", $tr);
}
if (!strpos($tr, "/TH")) {
$tr = preg_replace("|</tr>|isU", "<td><a href=\"javascript:newimg('" . array_shift($$
}
echo $tr;
}
}
?>
</table>

</div>
</body>
</html>

PHP Image Manipulation #1 (for whole sky chart) from a separate file

<?php
header("Content-type: image/jpeg");
if (isset($_GET['oldimg'])) {
$ii = urldecode($_GET['oldimg']);
} else {
$ii = "http://www.heavens-above.com/skychart.aspx?lat=33.96&lng=-84.53&alt=305&loc=Atlanta&TZ=EST&Time=53820.7369675926&BW=0&size=60$
}
$image = imagecreatefromgif($ii);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $black);
imagefill($image, 0, 500, $black);
imagefill($image, 599, 500, $black);
imagefill($image, 599, 00, $black);
imagejpeg($image, "", 90);
imagedesstroy($image);
?>

PHP Image Manipuiation #2 (Satellite Chart) from a separate file

<?php
header("Content-type: image/jpg");
$surl = urldecode($_GET['url']);
$c = curl_init($surl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);
preg_match_all("|\"viewfinder.*\"|isU", $page, $sats);
foreach ($sats[0] as $sats) {
$sats = preg_replace("|^\"|isU", "http://www.heavens-above.com/", $sats);
$sats = preg_replace("|\"$|isU", "", $sats);
$sats = preg_replace("|=400|isU", "=600", $sats);
$ii = imagecreatefromgif($sats);
$black = imagecolorallocate($ii, 0,0,0);
imagefill($ii, 0,0,$black);
imagefill($ii, 599,599,$black);
imagefill($ii, 0,599,$black);
imagefill($ii, 599,0,$black);

imagejpeg($ii,"",90);
imagedestroy($ii);
}
?>