Location: PHPKode > scripts > EMovies > emovies/erevfunc.php
<?php
###########################
#
#	EMovies Pro
#	Coder: FrosT
#	EMail: hide@address.com
#	File: erevfunc.php
#	Description: 
#		Processes the Review Code.
###########################

class movieReviews {
	var $url;
	var $SERVER_URL;
	var $reviews;
	var $title;
	var $ets;
	var $useCurl;
	
	// constructor
	function movieReviews() {
		$this->ets->copyright = "Powered by <a href=\"http://www.emocium.com\" target=\"_blank\">Emocium</a>.";
	}
	
	// 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->reviews == "") {
			if ($this->url == "") {
				$this->error("There is no URL to grab the data.");
				return;
			}
			
			$i=0;
			while ($this->reviews == false && $i != 4) {
				if ($this->useCurl) {
					$this->reviews = $this->curlGetContents($this->url, FALSE);
				}else {
					$this->reviews = $this->file_get_contents2($this->url, FALSE);
				}
				$i++;
			}
			
			if ($this->reviews == "") {
				$this->error("Unable to retrieve reviews, please try again later.");
			}
		}
	}
	
	// Grabs the cast and credits.
	function getCastCredits($castCredits) {
		if (is_array($castCredits)) {
			foreach($castCredits as $cast) {
				list($type, $cast) = split('</font>', $cast);
				list(,$cast) = split('<font face=arial size=-1>', $cast);
				
				if (strstr(strtolower($cast), '</a>')) {
					$individuals = split(',', $cast);
					$cast = "";
					foreach ($individuals as $indi) {
						$cast .= $indi;
					}				
					
					$individuals = split('">', $cast);
					array_shift($individuals);
					$cnt = count($individuals);
					$cast = "";
					$i=1;
					foreach ($individuals as $indi) {
						list($castIndi) = split("</a>", $indi);
						if ($i != $cnt) {
							$cast .= trim($castIndi) . ", ";
						}else {
							$cast .= trim($castIndi);
						}
						$i++;
					}				
					
				}
				
				if (strstr(strtolower($type), 'starring')) {
					$this->ets->starring = $cast;
				}
				
				if (strstr(strtolower($type), 'directed')) {
					$this->ets->directed = $cast;
				}
				
				if (strstr(strtolower($type), 'produced')) {
					$this->ets->produced = $cast;
				}
			}
		}else {
			$this->error("Invalid Data when retrieving Cast and Credits.");
		}
	}

	// Grabs the movies title.
	function getTitle() {
		if ($this->reviews == "") {
			$this->getData();
		}
		
		list(,$title) = split('<meta name="keywords" content="', strtolower($this->reviews));
		list($title) = split('">', $title);
		list($title) = split('),', $title);
		$this->ets->title = $this->title = trim(ucwords($title . ")"));		
	}

	// Grab the movie information
	function getMovieInfo() {
		if ($this->reviews == "") {
			$this->getData();
		}
		
		$this->getTitle();
		
		list($movImage,$movieData) = split('<!-- vertical spacer -->', $this->reviews);
		
		if (strstr($movImage, '<div id="whatsnew">')) {
			// Get image 101, 149
			list(,$adImage) = split('<div id="whatsnew">', $movImage);
			list($adImage) = split('</center>', $adImage);
			list(,,$adImage) = split('<img src=', $adImage);
			list($adImage) = split('width=', $adImage);
			$this->ets->imageCode = '<img src="'.$adImage.'" alt="'.$this->title.' Poster" width="101" height="149" />';
			$this->ets->image = $adImage;
		}else {
			// Get image 101, 149 without whatsnew
			list(,$image) = split('<!-- sneak peak feature -->', $movImage);
			list($image) = split('</center>', $image);
			list(,$image) = split('<img src=', $image);
			list($image) = split('width=', $image);
			$this->ets->imageCode = '<img src="'.$image.'" alt="'.$this->title.' Poster" width="101" height="149" />';
			$this->ets->image = $image;
		}
		
		// Description
		list($description,) = split('<br clear="all">', $movieData);
		list(,$description) = split('<font face=arial size=-1>', $description);
		$this->ets->description = ereg_replace("</font>", "", trim($description));
		
		// Properties (Genres etc)
		$properties = split('<!-- property -->', $movieData);
		array_shift($properties);
		$this->getProperties($properties);
		
		// Cast and Credits
		list(,$castCredits) = split('<!-- cast and credits -->', $movieData);
		list($castCredits) = split('<!-- /cast and crew -->', $castCredits);
		$castCredits = split('<tr>', $castCredits);
		array_shift($castCredits);
		$this->getCastCredits($castCredits);
	
		// Critics and Reviews
		list(,$critics) = split('<!-- /new critical consensus bar -->', $movieData);
		list($critics) = split('<!-- /critics reviews -->', $critics);
		list(, $critics) = split('<span class="grade">', $critics);
		list($grade, $critics) = split('</span>', $critics);
		$this->ets->grade = trim($grade);
		
		$critics = split('<tr bgcolor=white>', $critics);
		array_shift($critics);
		$this->getCritics($critics);	
	}		
	
	// Grab the critics and review data.
	function getCritics($criticts) {
		if (is_array($criticts)) {
			$i=0;
			foreach ($criticts as $critic) {
				list(,$critic) = split('<font face="Arial" size="-1">', $critic);
				list($critic, $grade) = split('<nobr>', $critic);
				list($critic, $review) = split('<br>', $critic);
				list(,$grade) = split('<font face="Arial">', $grade);
				list($grade) = split('</font>', $grade);
				
				$this->ets->critics[$i]->grade = trim($grade);
				$this->ets->critics[$i]->critic = trim($critic);
				$this->ets->critics[$i]->review = trim($review);
				$i++;
			}
		}else {
			$this->error('Invalid Data when retrieving Critics');
		}
	}
	
	// Fetches the properties of the movie.
	function getProperties($properties) {
		if (is_array($properties)) {
			foreach ($properties as $property) {
				list($type, $property) = split('</font>', $property);
				list(,$property) = split('<font face=arial size=-1>', $property);
				
				if (strstr(strtolower($type), "genres")) {
					$this->ets->genre = trim($property);
				}
				
				if (strstr(strtolower($type), "running")) {
					$this->ets->runningTime = trim($property);
				}
				
				if (strstr(strtolower($type), "release")) {
					$this->ets->releaseDate = trim($property);
				}
				
				if (strstr(strtolower($type), "mpaa")) {
					$this->ets->mpaaRating = trim($property);
				}
				
				if (strstr(strtolower($type), "distributors")) {
					$property = ereg_replace('<div style="padding-bottom:5px;">|</div>', '', $property);
					$this->ets->distributors = trim($property);
				}
			}
		}else {
			$this->error("Invalid data when retrieving Properties.");
		}
	}

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

?>
Return current item: EMovies