<?php
// phpblock_lunar
function phpblock_lunar($deflang="en") {
global 
$root ;
/************************************************************************/
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/* please credit me, it's my only block                                 */
/* Copyright Robert J. Sori, Las Vegas Nevada                           */
/************************************************************************/

//if (eregi("block-Lunar.php",$PHP_SELF)) {
//    Header("Location: index.php");
//    die();
//}


$lat 51.29;
$long = -0.0;
$tz = -0;
$loc ="Las Vegas, Nevada";


   
$a gmdate('D');                //day of the week
   
$b gmdate('M');               //Month of the Year
   
$c gmdate('j');              //day of the month
   
$d gmdate('Y');             //year
   
$e gmdate('z');            //day of the year
   
$f gmdate('I');           //daylight savings
   
$g gmdate('n');        // month number
   
$h gmdate('H');   //24hr hr's
   
$i gmdate('i');  //minutes
   
$j gmdate('s'); //seconds
   
$k date('O');           //GMT offset
   
$l 29.530588;    //  astronomical constant
   
$m 27.55454988;    // astronomical constant
   
$n 27.212220817;  // astronomical constant
   
$o 27.321660// astronomical constant
   
$p = (2*3.14159);        //2 Pie's
   
$q 3600//cache time delay in seconds, 3600=one hour


//formula for Julian Date

$jd 367*$d-intval(7*($d+intval(($g+9)/12))/4)
      - 
intval(3*(intval(($d+$g-9/7)/100)+1)/4)
      + 
intval(275*$g/9) + $c 1721028.5 + ($h/24)+($i/1440) +($j/84600);



//formula for Illumination of Moon

$v = ($jd-2452642.34931)/$l;               //recent new moon
$v $v-intval($v);
while (
$v<=0)
{
$v=($v+1);
}
$ip $v;
$vv $v;
$ag = ($ip*$l);
$ip = ($ip*$p);
$age =round($ag5);

//formula for distance of Moon
// anomalistic month 27.5545
$v=($jd-2452663.44722)/$m;      //recent perigee
$v $v-(intval($v));

while (
$v<=0)
{
$v=($v+1);
}
$dp $v;
$dp = ($dp*$p);
$di 60.4-3.3*cos($dp)-.6*cos(2*$ip-$dp)-.5*cos(2*$ip);
$er intval($di*6378);;
$ri round($di3);

//formula for latitude of Moon
// draconic month    27.2122

$v=($jd-2452649.37326)/$n;     //recent node at 0 lat
$v $v-(intval($v));
while (
$v<=0)
{
$v=($v+1);
}
$np $v;

$np $np*$p;
$la 5.1*sin($np);
$ladisplay round($la5);

//formula for longitude of Moon
// tropical month  27.3215
//measured by determining when the moon is again at a maximum (or minimum) azimuth position

$v=($jd-2452648.22049)/$o;  //recent  node at 0 long
$v $v-(intval($v));
while (
$v<=0)
{
$v=($v+1);
}
$rp $v;
$lo = (360*$rp)+(6.3*sin($dp))+(1.3*sin(2*$ip-$dp))+(.7*sin(2*$ip));
$longdisplay=round($lo5);

$angle_deg intval($ag*360/$l)  ;
if ((
$angle_deg%2)!=0$angle_deg++ ;
$angle_deg "m".str_pad($angle_deg3"0"STR_PAD_LEFT) ;

if (
$ag>.5){
$phase="Baby Moon";
//$daily="$root/images/lunar/new.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>1){
$phase="Thin Crescent";
//$daily="$root/images/lunar/tcx.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>2){
$phase="Crescent";
//$daily="$root/images/lunar/cx.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>3){
$phase="Waxing";
//$daily="$root/images/lunar/wx1.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>4){
$phase="Waxing";
//$daily="$root/images/lunar/wx2.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>5){
$phase="Waxing";
//$daily="$root/images/lunar/wx3.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>6){
$phase="Waxing";
//$daily="$root/images/lunar/wx4.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>7){
$phase="First Quarter";
//$daily="$root/images/lunar/fq.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>8){
$phase="Waxing Gibbous";
//$daily="$root/images/lunar/wx5.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>9){
$phase="Waxing Gibbous";
//$daily="$root/images/lunar/wx5.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>10){
$phase="Waxing Gibbous";
//$daily="$root/images/lunar/wx7.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>11){
$phase="Waxing Gibbous";
//$daily="$root/images/lunar/wx8.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}


if (
$ag>12){
$phase="Waxing Gibbous";
//$daily="$root/images/lunar/wx9.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>13){
$phase="Waxing Gibbous";
//$daily="$root/images/lunar/wx10.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>14){
$phase="Full Moon";
//$daily="$root/images/lunar/full.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>15){
$phase="Past Full";
//$daily="$root/images/lunar/wn1.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>16){
$phase="Waning Gibbous";
//$daily="$root/images/lunar/wn2.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>17){
$phase="Waning Gibbous";
//$daily="$root/images/lunar/wn3.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>18){
$phase="Waning Gibbous";
//$daily="$root/images/lunar/wn4.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>19){
$phase="Waning Gibbous";
//$daily="$root/images/lunar/wn5.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>20){
$phase="Waning Gibbous";
//$daily="$root/images/lunar/wn5.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>21){
$phase="Last Quarter";
//$daily="$root/images/lunar/lq.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>22){
$phase="Waning";
//$daily="$root/images/lunar/wn7.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>23){
$phase="Waning";
//$daily="$root/images/lunar/wn8.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>24){
$phase="Waning";
//$daily="$root/images/lunar/wn9.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>25.5){
$phase="Waning";
//$daily="$root/images/lunar/wn10.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>27){
$phase="Crescent";
//$daily="$root/images/lunar/cn.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if (
$ag>28){
$phase="Thin Crescent";
//$daily="$root/images/lunar/tcn.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

if ((
$ag>29.5) || ($ag<=0.5)){
$phase="New Moon";
//$daily="$root/images/lunar/new.jpg";
$daily="$root/images/lunar/$angle_deg.gif";
}

#next new moon / first quarter / full moon / last quarter
$nnm $l-$ag ;
$nfq $nnm $l/;
$nfm $nnm $l/;
$nlq $nfm $l/;

$nnm date("d/m/Y"date("U") + $nnm*24*60*60);
$nfq date("d/m/Y"date("U") + $nfq*24*60*60);
$nfm date("d/m/Y"date("U") + $nfm*24*60*60);
$nlq date("d/m/Y"date("U") + $nlq*24*60*60);

$content =  "<p style='background-color:black;text-align:center;font-size:1.1em;font-weight:bolder;color:white;'><a href=\"$daily\" target=\"_blank\">";
$content .=  "<img src=\"$daily\" width=\"100\" height=\"100\" alt=\"Click Image\" border=\"0\" /></a>";
$content .=  "<br /> * $phase * </p>\n";
$content .=  "<p style='text-align:center;'>Age since New <tt>$age</tt><br />\n";
$content .=  "<tt>GMT $h:$i:$j</tt><br />\n";
$content .=  "JDate <tt>$jd</tt><br />\n";
$content .=  "Distance in Radii <tt>$ri</tt><br />\n";
$content .=  "$er km at Equator<br />\n";
$content .=  "Longitude   : <tt>$longdisplay</tt> <br />\n";
$content .=  "R Ascension : <tt>$ladisplay</tt><br />\n";

$content .= "<table>
<tr>
<th colspan=\"2\"><span style='text-align:center;font-size:0.9em;font-weight:bold'>next phases</span></th>
</tr>
<tr>
<td><img src=\"$root/images/lunar/nl.gif\" alt=\"next new moon\" />
<span style='font-size:6pt;'>$nnm</span></td>
<td><img src=\"$root/images/lunar/dq.gif\" alt=\"next last quarter\" />
<span style='font-size:6pt;'>$nlq</span></td>
</tr>
<tr>
<td><img src=\"$root/images/lunar/pq.gif\" alt=\"next first quarter\" />
<span style='font-size:6pt;'>$nfq</span></td>
<td><img src=\"$root/images/lunar/pl.gif\" alt=\"next full moon\" />
<span style='font-size:6pt;'>$nfm</span></td>
</tr>
</table>" 
;

$content .= "</p>" ;

return 
$content ;
}

// phpblock_solar : ephemerids
function phpblock_solar($deflang="en") {
global 
$root ;
/************************************************************************/
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/* compiled from PD sources and snippets on the web                     */
/* Robert J. Sori, Las Vegas Nevada     robert@lvoncall.com             */
/************************************************************************/


//Sunrise Sunset Computation
// PHP code mattf@mail.com - please use this code in any way you wish
// and if you want to, let me know how you are using it.

// This is where you change the variables for your site, I left my originals for reference
// don't delete these, or if you mess up, you won't know the structure to use
// $latitude = 36.08036;
// $longitude = -115.1523333;
// $timezone = -8;
// Robert Sori, Las Vegas NV

// SHA SHANGHAI, CHINA   31 06 N        121 22 E 
// PAR PARIS, FRANCE         48 52 N        2 20 E
// CDG CHARLES DE GAULLE 48 50.23 N 2 20.23 E

//$latitude = 36.2;
//$longitude = -115.2;
//$timezone = -8;
//$location ="Las Vegas, Nevada";

$latitude 48.52;
$longitude 2.2;
$timezone date("I"); // for French summer time;
$location ="Paris, France";


   
$yday gmdate('z');
   
$mon gmdate('n');
   
$mday gmdate('j');
   
$year gmdate('Y');
   
$mes gmdate('F');
   
$dia gmdate('D');
   
$cosa date('O');

   
$A 1.5708;
   
$B 3.14159;
   
$C 4.71239;
   
$D 6.28319;
   
$E 0.0174533 $latitude;
   
$F 0.0174533 $longitude;
   
$G 0.261799  $timezone;
   
$q 3600//cache time delay in seconds, 3600=one minute

//For astronomical twilight, use R = -.309017
//For     nautical twilight, use R = -.207912
//For        civil twilight, use R = -.104528
//For     sunrise or sunset, use R = -.0145439
$R '-.0145439';

$J =$A ;
$type "rise" ;

$K $yday + (($J $F) / $D);
$L = ($K .017202) - .0574039;
$M $L .0334405 sin($L);
$M += 4.93289 + (3.49066E-04) * sin($L);
  
# Quadrant Determination
     
if ($D == 0) {echo "Trying to normalize with zero offset..."; exit;}
     while (
$M 0)   {$M = ($M $D);}
     while (
$M >= $D) {$M = ($M $D);}

   if ((
$M $A) - intval($M $A) == 0) {$M += 4.84814E-06;}
   
$P sin($M) / cos($M);
   
$P atan2(.91746 $P1);

   
# Quadrant Adjustment
   
if ($M $C) {$P += $D;}
   else {if (
$M $A) {$P += $B;} }

   
$Q .39782 sin($M);
   
$Q $Q sqrt(-$Q $Q 1);    # This is how the original author wrote it!
   
$Q atan2($Q1);

   
$S $R - (sin($Q) * sin($E));
   
$S $S / (cos($Q) * cos($E));

   if (
abs($S) > 1) {echo 'none';}

   
$S $S sqrt(-$S $S 1);
   
$S $A atan2($S1);

   if (
$type == 'rise') {$S $D $S ;}

   
$T $S $P 0.0172028 $K 1.73364;
   
$U $T $F;
   
$V $U $G;

     if (
$D == 0) {echo "Trying to normalize with zero offset..."; exit;}
     while (
$V 0)   {$V = ($V $D);}
     while (
$V >= $D) {$V = ($V $D);}
   
$V $V 3.81972;

   
$hour intval($V);
   
$min  intval((($V $hour) * 60) + 0.5);


$display1 date"g:i A"mktime($hour,$min,0,$mon,$mday,$year) );

$J =$C ;
$type "set" ;


   
$K $yday + (($J $F) / $D);
   
$L = ($K .017202) - .0574039;
   
$M $L .0334405 sin($L);
   
$M += 4.93289 + (3.49066E-04) * sin($L);
  
# Quadrant Determination
     
if ($D == 0) {echo "Trying to normalize with zero offset..."; exit;}
     while (
$M 0)   {$M = ($M $D);}
     while (
$M >= $D) {$M = ($M $D);}

   if ((
$M $A) - intval($M $A) == 0) {$M += 4.84814E-06;}
   
$P sin($M) / cos($M);
   
$P atan2(.91746 $P1);

   
# Quadrant Adjustment
   
if ($M $C) {$P += $D;}
   else {if (
$M $A) {$P += $B;} }

   
$Q .39782 sin($M);
   
$Q $Q sqrt(-$Q $Q 1);    # This is how the original author wrote it!
   
$Q atan2($Q1);

   
$S $R - (sin($Q) * sin($E));
   
$S $S / (cos($Q) * cos($E));

   if (
abs($S) > 1) {echo 'none';}

   
$S $S sqrt(-$S $S 1);
   
$S $A atan2($S1);

   if (
$type == 'rise') {$S $D $S ;}

   
$T $S $P 0.0172028 $K 1.73364;
   
$U $T $F;
   
$V $U $G;

     if (
$D == 0) {echo "Trying to normalize with zero offset..."; exit;}
     while (
$V 0)   {$V = ($V $D);}
     while (
$V >= $D) {$V = ($V $D);}
   
$V $V 3.81972;

   
$hour intval($V);
   
$min  intval((($V $hour) * 60) + 0.5);

   
$display2 date"g:i A"mktime($hour,$min,0,$mon,$mday,$year) );

$filesize filesize("./images/solar/solar.gif");
$lastvisit filemtime("./images/solar/solar.gif");
$currenttime getdate(time());
$currentdate $currenttime["0"];
$difference $currentdate $lastvisit;
$diff $q-$difference;
$hrs intval($diff/3600);
$min intval(($diff-($hrs*3600))/60);

$content "<p style='text-align:center;'>";
$content .= "<a href=\"http://umbra.nascom.nasa.gov/images/\" target=\"_blank\">$dia $mes-$mday-$year</a><br />";
$content .= "$location<br />";
$content .= "<a href=\"http://umbra.nascom.nasa.gov/eit/images/latest_eit_304.gif\" target=\"_blank\">";
$content .= "<img src=\"$root/images/solar/solar.gif\" border=\"0\"
width=\"100\" height=\"100\" alt=\"Click Image\" /></a><br />"
;
$content .= "Latitude <tt>N $latitude</tt><br />";
$content .= "Longitude <tt>E $longitude</tt><br />";
$content .= "Sunrise @ <tt>$display1</tt><br />";
$content .= "Sunset  @ <tt>$display2</tt><br />";
$content .= "</p>" ;

if ( (
$difference $q) AND ($filesize != 0) )
{ }
elseif ( (
$difference $q) OR ($filesize == 0) )

#http://umbra.nascom.nasa.gov/images/latest_eit_171.gif
#http://umbra.nascom.nasa.gov/images/latest_eit_195.gif
#http://umbra.nascom.nasa.gov/images/latest_eit_284.gif
#http://umbra.nascom.nasa.gov/images/latest_eit_304.gif
#http://beauty.nascom.nasa.gov/~gurman/images/sxi/images/latest_sxi_pmeda.gif
#http://umbra.nascom.nasa.gov/images/latest_nsoMG.gif
#http://umbra.nascom.nasa.gov/images/latest_nsoHe.gif
#http://umbra.nascom.nasa.gov/images/latest_nsoCh.gif
#http://umbra.nascom.nasa.gov/images/latest_K_line.gif
#http://umbra.nascom.nasa.gov/images/latest_mk4.gif
#http://umbra.nascom.nasa.gov/images/latest_mdi_igram.gif

{
$fc fopen("./images/solar/solar.gif""wb");
$file fopen ("http://umbra.nascom.nasa.gov/eit/images/latest_eit_171_thumbnail.gif""rb");


                    if (!
$file) {
                       
$info "E";
                       exit;
                    }
                    else
                    {
                    while (!
feof ($file)) {
                       
$line fread ($file4096);
                           
fwrite($fc,$line);
                       }


                    }
                    
fclose($fc);
                    
fclose($file);


                    
$info "F"; }


return 
$content ;

}


?>