Location: PHPKode > scripts > Mediaset TV > mediaset-tv/mediaset.class.php
<?
/*
Mediaset TV.

	//channel = 4,5,6 or "rete4","canale5","italia1" (noncaps sensitive)
	Mediaset( (int|string) channel )
	
	//time = "21.00", day = 0 (0 today, 1 tomorrow, 2 the day after tomorrow, 3 tomorrow after tomorrow...
	Mediaset::get( (string) time [, (int) day])

	Example:
			$time = '22.00';
			$obj = new Mediaset(6);
			list($name, $start, $end, $date, $channel) = $obj->get($time,1);
			print "Tomorrow, $date on $channel, at $time is aired $name, that starting at $start and finish at $end";
			
*/

class Mediaset
{
	
	var $Italia1 	= "http://www.italia1.mediaset.it/italia1/palinsestoi1.shtml";
	var $Canale5 	= "http://www.canale5.mediaset.it/canale5/palinsestoc5.shtml";
	var $Rete4		= "http://www.rete4.mediaset.it/rete4/palinsestor4.shtml";
	
	var $server;
	var $channel;
	var $html;
	
		function __construct($channel=6)
		{
			$this->channel =	eregi('italia1',$channel)||$channel==6?'Italia1':
								(eregi('canale5',$channel)||$channel==5?'Canale5':
								(eregi('rete4',$channel)||$channel==4?'Rete4':'Italia1'));
								
			$this->server = eval('return $this->{$this->channel};');
								
		}
	
		function getpage()
		{
				$this->html = file_get_contents($this->server) or die("is '$server' down?\n");
		}
		

		function get($time='now', $day='today')
		{
				$this->server .= $day<>'today'?'?day='.date('Ymd',mktime(date(H)+$day*24)):NULL;
				$this->getpage();
				
				$pattern1 = $this->channel == 'Italia1' || $this->channel == 'Canale5'?
							'#width="8%">(.+?)<\/td>#':'#class="col-hours">(.+?)<\/td>#';
							
				$pattern2 = $this->channel == 'Canale5' || $this->channel == 'Rete4'?
							'#<td>(.+?)<\/td>#':'#class=\'textpal\'>(.+?)<\/td>#';
				
					preg_match_all($pattern1, $this->html, $orari);
					preg_match_all($pattern2, $this->html, $programmi);
													
					$time = $time=='now'?floatval(date('H.i')):floatval($time);
					
						for($tmp=24,$i=0; $i<count($orari[1]); $i++)
						{
								$orario = floatval($orari[1][$i]);
								
								if(abs($time-$orario) < $tmp AND $orario<=$time){
									$tmp = abs($time-$orario);
									$n = $i;
								}
						}
						
						return array(	trim(str_replace('&nbsp;', NULL, $programmi[1][$n])),
										$orari[1][$n],
										$orari[1][$n+1],
										date('d/m/Y',mktime(date(H)+$day*24)),
										$this->channel
									);
		}

}	

?>
Return current item: Mediaset TV