<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';

only_reg();
$set['title']='Погода';
include_once 'sys/inc/thead.php';
title();
err();
aut();

if ((!isset($_SESSION['refer']) || $_SESSION['refer']==NULL)
&& isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL &&
!preg_match('#umenu\.php#',$_SERVER['HTTP_REFERER']))
$_SESSION['refer']=str_replace('&','&amp;',preg_replace('#^http://[^/]*/#','/', $_SERVER['HTTP_REFERER']));



    class GoogleWeather {
 public $xml;
 
 function __construct($city, $lang="ru", $charset="utf-8"){
       $base = 'http://www.google.com/ig/api';
       $params = "weather=" . trim($city);
       $params .= "&hl=" . trim($lang);
       $params .= "&oe=" . trim($charset);
       $url = $base . "?" . $params;
       $this->xml = simplexml_load_file($url);
 }
 
 function getInfo(){
      if(!$this->xml) return false;
      $information = $this->xml->xpath("/xml_api_reply/weather/forecast_information");
      return $information[0];
 }
 
 function getCurrentWeather(){
      if(!$this->xml) return false;
      $current = $this->xml->xpath("/xml_api_reply/weather/current_conditions");
      return $current[0];
 }
 
 function getForecast(){
      if(!$this->xml) return array();
      $forecast_list = $this->xml->xpath("/xml_api_reply/weather/forecast_conditions");
      return $forecast_list;
 }
 
}




$ucity=$user['ank_city'];
if($ucity){




// создаем экземпляр класса и указываем город

$gw = new GoogleWeather($ucity);
// погода на сегодня (текущие показания)
$gw_today = $gw->getCurrentWeather();
$gw_info = $gw->getInfo();
  


$posts=array(); 
echo 'Погода сегодня:<br/>';
echo '<img src="http://www.google.com'.$gw_today->icon['data'].'" style="float:left" alt=""/>'; echo $gw_info->city['data']; echo "<br/>{$gw_today->temp_c['data']} °C, {$gw_today->condition['data']}<br/> {$gw_today->humidity['data']}, {$gw_today->wind_condition['data']}<br/>";

if(isset($_GET['4days'])){


$gw_forecast = $gw->getForecast();



foreach ($gw_forecast as $forecast){ 

echo '<hr/><img src="http://www.google.com'.$forecast->icon['data'].'" style="float:left" alt=""/>'; echo $forecast->day_of_week['data']; echo "<br/>от {$forecast->low[data]} °C до {$forecast->high[data]} °C<br/>{$forecast->condition['data']}<br/>";


}

echo '<a href="?">Убрать &uarr;<br/></a>'; 
 }else{

echo '<a href="?4days">Прогноз погоды на 4 дня &darr;</a><br/>';
}

}else echo 'Хотите видеть прогноз погоды? <a href="/countr.php">Укажите свой город!</a><br/>';



include_once 'sys/inc/tfoot.php';
?>