'hebcal-shabbat',
'description' => 'displays various zmanim (times) for a USA zip code or world city');
/* Widget control settings. */
$control_ops = array('width' => 200,
'height' => 200,
'id_base' => 'hebcal-shabbat-widget');
/* Create the widget. */
$this->WP_Widget('hebcal-shabbat-widget', 'AdatoSystems Zmanim', $widget_ops, $control_ops);
}
/**
* How to display the widget on the screen.
*/
function widget($args, $instance) {
extract($args);
/* Our variables from the widget settings. */
$title = apply_filters('widget_title', $instance['title']);
$ashkenazis_checked = isset($instance['a']) ? $instance['a'] : false;
$ashkenazis = $ashkenazis_checked ? 'on' : 'off';
/* LEONLEON New calculations here */
/* What day is Friday? */
if(date('N')!=6) {
$friday = strtotime( "next friday" );
$friday_txt = date("m-d-Y", $friday );
$saturday_txt = date("Y-m-d", $saturday);
} else {
$friday = strtotime("now");
$friday_txt = date("m-d-Y");
$saturday_txt = date("Y-m-d", $saturday);
}
if(date('N')!=7) {
$saturday = strtotime( "next saturday" );
$saturday_txt = date("Y-m-d", $saturday);
} else {
$saturday = strtotime("now");
$saturday_txt = date("Y-m-d", $saturday);
}
// 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"; }
$hebcal = file_get_contents("https://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']);
$hebcaljd = json_decode($hebcal,true);
foreach($hebcaljd['items'] as $hebstat => $hebitem) {
foreach($hebitem as $stat=>$value) {
if($hebitem['category'] == "parashat") {
if($hebitem['date'] == $saturday_txt) {
$parshaname = $hebitem['title'];
if($instance['ptext'] == "sh" || $instance['ptext'] == "ah") {$parshaname = $parshaname." / ".$hebitem['hebrew']; }
}
}
}
}
/* JSON get lat/long from zip using maps.googleapis.com */
$du = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".$instance['zip']."&sensor=false");
$djd = json_decode(utf8_encode($du),true);
$long = $djd['results'][0]['geometry']['location']['lng'];
$lat = $djd['results'][0]['geometry']['location']['lat'];
$address = $djd['results'][0]['formatted_address'];
/* Get time offset for timzezone and DST using maps.googleapis.com */
$tz = file_get_contents("https://maps.googleapis.com/maps/api/timezone/json?location=".$lat.",".$long."×tamp=".$friday."&sensor=false");
$tzjd = json_decode(utf8_encode($tz),true);
$tzoffset = $tzjd['rawOffset'];
$dstoffset = $tzjd['dstOffset'];
$offset = $dstoffset+$tzoffset;
$tzname = $tzjd['timeZoneName'];
/* now calculate sunrise and suset time */
$suninfo = date_sun_info($friday, $lat, $long);
/* to see all the variables, use this:
foreach ($suninfo as $key=>$val)
{
$out = $out."$key: " . date("H:i:s",$val) . "
";
} */
$sunrise = date("h:i:s A", $suninfo['sunrise']+$offset);
$sunset = date("h:i:s A", $suninfo['sunset']+$offset);
echo $before_widget;
echo $before_title, $title, $after_title;
// Calculate Candles & havdalah
if($instance['ctime']=="cminutes") { $candletime = date("h:i:s A", strtotime($sunset) - ($instance['cmin'] * 60 ) ); }
if($instance['ctime']=="cfixed") { $candletime = date("h:i A", strtotime($instance['cfixed']) ); }
if($instance['showhavdalah']) {$havdalahtime = date("h:i A", strtotime($sunset) + ($instance['m'] * 60) ); }
echo "Shabbat Times for ".$friday_txt."
";
if( $instance['showparsha'] ) {echo $parshaname."
"; }
if( $instance['debug'] ) { echo "timestamp: ".$friday." and friday_db is ".$friday_db."
"; }
if( $instance['showparsha'] ) {echo "Location: ".$address."
"; }
if( $instance['debug'] ) { echo "Lat and Long is: ".$lat." and ".$long."
"; }
if( $instance['debug'] ) { echo "Time zone is ".$tzname.", tzoffset is ".$tzoffset.", dstoffset is ".$dstoffset." and offset is ".$offset."
"; }
if( $instance['debug'] ) { echo "saturday is ".$saturday_txt."
"; }
if( $instance['debug'] ) { echo $hebcaljd['link']."
"; }
if( $instance['showcandles'] ) {echo "Candle Lighting Time: ".$candletime."
"; }
if( $instance['showhavdalah'] ) {echo "Havdalah (".$instance['m']." min): ".$havdalahtime."
"; }
if( $instance['showsunrise'] ) {echo "Sunrise: ".$sunrise."
";}
if( $instance['showsunset'] ) {echo "Sunset: ".$sunset."
";}
echo $after_widget;
}
/**
* Update the widget settings.
*/
function update($new_instance, $old_instance) {
$instance = $old_instance;
/* Strip tags for title and name to remove HTML (important for text inputs). */
$instance['title'] = strip_tags($new_instance['title']);
$instance['zip'] = strip_tags($new_instance['zip']);
$instance['showlocation'] = $new_instance['showlocation'];
$instance['showcandles'] = $new_instance['showcandles'];
$instance['showparsha'] = $new_instance['showparsha'];
$instance['showhavdalah'] = $new_instance['showhavdalah'];
$instance['showsunrise'] = $new_instance['showsunrise'];
$instance['showsunset'] = $new_instance['showsunset'];
$instance['showplag'] = $new_instance['showplag'];
$instance['m'] = $new_instance['m'];
$instance['cmin'] = $new_instance['cmin'];
$instance['ctime'] = $new_instance['ctime'];
$instance['cfixed'] = $new_instance['cfixed'];
$instance['ptext'] = $new_instance['ptext'];
$instance['inisrael'] = $new_instance['inisrael'];
$instance['plagmethod'] = $new_instance['plagmethod'];
$instance['debug'] = $new_instance['debug'];
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form($instance) {
/* Set up some default widget settings. */
$defaults = array('zip' => '90210', 'm' => '72', 'cmin' => '18');
$instance = wp_parse_args((array) $instance, $defaults); ?>
General Display Choices:
id="get_field_id('showlocation'); ?>" name="get_field_name('showlocation'); ?>" />
id="get_field_id('showsunrise'); ?>" name="get_field_name('showsunrise'); ?>" />
id="get_field_id('showsunset'); ?>" name="get_field_name('showsunset'); ?>" />
Candlelighting & Havdalah Choices:
id="get_field_id('showcandles'); ?>" name="get_field_name('showcandles'); ?>" />
name="get_field_name('ctime'); ?>" value="cminutes" />Minutes before Sunset
name="get_field_name('ctime'); ?>" value="cfixed" />Specific Time
id="get_field_id('showhavdalah'); ?>" name="get_field_name('showhavdalah'); ?>" />
Torah Portion Display Options
id="get_field_id('showparsha'); ?>" name="get_field_name('showparsha'); ?>" />
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
id="get_field_id('inisrael'); ?>" name="get_field_name('inisrael'); ?>" />
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 (sunrise to sunset)
name="get_field_name('plagmethod'); ?>" value="avr">use Magen Avraham (daybreak to nightfall)
id="get_field_id('debug'); ?>" name="get_field_name('debug'); ?>" />