View file weather-kosovo/class.moti.php

File size: 3.31Kb
<?php

###########################################################################################################
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////#################### KLASSA PER MOTIN ####################///////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
###########################################################################################################

class koha{
  //xml dhanat
  private $xml = 'http://www.google.com/ig/api?weather=';
  //Default qyteti
  private $qyteti = 'Pietermaritzburg, South Africa';
  //Lexo XML-in
  function readXML(){
  //Curl dhanat
    $url = $this->xml.urlencode($this->qyteti)."&hl=en";
    $response = $this->dhanat($url);
    $dhanat = utf8_encode($response);
    $xml = simplexml_load_string($dhanat);
    if(!isset($xml->weather->problem_cause)){
    return $xml;
    }else{
      die("Location Unknown... Please Check Spelling, etc...");
    }

  }
  //Kohorja ne qytet
  function qyteti($qyteti){
    $this->qyteti = $qyteti;
  }

  private function dhanat($url){

	if (!extension_loaded('curl')) {
            throw new Exception('curl extension is not available');
        }

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_URL, $url);
        $response = curl_exec($curl);
		curl_close ($curl);

        return $response;

  }



  //Emri i Qytetit
  function emri_qyteti(){
    return (string)$this->readXML()->weather->forecast_information->city->attributes()->data;
  }

  //Ikonat
  function ikona(){
    $ikona = (string)$this->readXML()->weather->forecast_conditions->icon[0]->attributes()->data;
    echo "<img src=\"http://www.google.com".$ikona."\">";
  }
  //ditete
  function ditet_javes(){

  }

  //Ora tanishme e temperatures
  function oraTanishme(){
    $ora = (string)$this->readXML()->weather->forecast_information->current_date_time->attributes()->data;
    $ora = substr($ora,-14);
    $ora = substr($ora,0,-9);
    return $ora;
  }
  //Temperatura e sodit ne Farad
  function temperatura_f(){
    return (string)$this->readXML()->weather->current_conditions->temp_f->attributes()->data;
  }
  //Temperatura e sodit ne Celsius
  function temperatura_c(){
    return (string)$this->readXML()->weather->current_conditions->temp_c->attributes()->data;
  }


  //Konverto Farad ne Celsius
  function convert_celsius($fahrenheit){
    $celsius = ($fahrenheit-32)*5/9;
    return number_format($celsius,0);
  }

}

###########################################################################################################
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////#################### KLASSA PER MOTIN ####################///////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
###########################################################################################################
?>