Location: PHPKode > scripts > EMovies > emovies/emovfunc.php
<?php
###########################
#
#	EMovies Pro
#	Coder: FrosT
#	EMail: hide@address.com
#	File: emovfunc.php
#	Description: 
#		Listings Functions.
###########################

class movieListings {
	var $url;
	var $theaterNames;
	var $movies;
	var $ets;
	var $SERVER_URL;
	var $useCurl;
	
	// Constructor
	function movieListings() {
		// Please leave the copyright for us on there, it is much appreciated.
		$this->ets->copyright = "Powered by <a href=\"http://www.emocium.com\" target=\"_blank\">Emocium</a>.";
		$this->ets->bookmark = '<a href="javascript:window.external.AddFavorite(\'movielistings\',\'Movie Listings\')">Click here to bookmark this site</a>';
		$this->useCurl = true;
	}

	// Grab the web information
	function file_get_contents2($filename, $use_include_path = 0) {
		$file = @fopen($filename, 'rb', $use_include_path);
		if ($file) {
			if ($fsize = @filesize($filename)) {
				$data = fread($file, $fsize);
			}else {
				while (!feof($file)) {
					$data .= fread($file, 1024);
				}
			}
			fclose($file);
			return $data;
		}else {
			return false;
		}	        
	}
	
	// grab the web information via curl
	function curlGetContents() {
		// create a new curl resource
		$ch = curl_init();
		
		// set URL and other appropriate options
		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		
		// grab URL and pass it to the browser
		$data = curl_exec($ch);
		
		// close curl resource, and free up system resources
		curl_close($ch);
		
		return $data;
	}
	
	// Given the Url grabs the Yahoo Page.
	function getData() {
		if ($this->movies == "") {
			$i=0;
			while ($this->movies == false && $i != 4) {
				if ($this->useCurl) {
					$this->movies = $this->curlGetContents($this->url, FALSE);
				}else {
					$this->movies = $this->file_get_contents2($this->url, FALSE);
				}	
				$i++;
			}
			
			if ($this->movies == "") {
				$this->error('Unable to retrieve Movie Listings.');
			}
		}
	}
	
	// Grabs the initial List of Theaters
	function getTheaterList() {		
		// Get the theaters names.
		list(,$theaterNameTable) = split("<!-- Start theater name table -->", $this->movies);
		list($theaterNameTable, $this->movies) = split("<!-- /End theater name table -->", $theaterNameTable);
		
		// grab the date
		list(,$date) = split("selected>Today,", $this->movies);
		list($date) = split("</option><br>", $date);
		$this->ets->date = $date;
		
		$theaterNames = split("<br>", $theaterNameTable);
		$i=0;
		foreach ($theaterNames as $theater) {
			if (strstr($theater, '<a href=')) {
				list(,$theater) = split("<a href=", $theater);
				$theaterNames[$i] = "<a href=" . trim($theater);
				
				if (strstr($theater, '</td>')) {
					list($theater) = split("</td>", $theater);
					$theaterNames[$i] = "<a href=" . trim($theater);
				}
			}else {
				$theaterNames[$i] = trim($theater);
			}
			
			$i++;
		}
		
		$this->theaterNames = $theaterNames;
		
		$i=0;
		foreach($theaterNames as $theaterNm) {
			$this->ets->theaterList[$i]->name = $theaterNm;		
			$this->ets->theaterList[$i]->split = 0;
			
			if ($i == 5) {
				$this->ets->theaterList[$i]->split = 1;
			}
			$i++;
		}
	}

	// Grabs the theater information and movies playing.
	function getTheater() {
		$this->getData();
		$this->getTheaterList();
		
		if ($this->movies != "") {
			// This gets each theater in its individual setting
			$theaters = split("<!--  Print the name of the theater. -->", $this->movies);
			$i=0;
			foreach ($theaters as $theater) {
				list($theaters[$i]) = split("<!-- /Theater Table -->", $theater);
				$i++;
			}
			array_shift($theaters);
			
			$theater = array();
			$i=0;
			foreach ($theaters as $theaterInfo) {
				// Get the Theater Name
				$theater[$i]->name = ereg_replace("<a href=\"\#T".($i + 1)."\">", "", $this->theaterNames[$i]);
				$theater[$i]->name = ereg_replace("</a>", "", $theater[$i]->name);
				$theater[$i]->name .= '<a name="#T'.($i + 1).'"></a>';
				
				// Check for special theater featuers
				if (strstr(strtolower($theaterInfo), "wheelchair")) {
					$theater[$i]->wheel = '<img src="http://us.i1.yimg.com/us.yimg.com/i/mo/wchr.gif" title="Wheelchair Accessible" />';
				}
	
				if (strstr(strtolower($theaterInfo), "listening")) {
					$theater[$i]->listen = '<img src="http://us.i1.yimg.com/us.yimg.com/i/mo/hear.gif" title="Hearing Impaired Accomodations" />';
				}
				
				if (strstr(strtolower($theaterInfo), "print")) {
					$theater[$i]->printTix = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/mov/b/i16_print.gif" title="Ticket Printing" />';
				}
				
				if (strstr(strtolower($theaterInfo), "stadium")) {
					$theater[$i]->stadium = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/mov/b/i16_stad.gif" title="Stadium Seating" />';
				}
				
				if (strstr(strtolower($theaterInfo), "game")) {
					$theater[$i]->game = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/mov/b/i16_game.gif" title="Game Room" />';
				}
				
				if (strstr(strtolower($theaterInfo), "thx")) {
					$theater[$i]->thx = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/mov/b/i16_thx.gif" title="THX Certified" />';
				}
				
				if (strstr(strtolower($theaterInfo), "cafe")) {
					$theater[$i]->cafe = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/mov/b/i16_cafe.gif" title="Cafe Lounge" />';
				}
				
				// grab the address
				list(,$address) = split("<!-- Address Row -->", $theaterInfo);
				list($address, $movieInfo) = split("<!-- /Address Row -->", $address);
				
				list($address, $extraLinks) = split("</td>", $address);
	
				list(,$address) = split("class=ygfa>", $address);
				$theater[$i]->address = trim($address, "\n");
				
				// grab the extraLinks (map and theater info)
				list(,$extraLinks) = split("&nbsp;", $extraLinks);
				$extraLinks = ereg_replace("href=\"/", "href=\"http://movies.yahoo.com/", $extraLinks);
				$extraLinks = ereg_replace("\">", "\" target=\"_blank\">", $extraLinks);
				$theater[$i]->extraLinks = trim($extraLinks);
				
				// grab the movie time Information
				$theater[$i]->movies = $this->getMovies($movieInfo);
				
				$i++;
			}
			
			$this->ets->theater = $theater;
			
			return $this->ets->theater;
		}else {
			$this->error("Unable to Retrieve Theaters, invalid data supplied.");
		}
	}
	
	// Grab the movie information.
	function getMovies($movieInfo) {
		if ($movieInfo != "") {
			$movInfo = split('<td width="50%" class=ygfa>', $movieInfo);
			array_shift($movInfo);
			
			$i=0;
			$cnt = count($movInfo);
			foreach ($movInfo as $movieData) {
				list($movieTitle, $movieInfo, $movieTime) = split("<br>", $movieData);
				$movieTitle = ereg_replace("http://movies.yahoo.com/movie", $this->SERVER_URL . "/index.php/reviews", $movieTitle);
				$movieTitle = ereg_replace("/info", "", $movieTitle);
				$movies[$i]->movieTitle = trim($movieTitle);
				
				// grab the Rating/Start Date
				if (strstr(strtolower($movieInfo), "start")) {
					$movies[$i]->movieRating = "N/A";
					$movies[$i]->movieStarts = trim($movieInfo);
					continue;
				}else {
					list(,$movieRating) = split("<small>", $movieInfo);
					$movies[$i]->movieRating = trim($movieRating);
				}			
	
				// Grab the movie time
				$movies[$i]->movieTimes = $this->getMovieTimes($movieTime);
				
				$movies[$i]->isEven = ($i % 2);
				
				if ($cnt == ($i + 1) && $movies[$i]->isEven == 0) {
					$movies[$i]->endsEven = 1;
				}
				
				$i++;
			}
			
			return $movies;
		}else {
			$this->error("Invalid Data supplied for Movie Information.");
		}
	}
	
	// Grabs the movie times for each movie.
	function getMovieTimes($movieTimes) {
		if ($movieTimes != "") {
			$times = $movieTimes;
			if (strstr(strtolower($movieTimes), "buy")) {
				$times = split("http%3A//", $movieTimes);
				array_shift($times);
				
				$cnt = (count($times) - 1);
				$i=0;
				foreach ($times as $time) {
					list($timeLink) = split(",", $time);
					$timeLink = ereg_replace("\)", "", $timeLink);
					
					if ($i != $cnt) {
						$timeLink = '<a target="_blank" href="http://'.$timeLink.', ';
					}else {
						list($timeLink) = split("</tr>", $timeLink); 
						$timeLink = '<a target="_blank" href="http://'.trim($timeLink);
					}
					
					$movieTime .= $timeLink;
					$i++;
				}
			}else {
				list(,$times) = split("</span>", $movieTimes);
				$times = ereg_replace("\(", "", $times);
				$times = ereg_replace("\)", "", $times);
				
				if (strstr($times, "</tr>")) {
					list($times) = split("</tr>", $times); 
					
					if (strstr($times, "<td>")) {
						list($times) = split("<td>", $times); 
					}
				}
				
				$movieTime = trim($times);
			}
			
			return $movieTime;
		}else {
			$this->error("Invalid Data supplied for Movie Times.");
		}
	}

	// Error handling.
	function error($msg) {
		include('error.php');
		die();
	}
	
}

?>
Return current item: EMovies