Ejemplo n.º 1
0
function forecast_render_element_content()
{
    global $template, $picture, $page, $conf;
    load_language('plugin.lang', FORECAST_PATH);
    if (empty($page['image_id']) and !is_numeric($page['image_id'])) {
        return;
    }
    // Load coordinates and date_creation from picture
    $query = "SELECT latitude,longitude,date FROM forecast WHERE id='" . $page['image_id'] . "';";
    //FIXME LIMIT 1 ?
    $result = pwg_query($query);
    $row = pwg_db_fetch_assoc($result);
    if (!isset($row) or !isset($row['latitude']) or empty($row['latitude']) or !isset($row['longitude']) or empty($row['longitude']) or !isset($row['date']) or empty($row['date'])) {
        return;
    }
    $lat = $row['latitude'];
    $lon = $row['longitude'];
    $date = $row['date'];
    // Load parameter, fallback to default if unset
    $fc_height = isset($conf['forecast_conf']['height']) ? $conf['forecast_conf']['height'] : '200';
    $fc_header = isset($conf['forecast_conf']['link']) ? $conf['forecast_conf']['link'] : 'Overcast';
    $fc_header_css = isset($conf['forecast_conf']['linkcss']) ? $conf['forecast_conf']['linkcss'] : '';
    $fc_show_link = isset($conf['forecast_conf']['show']) ? $conf['forecast_conf']['show'] : 'true';
    $fc_api_key = isset($conf['forecast_conf']['api_key']) ? $conf['forecast_conf']['api_key'] : '';
    if (strlen($fc_header_css) != 0) {
        $fc_css = "style='" . $fc_header_css . "'";
    }
    $fc_link = "http://forecast.io/#/f/" . $lat . "," . $lon;
    //  Init Forecast.io lib
    include 'lib/forecast.io.php';
    // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
    // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
    $fc_unit = isset($conf['forecast_conf']['unit']) ? $conf['forecast_conf']['unit'] : 'auto';
    $fc_lang = isset($conf['forecast_conf']['lang']) ? $conf['forecast_conf']['lang'] : 'en';
    /* Do we have a Forecast.io API key */
    if (strlen($fc_api_key) != 0) {
        // Make a request to Forecast.io using the user supply API, proxy set to false
        $forecast = new ForecastIO($fc_api_key, $fc_unit, $fc_lang, false);
    } else {
        /**
         * Make a request to https://forecast-xbgmsharp.rhcloud.com
         * to non disclose the Forecast.io API key, proxy set to true
         * Source code at https://github.com/xbgmsharp/nodejs-forecast
         **/
        $forecast = new ForecastIO($fc_api_key, $fc_unit, $fc_lang, true);
    }
    $condition = $forecast->getHistoricalConditions($lat, $lon, $date);
    if (!isset($condition) or $condition === 'false') {
        return;
    }
    //print_r($condition);
    // Parse weather condition to human readable
    $condition = parseCondition($condition);
    // Select the template
    $template->set_filenames(array('forecast_content' => dirname(__FILE__) . "/template/picture.tpl"));
    // Assign the template variables
    $template->assign(array('FORECAST_HEIGHT' => $fc_height, 'FORECAST_PATH' => embellish_url(get_gallery_home_url() . FORECAST_PATH), 'FORECAST_NAME' => $fc_header, 'FORECAST_NAME_CSS' => $fc_header_css, 'FORECAST_SHOW_LINK' => $fc_show_link, 'FORECAST_LINK' => $fc_link, 'FORECAST_DATA' => $condition));
    // Return the rendered html
    $forecast_content = $template->parse('forecast_content', true);
    return $forecast_content;
}
Ejemplo n.º 2
0
$apiKeyParam = $_GET["apiKey"];
$latParam = $_GET["lat"];
$lonParam = $_GET["lon"];
$unitsParam = $_GET["units"];
$langParam = $_GET["lang"];
$units = 'us';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
if ($unitsParam != "") {
    $units = $unitsParam;
}
if ($langParam != "") {
    $lang = $langParam;
}
//error_log(date(DATE_RFC822)." -- api=".$apiKeyParam.",lat=".$latParam.",lon=".$lonParam.",units=".$units.",lang=".$lang."\n", 3, '/home/weather.log');
$forecast = new ForecastIO($apiKeyParam, $units, $lang);
$condition = $forecast->getCurrentConditions($latParam, $lonParam);
echo "CURRENT_TEMP=" . round($condition->getTemperature()) . "\n";
echo "CURRENT_HUMIDITY=" . $condition->getHumidity() * 100 . "\n";
echo "CURRENT_ICON=" . $condition->getIcon() . "\n";
echo "CURRENT_SUMMARY=" . $condition->getSummary() . "\n";
$conditions_week = $forecast->getForecastWeek($latParam, $lonParam);
echo "MAX_TEMP_TODAY=" . round($conditions_week[0]->getMaxTemperature()) . "\n";
echo "MIN_TEMP_TODAY=" . round($conditions_week[0]->getMinTemperature()) . "\n";
echo "ICON_TODAY=" . $conditions_week[0]->getIcon() . "\n";
echo "SUMMARY_TODAY=" . $conditions_week[0]->getSummary() . "\n";
echo "MAX_TEMP_TOMORROW=" . round($conditions_week[1]->getMaxTemperature()) . "\n";
echo "ICON_TOMORROW=" . $conditions_week[1]->getIcon() . "\n";
echo "MIN_TEMP_TOMORROW=" . round($conditions_week[1]->getMinTemperature()) . "\n";
echo "SUMMARY_TODAY=" . $conditions_week[1]->getSummary() . "\n";
Ejemplo n.º 3
0
<?php

include 'lib/forecast.io.php';
$api_key = '<your_api_key>';
$latitude = '52.4308';
$longitude = '13.2588';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
// all default will be
// $forecast = new ForecastIO($api_key);
/*
 * GET CURRENT CONDITIONS
 */
$condition = $forecast->getCurrentConditions($latitude, $longitude);
echo 'Current temperature: ' . $condition->getTemperature() . "\n";
/*
 * GET HOURLY CONDITIONS FOR TODAY
 */
$conditions_today = $forecast->getForecastToday($latitude, $longitude);
echo "\n\nTodays temperature:\n";
foreach ($conditions_today as $cond) {
    echo $cond->getTime('H:i:s') . ': ' . $cond->getTemperature() . "\n";
}
/*
 * GET DAILY CONDITIONS FOR NEXT 7 DAYS
 */
$conditions_week = $forecast->getForecastWeek($latitude, $longitude);
echo "\n\nConditions this week:\n";
Ejemplo n.º 4
0
            $userIP = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $userIP = $_SERVER['REMOTE_ADDR'];
        }
        $IPInfoLoc = json_decode(file_get_contents('http://ipinfo.io/{$userIP}/loc'));
        $IPInfoArray = explode(",", $IPInfoLoc);
        $userLat = $IPInfoArray[0];
        $userLong = $IPInfoArray[1];
    } else {
        $userLat = $_GET['latitude'];
        $userLong = $_GET['longitude'];
    }
}
$forecast = new ForecastIO($apikey);
if ($userLat != null && $userLong != null) {
    $units = 'si';
    $_COOKIE['tempPref'] == 'F' ? $units = 'us' : pass;
    $condition = $forecast->getCurrentConditions($userLat, $userLong, $units);
    $weatherCondition = $condition->getIcon();
    // $weatherCondition = 'clear';
    $backgroundImageURL = './weather-backgrounds/' . $weatherCondition . '.jpg';
    $conditionLaterToday = $forecast->getForecastToday($userLat, $userLong, $units);
    $weatherConditionLater = $conditionLaterToday[7]->getIcon();
    if (in_array($weatherConditionLater, ['rain', 'snow', 'sleet'])) {
    }
    if (in_array($weatherCondition, ['clear-night', 'partly-cloudy-night'])) {
        $isNight = True;
    }
}
Ejemplo n.º 5
0
        $city[$count] = $row["city"];
        $Latitude[$count] = $row["latitude"];
        $Longtitude[$count] = $row["longtitude"];
        $count++;
    }
} else {
    echo "0 results";
}
//making api request
include 'forecast.io.php';
$api_key = 'f823baf7f2ef7fdf8122040b3f7c8074';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
$tempCount = 0;
while ($tempCount < $count) {
    $arrayData = $forecast->getArray($Latitude[$tempCount], $Longtitude[$tempCount]);
    //weekly
    $weekly = $arrayData[2];
    $current = $arrayData[0];
    $day = 0;
    foreach ($weekly as $current) {
        $dateW = $current->getTime('Y-m-d');
        $summaryW = $current->getSummary();
        $maxTempW = $current->getMaxTemperature();
        $minTempW = $current->getMinTemperature();
        $iconW = $current->getIcon();
        $sunRise = $current->getSunrise();
        $sunSet = $current->getSunset();
Ejemplo n.º 6
0
<?php

include 'lib/forecast.io.php';
#Slack slash command to return the weather given a zipcode
# Uses forecast.io PHP API by https://github.com/tobias-redmann
$api_key = '0743673bd6f1c055452ab6ee2731dcfd';
//forecast.io API key
$units = 'us';
//units of measurement
$lang = 'en';
//language
#$command = $_POST['command'];   //Slack command name
$text = $_POST['text'];
//given zipcode
$forecast = new ForecastIO($api_key, $units, $lang);
#Convert zipcode to lat/long
$zip = $forecast->getLatLong($text);
$latitude = $zip['lat'];
$longitude = $zip['lng'];
#Int conversion on lat/long
$lat = (int) $latitude;
$long = (int) $longitude;
$geocode = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . $text . '&sensor=true');
$output = json_decode($geocode);
$location = $output->results[0]->formatted_address;
$condition = $forecast->getCurrentConditions($lat, $long);
echo $location . '|' . $condition->getTemperature() . '|' . $condition->getCloudCover();
//print info to slack
Ejemplo n.º 7
0
<?php

//making api request
include 'forecast.io.php';
$api_key = 'f823baf7f2ef7fdf8122040b3f7c8074';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
$arrayData = $forecast->getArray(43.7, 79.40000000000001);
$temperatureNow = $arrayData[0];
$temperatureWeekly = $arrayData[2];
echo $temperatureNow . getTemperature();
foreach ($temperatureWeekly as $temperatureNow) {
    echo $temperatureNow->getTime('Y-m-d') . ': ' . $temperatureNow->getMaxTemperature() . "\n";
}
//echo $temperatureWeekly;
//while ($tempCount < $count)
//{
//getting data array
//$arrayData = $forecast->getArray(43.7, -79.4);
//$temperatureNow = $arrayData[0]->getTemperature();
//echo $temperatureNow;
/*$temperature = $condition->getTemperature();
	$ApparentTemperature = $condition->getApparentTemperature();
	$Summary = $condition->getSummary();
	$Icon = $condition->getIcon();
	$Time = $condition->getTime();
	$ressure = $condition->getPressure();
	$DewPoint = $condition->getDewPoint();
Ejemplo n.º 8
0
ini_set("html_errors", 1);
error_reporting(E_ALL);
session_start();
include_once '../m/ToolsPdo.php';
include '../m/libs/forecast.io.php';
// include('./v/stylesheet.css');
//Get my model's singleton ToolsPdo
$toolPdo = ToolsPdo::getToolsPdo();
$searchRange = 10;
//forecast api need those
$api_key = '538a11475afb9fdd4f9891efb0b697db';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
if (!empty($_GET['ID'])) {
    for ($i = 0; $i < $searchRange; $i++) {
        if ($_GET['ID'] == $i) {
            $found = true;
            break;
        } else {
            $found = false;
        }
    }
    if ($found) {
        $_SESSION['user'] = $toolPdo->getUser($_GET['ID']);
        $condition = $forecast->getCurrentConditions($_SESSION['user']['CoordLat'], $_SESSION['user']['CoordLong']);
        include "../v/v_weather.php";
    } else {
        echo "<div='error'><h1>We've met some 404 error, sorry for that...</h1></div>\n\t\t\t<p>Consider trying another ID number in the URL</p>";
Ejemplo n.º 9
0
function getweather($api_key, $latitude, $longitude, $units = "auto", $lang = "en")
{
    $forecast = new ForecastIO($api_key, $units, $lang);
    //This is array holding CURRENT weather data i.e. weather right now
    $now = array();
    $yesterday = array();
    //This holds today's, tomorrow's and the day after's weather data
    $twoday = array();
    //create a timestamp of yestday, so we can retrieve its weather
    $today = new DateTime("now");
    $yesterdaytime = $today->sub(new DateInterval('P1D'))->getTimeStamp();
    //echo $yesterday;
    //Get current conditions and give to array too
    $condition = $forecast->getCurrentConditions($latitude, $longitude);
    echo "current: " . $condition->getTemperature() . "\n";
    echo "percent rain: " . $condition->getPrecipitationProbability() . "\n";
    echo "humidity: " . $condition->getHumidity() . "\n";
    echo "rain fall: " . $condition->getPrecipitationIntensity();
    $now['temp'] = $condition->getTemperature();
    $now['chancerain'] = $condition->getPrecipitationProbability();
    $now['humidity'] = $condition->getHumidity();
    $now['summary'] = $condition->getSummary();
    $now['rainfall'] = $condition->getPrecipitationIntensity();
    //If precip probability > 0 then get precip type too
    if ($now['chancerain'] > 0) {
        echo "Precip type: " . $current->PrecipitationType() . "\n";
        $now['preciptype'] = $current->PrecipitationType();
    }
    //Get weekly forecast (next 2 days is fine)
    $conditions_week = $forecast->getForecastWeek($latitude, $longitude);
    //print_r($conditions_week);
    echo "\nConditions this week:\n";
    $i = 0;
    foreach ($conditions_week as $conditions) {
        $cheese = new DateTime("now");
        $step = new DateInterval('P2D');
        //If day is less then or equal to 2 days from now then we want that info
        if ($cheese->add($step)->format('Y-m-d') >= $conditions->getTime('Y-m-d')) {
            echo $conditions->getTime('Y-m-d') . ": " . $conditions->getMaxTemperature() . "\n";
            $twoday[$i]['maxtemp'] = $conditions->getMaxTemperature();
            $twoday[$i]['chancerain'] = $conditions->getPrecipitationProbability();
            $twoday[$i]['rainfall'] = $conditions->getPrecipitationIntensity();
            $twoday[$i]['rainfallmax'] = $conditions->getPrecipitationIntensityMax();
            if ($twoday[$i]['rainfallmax'] > 0) {
                $twoday[$i]['rainfallmaxtime'] = $conditions->getPrecipitationIntensityMaxTime();
            }
            if ($twoday[$i]['chancerain'] > 0) {
                echo "Precip type: " . $conditions->getPrecipitationType() . "\n";
                $twoday[$i]['preciptype'] = $conditions->getPrecipitationType();
            }
            $twoday[$i]['humidity'] = $conditions->getHumidity();
            $twoday[$i]['summary'] = $conditions->getSummary();
        }
        $i++;
    }
    //Get Yesterdays forecast
    echo "\n Yesterdays conditions: \n";
    $yesterdays = $forecast->getHistoricalConditions($latitude, $longitude, $yesterdaytime);
    echo "Yesterday: " . $yesterdays->getMaxTemperature() . "\n";
    echo "percent rain: " . $yesterdays->getPrecipitationProbability() . "\n";
    echo "humidity: " . $yesterdays->getHumidity() . "\n";
    echo "rain fall: " . $yesterdays->getPrecipitationIntensity();
    $yesterday['temp'] = $yesterdays->getMaxTemperature();
    $yesterday['chancerain'] = $yesterdays->getPrecipitationProbability();
    $yesterday['humidity'] = $yesterdays->getHumidity();
    $yesterday['summary'] = $yesterdays->getSummary();
    $yesterday['rainfall'] = $yesterdays->getPrecipitationIntensity();
    //If precip probability > 0 then get precip type too
    if ($yesterday['chancerain'] > 0) {
        echo "Precip type: " . $yesterdays->PrecipitationType() . "\n";
        $yesterdays['preciptype'] = $yesterdays->PrecipitationType();
    }
    //print_r($yesterdays);
    //return array with current, today, tomorrow, and day after temp/conditions
    return [$now, $twoday];
}
Ejemplo n.º 10
0
<?php

include 'forecast.io.php';
$api_key = 'e3e8ebe2bd577358b2092c49cb6da160';
$latitude = '52.4308';
$longitude = '13.2588';
$units = 'us';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key);
/*
* GET CURRENT CONDITIONS
*/
$condition = $forecast->getCurrentConditions($latitude, $longitude, $units, $lang);
echo $condition->getTemperature();
/*
* GET HOURLY CONDITIONS FOR TODAY
*/
$conditions_today = $forecast->getForecastToday($latitude, $longitude, $units, $lang);
foreach ($conditions_today as $cond) {
    echo $cond->getTime('H:i:s') . ': ' . $cond->getTemperature();
}
/*
* GET DAILY CONDITIONS FOR NEXT 7 DAYS
*/
$conditions_week = $forecast->getForecastWeek($latitude, $longitude);
foreach ($conditions_week as $conditions) {
    echo $conditions->getTime('Y.m.d') . ': ' . $conditions->getMaxTemperature();
}
/*
Ejemplo n.º 11
0
    } else {
        return 'none';
    }
}
$now = date("Y-m-d H:i:s");
//proper created_at / updated_at mysql format
$today = date("Y-m-d");
$db = connect();
$api_key = returnApiKey();
$latitude = '34.101655';
$longitude = '-117.707591';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
// all default will be
// $forecast = new ForecastIO($api_key);
/*
 * GET CURRENT CONDITIONS
 */
//$condition = $forecast->getCurrentConditions($latitude, $longitude);
/*
 * GET HOURLY CONDITIONS FOR TODAY
 */
$temperature = $forecast->getForecastToday($latitude, $longitude);
$current_temp = $temperature[0]->getTemperature();
// foreach($conditions_today as $cond) {
//
//     //echo $cond->getTime('H:i:s') . ': ' . $cond->getTemperature(). "\n";
//     //echo "<br>";
Ejemplo n.º 12
0
 $fc_api_key = isset($conf['forecast_conf']['api_key']) ? $conf['forecast_conf']['api_key'] : '';
 // Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
 // Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
 $fc_unit = isset($conf['forecast_conf']['unit']) ? $conf['forecast_conf']['unit'] : 'auto';
 $fc_lang = isset($conf['forecast_conf']['lang']) ? $conf['forecast_conf']['lang'] : 'en';
 /* Do we have a Forecast.io API key */
 if (strlen($fc_api_key) != 0) {
     // Make a request to Forecast.io using the user supply API, proxy set to false
     $forecast = new ForecastIO($fc_api_key, $fc_unit, $fc_lang, false);
 } else {
     /**
      * Make a request to https://forecast-xbgmsharp.rhcloud.com
      * to non disclose the Forecast.io API key, proxy set to true
      * Source code at https://github.com/xbgmsharp/nodejs-forecast
      **/
     $forecast = new ForecastIO($fc_api_key, $fc_unit, $fc_lang, true);
 }
 $images = hash_from_query($query, 'id');
 $datas = array();
 $errors = array();
 $warnings = array();
 $infos = array();
 foreach ($images as $image) {
     // Fech reverse location from API
     $condition = $forecast->getHistoricalConditions($image['latitude'], $image['longitude'], $image['date']);
     if (!isset($condition) or $condition === 'false') {
         $errors[] = "Error fetching weather condition data for " . $image['name'];
     }
     //print_r($condition);
     // If reponse include icon
     if (isset($condition) and isset($condition->icon) and !empty($condition->icon)) {