I’m currently using a script which when someone searches for a movie on my site, it checks the MySQL db to see if the movie data exists.
If it does, it shows the search result. If it doesn’t, it goes to IMDB.com, scrapes content and then inserts that data into the MySQL database.
Does anyone know from quickly looking at the code below if there’s a way to quickly disable that from happening by just commenting out a line or will it require someone to go over it thoroughly?
I don’t want it to go to IMDB if it doesn’t see the movie data in the MySQL DB.
<?php
function PageMain() {
global $TMPL;
include('./includes/imdb.php');
$all = 'Sorry, it seems that the movie you where looking for doesn\'t exist or we don\'t have it in our database...';
$text = $_GET['a'];
$name = htmlspecialchars(urldecode($_GET['q']), ENT_QUOTES);
$per_page = 50;
$page_query = mysql_query("SELECT COUNT(id) from imdb WHERE title LIKE '%%$name%'");
$pages = ceil(mysql_result($page_query, 0) / $per_page);
$page = (isset($_GET['page']) AND (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
if(!empty($name)) {
$queryid = 'SELECT * FROM imdb WHERE title LIKE "%%'.$name.'%"';
if(mysql_fetch_row(mysql_query($queryid)) >= 1) {
$query = "SELECT * FROM imdb WHERE title LIKE '%%%s%%' LIMIT %d, %d;";
$query = sprintf($query, $name, $start, $per_page);
$result = mysql_query($query);
$TMPL_old = $TMPL; $TMPL = array();
$skin = new skin('search/rows'); $all = '';
while($TMPL = mysql_fetch_assoc($result)) {
if ($TMPL['votes'] == NULL) {$TMPL['votes'] = '?';}
if ($TMPL['tagline'] == NULL) {$TMPL['tagline'] = 'None';}
$TMPL['title_encoded'] = str_replace("+", "-", urlencode($TMPL['title']));
$TMPL['genre'] = '';
foreach(explode(', ', $TMPL['genres']) as $v)
$TMPL['genre'] .= '<a href="/genre/'.$v.'">'.$v.'</a>, ';
$TMPL['actor'] = '';
foreach(explode(', ', $TMPL['actors']) as $v)
$TMPL['actor'] .= '<a href="/actor/'.str_replace("+", "-", urlencode($v)).'">'.$v.'</a>, ';
$all .= $skin->make();
}
//Incepe selectarea actorilor
$query_actors = "SELECT `actors` FROM `imdb` ORDER BY `id` DESC LIMIT 0,3";
$actors_result = mysql_query($query_actors);
$TMPL = array (); $skin = new skin('shared/actors'); $actors = '';
while ($TMPL = mysql_fetch_assoc($actors_result))
{
$TMPL['actor'] = '';
foreach(explode(', ', $TMPL['actors']) as $v)
$TMPL['actor'] .= '<a href="/actor/'.str_replace("+", "-", urlencode($v)).'">'.$v.'</a> <br />';
$actors .= $skin->make();
}
// Incepe paginarea
$skin = new skin('shared/pagination'); $pagination = '';
if ($pages >= 1 && $page <= $pages) {
for ($x=1; $x<=$pages; $x++) {
$TMPL['pagination'] = ($x == $page) ? '<strong><a href="/index.php?a=search&q='.urlencode($name).'&page='.$x.'">'.$x.'</a></strong> ' : '<a href="/index.php?a=search&q='.urlencode($name).'&page='.$x.'">'.$x.'</a> ';
$pagination .= $skin->make();
}
}
$TMPL = $TMPL_old; unset($TMPL_old);
$TMPL['actors'] = $actors;
$TMPL['rows'] = $all;
$TMPL['pagination'] = $pagination;
$text = 'content';
} else {
$imdb = new Imdb();
$movieArray = $imdb->getMovieInfo(htmlEntities($_GET['q']));
if(!isset($movieArray['title_id'])) { $TMPL['rows'] = $all; } else {
$title_id = $movieArray['title_id'];
$poster = $movieArray['poster'];
$title = $movieArray['title'];
$tagline = $movieArray['tagline'];
$year = $movieArray['year'];
$release = $movieArray['release_date'];
$votes = $movieArray['rating'];
$plot = $movieArray['plot'];
$runtime = $movieArray['runtime'];
$storyline = $movieArray['storyline'];
$genres = $movieArray['genres'];
$stars = $movieArray['stars'];
$oscars = $movieArray['oscars'];
$mpaa = $movieArray['mpaa_rating'];
$country = $movieArray['country'];
$actori = implode(", ", $stars);
$genuri = implode(", ", $genres);
$countries = implode(", ", $country);
$trivia = $movieArray['trivia'];
$selectData = "SELECT * FROM `imdb` where `imdbid` = '$title_id'";
if(strlen($poster) >= 5) {
if(mysql_fetch_row(mysql_query($selectData)) === false) {
$insertData = "INSERT INTO `imdb` (`imdbid` , `poster` , `title` , `tagline` , `plot` , `year` , `release`, `country`, `runtime` , `storyline`, `genres`, `actors`, `votes`, `oscars`, `mpaa`, `trivia`) VALUES ('$title_id', 'posters/$title_id.jpg', '$title', '$tagline', '$plot', '$year', '$release', '$countries', '$runtime', '$storyline', '$genuri', '$actori', '$votes', '$oscars', '$mpaa', '$trivia')";
mysql_query($insertData);
$ch = curl_init ($poster);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.12 Safari/535.2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen('posters/'.$title_id.'.jpg', 'w');
fwrite($fp, $rawdata);
fclose($fp);
}
} else {
if(mysql_fetch_row(mysql_query($selectData)) === false) {
$insertData = "INSERT INTO `imdb` (`imdbid` , `poster` , `title` , `tagline` , `plot` , `year` , `release`, `country`, `runtime` , `storyline`, `genres`, `actors`, `votes`, `oscars`, `mpaa`, `trivia`) VALUES ('$title_id', 'posters/noposter.jpg', '$title', '$tagline', '$plot', '$year', '$release', '$countries', '$runtime', '$storyline', '$genuri', '$actori', '$votes', '$oscars', '$mpaa', '$trivia')";
mysql_query($insertData);
}
}
$query = "SELECT * FROM imdb WHERE title LIKE '%%%s%%' LIMIT %d;";
$query = sprintf($query, $name, 40);
$result = mysql_query($query);
$TMPL_old = $TMPL; $TMPL = array();
$skin = new skin('search/rows'); $all = '';
while($TMPL = mysql_fetch_assoc($result)) {
if ($TMPL['votes'] == NULL) {$TMPL['votes'] = '?';}
if ($TMPL['tagline'] == NULL) {$TMPL['tagline'] = 'None';}
$TMPL['title_encoded'] = str_replace("+", "-", urlencode($TMPL['title']));
$TMPL['genre'] = '';
foreach(explode(', ', $TMPL['genres']) as $v)
$TMPL['genre'] .= '<a href="/genre/'.$v.'">'.$v.'</a>, ';
$TMPL['actor'] = '';
foreach(explode(', ', $TMPL['actors']) as $v)
$TMPL['actor'] .= '<a href="/actor/'.str_replace("+", "-", urlencode($v)).'">'.$v.'</a>, ';
$all .= $skin->make();
}
//Incepe selectarea actorilor
$query_actors = "SELECT `actors` FROM `imdb` ORDER BY `id` DESC LIMIT 0,3";
$actors_result = mysql_query($query_actors);
$TMPL = array (); $skin = new skin('shared/actors'); $actors = '';
while ($TMPL = mysql_fetch_assoc($actors_result))
{
$TMPL['actor'] = '';
foreach(explode(', ', $TMPL['actors']) as $v)
$TMPL['actor'] .= '<a href="/actor/'.str_replace("+", "-", urlencode($v)).'">'.$v.'</a> <br />';
$actors .= $skin->make();
}
$TMPL = $TMPL_old; unset($TMPL_old);
$TMPL['actors'] = $actors;
$TMPL['rows'] = $all;
$text = 'content';
}
}
}
$TMPL['query'] = $name;
$TMPL['title'] = 'yourgamecodes.com/ - Movie - '.$name.'';
$skin = new skin("search/$text");
return $skin->make();
}
?>
This:
You could comment out that whole else block and it would not make any more calls to imdb