<?
class bash_weather{
    // property declaration
	function bash_weather(){
	$this->dest_type=array(0=>'יבשת',1=>'מדינה',2=>'עיר'); //,2=>'טריטוריה'
	$this->dest_cust=array('type'=>'bash_dest_type', 'en'=>'bash_dest_en_name', 'dad'=>'bash_dest_father');
	$this->post_Arr=array(
		'post_title'     =>'',
		'post_author'     =>'',
		'post_status'     =>'',
		'post_type'     =>'',
		'post_content' =>''
		);
	$this->bashDB=new db();
	}
	
	function build_w_city_side($type,$city,$country,$usa,$hName){
		if($type=='2'){
		$this->get_w_id($this->theYahooURL(	$this->yahooMatch($city,$country,$usa)	),$this->yahooMatch($city,$country,$usa),$hName);
		}
		else{echo 'nada';}
	
	}
	
	function yahooMatch($cityEN, $countryEN,$usa){
		$usTxt='';
		$cityEN=$this->cleanName($cityEN);
		$countryEN=$this->cleanName($countryEN);
		if($usa=='usa'){$usTxt='%20USA';}
		$city=str_replace(' ','%20', $this->yahooCity($cityEN));
		$country=str_replace(' ','%20', $this->yahooCountry($countryEN));
		return $city.'%20'.$country.$usTxt;
}
	
	function cleanName($name){
	$sogar_en= strpos($name, ' (');
	$sogar_en2= strpos($name, '(');		
		if ($sogar_en==true){
		$b_c2= explode(' (', $name); 
		return $b_c2[0];
		}
		else if($sogar_en2==true){
		$b_c2= explode('(', $name);
		return $b_c2[0];
		}
		else {return $name;}
	}
	


function theYahooURL($theAdd){
return 'http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22'.$theAdd.'%22&format=xml';	
}


function get_w_id($woeid,$city,$hName){
$place_geo='';
$place_geo=file_get_contents($woeid);
	if ($place_geo!=''){
	$xmlA=explode ('<woeid>',$place_geo);
	$xmlB=explode ('</woeid>', $xmlA[1]);
	$dest_w_id=$xmlB[0];
	require_once('bash_w_disp.php');
	}
	else {return 'לא נמצא מזג האוויר ליעד זה'.$place_geo;}
}			


function yahooCity($tmp_city){
switch ($tmp_city){
	case 'New York City': $back='NYC'; break; 		
	default : $back=$tmp_city;
	}
	
	return $back;
}


function yahooCountry($tmp_country){
switch ($tmp_country){
	case 'Andorra': $back='Andorra la Vella' ; break; 		
//	case 'England': $back='Andorra la Vella' ; break; 		

	default : $back=$tmp_country;
	}
	
	return $back;
}
















	
}

?>