Exemplo n.º 1
0
 # time
 $time = gmmktime($hour, $minute, 00, $month, $day, $year);
 $TIME = date($SITE['timeOnlyFormat'], $time);
 # air temp
 if ($ATMP != '-') {
     $temp = wsConvertTemperature($ATMP, $uom_in['temp']);
     $ATMP = wsNumber($temp, $SITE['decTemp']);
 }
 # water temp
 if ($WTMP != '-') {
     $found_wtmp = true;
     $temp = wsConvertTemperature($WTMP, $uom_in['temp']);
     $WTMP = wsNumber($temp, $SITE['decTemp']);
 }
 # wind description based on wind dir in degrees
 $WDSC = getWindDir($WDIR);
 //  180 degr => S
 # wind speed
 $wind = convertWind($WSPD);
 $WSPD = wsNumber($wind, $SITE['decWind']);
 # wind gust
 if ($GST != '-') {
     $found_gust = true;
     $wind = convertWind($GST);
     $GST = wsNumber($wind, $SITE['decWind']);
 }
 # pressure
 if ($PRES != '-') {
     $baro = wsConvertBaro($PRES, $uom_in['baro']);
     $PRES = wsNumber($baro, $SITE['decBaro']);
 }
function makeWeatherSidebar()
{
    global $forecast_api;
    global $weather_lat;
    global $weather_long;
    global $weather_units;
    $wind_speed_units = "mph";
    $forecastExcludes = '?exclude=flags';
    // Take a look at https://developer.forecast.io/docs/v2 to configure your weather information.
    if (strtoupper($weather_units) == "C") {
        $forecastExcludes = "?exclude=flags&units=ca";
        $wind_speed_units = "km/h";
    }
    $currentForecast = json_decode(file_get_contents('https://api.forecast.io/forecast/' . $forecast_api . '/' . $weather_lat . ',' . $weather_long . $forecastExcludes));
    $currentSummary = $currentForecast->currently->summary;
    $currentSummaryIcon = $currentForecast->currently->icon;
    $currentTemp = round($currentForecast->currently->temperature);
    $currentWindSpeed = round($currentForecast->currently->windSpeed);
    if ($currentWindSpeed > 0) {
        $currentWindBearing = $currentForecast->currently->windBearing;
    }
    $minutelySummary = $currentForecast->minutely->summary;
    $hourlySummary = $currentForecast->hourly->summary;
    $sunriseTime = $currentForecast->daily->data[0]->sunriseTime;
    $sunsetTime = $currentForecast->daily->data[0]->sunsetTime;
    if ($sunriseTime > time()) {
        $rises = 'Rises';
    } else {
        $rises = 'Rose';
    }
    if ($sunsetTime > time()) {
        $sets = 'Sets';
    } else {
        $sets = 'Set';
    }
    // If there are alerts, make the alerts variables
    if (isset($currentForecast->alerts)) {
        $alertTitle = $currentForecast->alerts[0]->title;
        $alertExpires = $currentForecast->alerts[0]->expires;
        $alertDescription = $currentForecast->alerts[0]->description;
        $alertUri = $currentForecast->alerts[0]->uri;
    }
    // Make the array for weather icons
    $weatherIcons = ['clear-day' => 'B', 'clear-night' => 'C', 'rain' => 'R', 'snow' => 'W', 'sleet' => 'X', 'wind' => 'F', 'fog' => 'L', 'cloudy' => 'N', 'partly-cloudy-day' => 'H', 'partly-cloudy-night' => 'I'];
    $weatherIcon = $weatherIcons[$currentSummaryIcon];
    // If there is a severe weather warning, display it
    //if (isset($currentForecast->alerts)) {
    //	echo '<div class="alert alert-warning alert-dismissable">';
    //	echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>';
    //	echo '<strong><a href="'.$alertUri.'" class="alert-link">'.$alertTitle.'</a></strong>';
    //	echo '</div>';
    //}
    echo '<ul class="list-inline" style="margin-bottom:-20px">';
    echo '<li><h1 data-icon="' . $weatherIcon . '" style="font-size:500%;margin:0px -10px 20px -5px"></h1></li>';
    echo '<li><ul class="list-unstyled">';
    echo '<li><h1 class="exoregular" style="margin:0px">' . $currentTemp . '°</h1></li>';
    echo '<li><h4 class="exoregular" style="margin:0px;padding-right:10px;width:80px">' . $currentSummary . '</h4></li>';
    echo '</ul></li>';
    echo '</ul>';
    if ($currentWindSpeed > 0) {
        $direction = getWindDir($currentWindBearing);
        echo '<h4 class="exoextralight" style="margin-top:0px">Wind: ' . $currentWindSpeed . ' ' . $wind_speed_units . ' from the ' . $direction . '</h4>';
    } else {
        echo '<h4 class="exoextralight" style="margin-top:0px">Wind: Calm</h4>';
    }
    echo '<h4 class="exoregular">Next Hour</h4>';
    echo '<h5 class="exoextralight" style="margin-top:10px">' . $minutelySummary . '</h5>';
    echo '<h4 class="exoregular">Next 24 Hours</h4>';
    echo '<h5 class="exoextralight" style="margin-top:10px">' . $hourlySummary . '</h5>';
    echo '<h4 class="exoregular">The Sun</h4>';
    echo '<h5 class="exoextralight" style="margin-top:10px">' . $rises . ' at ' . date('g:i A', $sunriseTime) . '</h5>';
    echo '<h5 class="exoextralight" style="margin-top:10px">' . $sets . ' at ' . date('g:i A', $sunsetTime) . '</h5>';
    echo '<p class="text-right no-link-color" style="margin-bottom:-10px"><small><a href="http://forecast.io/#/f/' . $weather_lat . ',' . $weather_long . '">Forecast.io</a></small></p> ';
}
// WD/CU Sample= '2013,01,20,23,39,59'
$JSONdata['BearingRangeFrom10'] = '359';
// CU Sample= '289'
$JSONdata['BearingRangeTo10'] = '0';
// CU Sample= '6'
$JSONdata['UV'] = round($wflash[19], 1);
// CU Sample= '0.7'
$JSONdata['UVTH'] = round($wflash[46], 1);
// CU Sample= '1.7';
$JSONdata['SolarRad'] = round($wflash[20]);
// CU Sample= '267'
$JSONdata['SolarTM'] = round($wflash2[47]);
// CU Sample= '560'
$JSONdata['CurrentSolarMax'] = round($wflash2[47]);
// CU Sample= '438'
$JSONdata['domwinddir'] = getWindDir($wflash2[3]);
// WD Sample= 'Northwesterly', CU Sample= 'NW'
$JSONdata['WindRoseData'] = '[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]';
// Note: VWS does not collect/publish this windrose data
// a WD Sample='[22.0,23.0,7.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,3.0,233.0,139.0]'
$JSONdata['windrun'] = convertWind($wflash2[258], $uomWindRun);
// new in ver=9
$JSONdata['cloudbase'] = round($wflash[27], 0);
// CU Sample= '1783', new in ver 11
$JSONdata['cloudbaseunit'] = $uomCloudBase;
// CU Sample= 'ft', new in ver 11
$JSONdata['version'] = substr($wflash2[283], 1);
// WD Sample= '10.37R'
$JSONdata['build'] = ' n/a';
// WD Sample= '45'
$JSONdata['ver'] = '11';