.
* For details about this program, see the readme file.
*/
class AdatoSystems_Zman_Widget extends WP_Widget {
/**
* Widget setup.
*/
function AdatoSystems_Zman_Widget() {
/* Widget settings. */
$widget_ops = array('classname' => 'frizman-shabbat',
'description' => 'displays various Shabbat zmanim (times) for a USA zip code or world city');
/* Widget control settings. */
$control_ops = array('width' => 200,
'height' => 200,
'id_base' => 'frizman-shabbat-widget');
/* Create the widget. */
$this->WP_Widget('frizman-shabbat-widget', 'Shabbat Zmanim', $widget_ops, $control_ops);
} //end function AdatoSystems_Zman_Widget
function widget($args, $instance) {
extract($args);
/* Our variables from the widget settings. */
date_default_timezone_set('UTC');
$title = apply_filters('widget_title', $instance['title']);
// Show the love
$lovetext = "
Developed by AdatoSystems.com.
Key features by Hebcal.com.";
// Set time display (seconds or no seconds)
if($instance['showseconds']) { $timedisplay = "g:i:s A"; } else { $timedisplay = "g:i A"; }
// Set transliteration style
if($instance['ashki']) {
$titleshabbat = 'Shabbos';
$titlehavdalah = 'Havdolo';
} else {
$titleshabbat = 'Shabbat';
$titlehavdalah = 'Havdalah';
} //end transliteration style
/* What day is Friday */
if(date('N')==5 || date("N")==6) {
$friday = strtotime("now");
$friday_txt = date("M d, Y", $friday);
$friday_ymd = date("Y-m-d", $friday);
} else {
$friday = strtotime( "next friday" );
if(!$friday) {
$daysdiff = 5-now("N");
$friday = date('Y-m-d', strtotime(now(), " + ".$daysdiff." day"));
$friday_ymd = date("Y-m-d", $friday);
}
$friday_txt = date("M d, Y", $friday );
$friday_ymd = date("Y-m-d", $friday);
} //end get Friday
if(date('N')!=6) {
$saturday = strtotime( "next saturday" );
if(!$saturday) {
$daysdiff = 6-now("N");
$saturday = date('Y-m-d', strtotime(now(), " + ".$daysdiff." day"));
}
$saturday_txt = date("Y-m-d", $saturday);
} else {
$saturday = strtotime("now");
$saturday_txt = date("Y-m-d", $saturday);
} //end what day is saturday
/* JSON get lat/long from zip using geocoder.us */
if(!$instance['userlat']) {
$latlongurl = "http://api.geonames.org/postalCodeLookupJSON?formatted=true&postalcode=".$instance['zip']."&country=US&date=".$friday."&username=adatosystems&style=full";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $latlongurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$du = curl_exec($ch);
curl_close($ch);
$djd = json_decode(utf8_encode($du),true);
$long = $djd['postalcodes'][0]['lng'];
$lat = $djd['postalcodes'][0]['lat'];
$city = $djd['postalcodes'][0]['placeName'];
$state = $djd['postalcodes'][0]['adminCode1'];
$country = $djd['postalcodes'][0]['countryCode'];
$address = "$city, $state $country";
} else {
$lat = $instance['userlat'];
$long = $instance['userlong'];
$latlongurl = "http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&lat=".$lat."&lon=".$long;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $latlongurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$du = curl_exec($ch);
curl_close($ch);
$djd = json_decode(utf8_encode($du),true);
$city = $djd['address']['city'];
$state = $djd['address']['state'];
$country = $djd['address']['country_code'];
$address = "$city, $state $country";
}
/* Get time offset for timzezone and DST */
$tzurl = "http://api.geonames.org/timezoneJSON?lat=".$lat."&lng=".$long."&date=".$friday_ymd."&username=adatosystems";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tzurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tz = curl_exec($ch);
curl_close($ch);
$tzjd = json_decode(utf8_encode($tz),true);
$tzname = $tzjd['timezoneId'];
$frisunrise = $tzjd['dates'][0]['sunrise'];
$frisunset = $tzjd['dates'][0]['sunset'];
//***Gives "2013-11-22 17:01". Now convert to date, and set the text to something readable
$frisunrisedatetime = strtotime($frisunrise);
$frisunsetdatetime = strtotime($frisunset);
$saturl = "http://api.geonames.org/timezoneJSON?lat=".$lat."&lng=".$long."&date=".$saturday_txt."&username=adatosystems";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tzurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tz = curl_exec($ch);
curl_close($ch);
$tzjd = json_decode(utf8_encode($tz),true);
$tzname = $tzjd['timezoneId'];
$satsunrise = $tzjd['dates'][0]['sunrise'];
$satsunset = $tzjd['dates'][0]['sunset'];
$satsunrisedatetime = strtotime($satsunrise);
$satsunsetdatetime = strtotime($satsunset);
// Get Hebrew Date from HebCal
// more info: http://www.hebcal.com/home/219/hebrew-date-converter-rest-api
if($instance['hebdatetxt']) {
$hebdateurl = "http://www.hebcal.com/converter/?cfg=json&gy=".date("Y",$friday)."&gm=".date("n",$friday)."&gd=".date("j",$friday)."&g2h=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $hebdateurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$hebdate = curl_exec($ch);
curl_close($ch);
//$hebdate = file_get_contents("http://www.hebcal.com/converter/?cfg=json&gy=".date("Y",$friday)."&gm=".date("n",$friday)."&gd=".date("j",$friday)."&g2h=1");
$hebdatejd = json_decode($hebdate,true);
$hebengdate = $hebdatejd['hd']." ".$hebdatejd['hm'].", ".$hebdatejd['hy'];
$hebhebdate = $hebdatejd['hebrew'];
if($instance['hebdatetxt'] == "e") {$hebrewdate = $hebengdate; }
if($instance['hebdatetxt'] == "h") {$hebrewdate = $hebhebdate; }
if($instance['hebdatetxt'] == "b") {$hebrewdate = $hebengdate."
".$hebhebdate; }
} //end get Hebcal date
// Use the HebCal JSON for the hebrew elements (parsha hashavua, etc.)
// information here: http://www.hebcal.com/home/195/jewish-calendar-rest-api
if($instance['inisrael']) { $inisrael = "i=on"; } else { $inisrael = "i=off"; }
$hebcalurl = "http://www.hebcal.com/hebcal/?v=1&cfg=json&nh=off&nx=off&year=now&month=x&ss=off&mf=off&c=off&s=on&".$inisrael."&lg=".$instance['ptext'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $hebcalurl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$hebcal = curl_exec($ch);
if($instance['debug'] ) {
echo "
Or provide the latitude/Longitude
General Display Choices:
id="get_field_id('ashki'); ?>" name="get_field_name('ashki'); ?>" />
id="get_field_id('showlocation'); ?>" name="get_field_name('showlocation'); ?>" />
id="get_field_id('showseconds'); ?>" name="get_field_name('showseconds'); ?>" />
id="get_field_id('showsunrise'); ?>" name="get_field_name('showsunrise'); ?>" />
id="get_field_id('showfrisunset'); ?>" name="get_field_name('showfrisunset'); ?>" />
id="get_field_id('showsatsunset'); ?>" name="get_field_name('showsatsunset'); ?>" />
Hebrew Date Display:
name="get_field_name('hebdatetxt'); ?>" value="n">Do not show Hebrew date
name="get_field_name('hebdatetxt'); ?>" value="e">Show Hebrew date in English
name="get_field_name('hebdatetxt'); ?>" value="h">Show Hebrew date in Hebrew
name="get_field_name('hebdatetxt'); ?>" value="b">Show Hebrew date in both
Candlelighting & Havdalah Choices:
id="get_field_id('showcandles'); ?>" name="get_field_name('showcandles'); ?>" />
id="get_field_id('showhavdalah'); ?>" name="get_field_name('showhavdalah'); ?>" />
Torah Portion Display Options
id="get_field_id('showparsha'); ?>" name="get_field_name('showparsha'); ?>" />
id="get_field_id('inisrael'); ?>" name="get_field_name('inisrael'); ?>" />
Display using:
name="get_field_name('ptext'); ?>" value="s">Sephardic Transliterations
name="get_field_name('ptext'); ?>" value="sh">Sephardic Transliterations + Hebrew
name="get_field_name('ptext'); ?>" value="a">Ashkenazic Transliterations
name="get_field_name('ptext'); ?>" value="ah">Ashkenazic Transliterations + Hebrew
Plag haMincha Options:
id="get_field_id('showplag'); ?>" name="get_field_name('showplag'); ?>" />
Calculate using:
name="get_field_name('plagmethod'); ?>" value="gra">use GR''A
name="get_field_name('plagmethod'); ?>" value="avr">use Magen Avraham
Shema Options:
id="get_field_id('showshema'); ?>" name="get_field_name('showshema'); ?>" />
Calculate using:
name="get_field_name('shemamethod'); ?>" value="gra">use GR''A
name="get_field_name('shemamethod'); ?>" value="avr">use Magen Avraham
id="get_field_id('debug'); ?>" name="get_field_name('debug'); ?>" />
id="get_field_id('love'); ?>" name="get_field_name('love'); ?>" />
If you REALLY like this widget, cash never hurts. Any amount is welcome.