Return to Snippet

Revision: 38504
at February 20, 2011 00:55 by GeekOfWeb


Updated Code
<?php
/**
 * This class will get the times of pray of the current day
 * All times are correct because we get them from Diyanet.gov.tr
 *
 * @author Serkan Yildiz <[email protected]>
 * @version 1.0
 * @copyright Serkan Yildiz (freelancer), 3 January, 2011
 * @example 
*		try{
*			$namaz = new NamazSaati('COUNTRY_NAME', 'CITY_NAME') // turkish names
*		}catch($e Exception){
*			$saatler = $namaz->getAllTimes();
*		}
 **/


Class NamazSaati {
	
	/**
	* Country
	* @access protected
	*/
	protected $country;
	
	/**
	* City
	* @access protected
	*/
	protected $city;
	
	/**
	* Data URL
	* @access private
	*/
	private $url = "http://diyanet8.diyanet.gov.tr/turkish/namazapi/Getir.ashx?country=%country%&cities=%city%&Backcolor=000000&forecolor=ffffff&lang=TR&fontsize=14";
	
	/**
	* Instance for DOM stuff
	* @access private
	*/
	private $xml;
	
	/**
	* constructor, build url and load the DOM
	* @return void
	* @param 	string $country		Country
	* @param 	string $city		City
	*/
	public function __construct($country, $city)
	{
		//redefine
		$country	= strtoupper($country);
		$city 		= strtoupper($city);
		$this->setCountry($country);
		$this->setCity($city);
		
		$this->dom = new DOMDocument('1.0', 'utf-8'); // an instance from DOMDocument
		$replace = array('%country%', '%city%');
		$replaceWith = array($country, $city);
		$dataUrl = str_replace($replace, $replaceWith, $this->url);
		$content = @file_get_contents($dataUrl); // trying to connect the API
		
		if($content === false){ // If we can't connect the API catch it!
			throw new Exception('The API is unavailable')
		}
		
		$content = "<html><head><title>Namaz Saati Class</title></head><body>".$content."</body></html>";
		$this->dom->loadHTML($content);
	}
	
	/**
	* setter for Country
	* @return void
	* @param 	string $country		Country
	*/
	private function setCountry($country)
	{
		$this->country = $country;
	}
	
	/**
	* setter for City
	* @return void
	* @param 	string $city		city
	*/
	private function setCity($city)
	{
		$this->city = $city;
	}
	
	/**
	* getter for Country
	* @return string	Country
	*/
	public function getCountry()
	{
		return $this->country;
	}
	
	/**
	* getter for City
	* @return	string		City
	*/
	public function getCity()
	{
		return $this->city;
	}
	
	/**
	* getter for Imsak time
	* @return 	string	$timeSelector		time of imsak
	*/
	public function getImsakTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(9)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Gunes time
	* @return 	string $timeSelector		time of Gunes
	*/
	public function getGunesTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(10)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Ogle time
	* @return 	string	$timeSelector		time of Ogle
	*/
	public function getOgleTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(11)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Ikindi time
	* @return 	string $timeSelector		time of ikindi
	*/
	public function getIkindiTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(12)->nodeValue;
		return $timeSelector;
	} 
	
	/**
	* getter for Aksam time
	* @return 	string $timeSelector		time of Aksam
	*/
	public function getAksamTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(13)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Yatsi time
	* @return 	string $timeSelector	time of Yatsi
	*/
	public function getYatsiTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(14)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter all times of the current day
	* @return 	array $times	all times of current day
	*/
	public function getAllTime()
	{
		$times = array(
						'imsak' 	=>	$this->getImsakTime(),
						'gunes' 	=>	$this->getGunesTime(),
						'ogle' 		=> 	$this->getOgleTime(),
						'ikindi' 	=>	$this->getIkindiTime(),
						'aksam' 	=>	$this->getAksamTime(),
						'yatsi' 	=>	$this->getYatsiTime()
					);
		return $times;
	}
}

Revision: 38503
at January 4, 2011 09:32 by GeekOfWeb


Updated Code
<?php
/**
 * This class will get the times of pray of the current day
 * All times are correct because we get them from Diyanet.gov.tr
 *
 * @author Serkan Yildiz <[email protected]>
 * @version 1.0
 * @copyright Serkan Yildiz (freelancer), 3 January, 2011
 * @example  $namaz = new NamazSaati('COUNTRY_NAME', 'CITY_NAME') // turkish names
 *			$namaz->getAllTimes(); // it will return an array with the times of today in an array
 **/


Class NamazSaati {
	
	/**
	* Country
	* @access protected
	*/
	protected $country;
	
	/**
	* City
	* @access protected
	*/
	protected $city;
	
	/**
	* Data URL
	* @access private
	*/
	private $url = "http://diyanet8.diyanet.gov.tr/turkish/namazapi/Getir.ashx?country=%country%&cities=%city%&Backcolor=000000&forecolor=ffffff&lang=TR&fontsize=14";
	
	/**
	* Instance for DOM stuff
	* @access private
	*/
	private $xml;
	
	/**
	* constructor, build url and load the DOM
	* @return void
	* @param 	string $country		Country
	* @param 	string $city		City
	*/
	public function __construct($country, $city)
	{
		//redefine
		$country	= strtoupper($country);
		$city 		= strtoupper($city);
		$this->setCountry($country);
		$this->setCity($city);
		
		$this->dom = new DOMDocument('1.0', 'utf-8'); // an instance from DOMDocument
		$replace = array('%country%', '%city%');
		$replaceWith = array($country, $city);
		$dataUrl = str_replace($replace, $replaceWith, $this->url);
		$content = @file_get_contents($dataUrl);
		$content = "<html><head><title>Hello</title></head><body>".$content."</body></html>";
		$this->dom->loadHTML($content);
	}
	
	/**
	* setter for Country
	* @return void
	* @param 	string $country		Country
	*/
	private function setCountry($country)
	{
		$this->country = $country;
	}
	
	/**
	* setter for City
	* @return void
	* @param 	string $city		city
	*/
	private function setCity($city)
	{
		$this->city = $city;
	}
	
	/**
	* getter for Country
	* @return string	Country
	*/
	public function getCountry()
	{
		return $this->country;
	}
	
	/**
	* getter for City
	* @return	string		City
	*/
	public function getCity()
	{
		return $this->city;
	}
	
	/**
	* getter for Imsak time
	* @return 	string	$timeSelector		time of imsak
	*/
	public function getImsakTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(9)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Gunes time
	* @return 	string $timeSelector		time of Gunes
	*/
	public function getGunesTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(10)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Ogle time
	* @return 	string	$timeSelector		time of Ogle
	*/
	public function getOgleTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(11)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Ikindi time
	* @return 	string $timeSelector		time of ikindi
	*/
	public function getIkindiTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(12)->nodeValue;
		return $timeSelector;
	} 
	
	/**
	* getter for Aksam time
	* @return 	string $timeSelector		time of Aksam
	*/
	public function getAksamTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(13)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Yatsi time
	* @return 	string $timeSelector	time of Yatsi
	*/
	public function getYatsiTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(14)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter all times of the current day
	* @return 	array $times	all times of current day
	*/
	public function getAllTime()
	{
		$times = array(
						'imsak' 	=>	$this->getImsakTime(),
						'gunes' 	=>	$this->getGunesTime(),
						'ogle' 		=> 	$this->getOgleTime(),
						'ikindi' 	=>	$this->getIkindiTime(),
						'aksam' 	=>	$this->getAksamTime(),
						'yatsi' 	=>	$this->getYatsiTime()
					);
		return $times;
	}
}

Revision: 38502
at January 4, 2011 09:09 by GeekOfWeb


Initial Code
<?php
/**
 * This class will get the times of pray of the current day
 * All times are correct because we get them from Diyanet.gov.tr
 *
 * @author Serkan Yildiz <[email protected]>
 * @version 1.0
 * @copyright Serkan Yildiz (freelancer), 3 January, 2011
 * @example  $namaz = new NamazSaati('COUNTRY_NAME', 'CITY_NAME') // turkish names
 *			$namaz->getAllTimes(); // it will return an array with the times of today in an array
 **/


Class NamazSaati {
	
	/**
	* Country
	* @access protected
	*/
	protected $country;
	
	/**
	* City
	* @access protected
	*/
	protected $city;
	
	/**
	* Data URL
	* @access private
	*/
	private $url = "http://diyanet8.diyanet.gov.tr/turkish/namazapi/Getir.ashx?country=%country%&cities=%city%&Backcolor=000000&forecolor=ffffff&lang=TR&fontsize=14";
	
	/**
	* Instance for DOM stuff
	* @access private
	*/
	private $xml;
	
	/**
	* constructor, build url and load the DOM
	* @return void
	* @param 	string $country		Country
	* @param 	string $city		City
	*/
	public function __construct($country, $city)
	{
		$this->setCountry($country);
		$this->setCity($city);
		
		$this->dom = new DOMDocument('1.0', 'utf-8'); // an instance from DOMDocument
		$replace = array('%country%', '%city%');
		$replaceWith = array($country, $city);
		$dataUrl = str_replace($replace, $replaceWith, $this->url);
		$content = @file_get_contents($dataUrl);
		$content = "<html><head><title>Hello</title></head><body>".$content."</body></html>";
		$this->dom->loadHTML($content);
	}
	
	/**
	* setter for Country
	* @return void
	* @param 	string $country		Country
	*/
	private function setCountry($country)
	{
		$this->country = $country;
	}
	
	/**
	* setter for City
	* @return void
	* @param 	string $city		city
	*/
	private function setCity($city)
	{
		$this->city = $city;
	}
	
	/**
	* getter for Country
	* @return string	Country
	*/
	public function getCountry()
	{
		return $this->country;
	}
	
	/**
	* getter for City
	* @return	string		City
	*/
	public function getCity()
	{
		return $this->city;
	}
	
	/**
	* getter for Imsak time
	* @return 	string	$timeSelector		time of imsak
	*/
	public function getImsakTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(9)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Gunes time
	* @return 	string $timeSelector		time of Gunes
	*/
	public function getGunesTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(10)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Ogle time
	* @return 	string	$timeSelector		time of Ogle
	*/
	public function getOgleTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(11)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Ikindi time
	* @return 	string $timeSelector		time of ikindi
	*/
	public function getIkindiTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(12)->nodeValue;
		return $timeSelector;
	} 
	
	/**
	* getter for Aksam time
	* @return 	string $timeSelector		time of Aksam
	*/
	public function getAksamTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(13)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter for Yatsi time
	* @return 	string $timeSelector	time of Yatsi
	*/
	public function getYatsiTime()
	{
		$timeSelector = $this->dom->getElementsByTagName('td')->item(14)->nodeValue;
		return $timeSelector;
	}
	
	/**
	* getter all times of the current day
	* @return 	array $times	all times of current day
	*/
	public function getAllTime()
	{
		$times = array(
						'imsak' 	=>	$this->getImsakTime(),
						'gunes' 	=>	$this->getGunesTime(),
						'ogle' 		=> 	$this->getOgleTime(),
						'ikindi' 	=>	$this->getIkindiTime(),
						'aksam' 	=>	$this->getAksamTime(),
						'yatsi' 	=>	$this->getYatsiTime()
					);
		return $times;
	}
}

Initial URL


Initial Description


Initial Title
Namaz Saati Class

Initial Tags


Initial Language
PHP