-1

我目前正在使用一个脚本,当有人在我的网站上搜索电影时,它会检查 MySQL 数据库以查看电影数据是否存在。

如果是,它会显示搜索结果。如果没有,它会转到 IMDB.com,抓取内容,然后将该数据插入 MySQL 数据库。

有没有人通过快速查看下面的代码知道是否有一种方法可以通过注释掉一行来快速禁止这种情况发生,或者是否需要有人彻底检查它?

如果它在 MySQL DB 中看不到电影数据,我不希望它进入 IMDB。

    <?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();
}
    ?>
4

2 回答 2

0

这:

else {
    $imdb = new Imdb();
    $movieArray = $imdb->getMovieInfo(htmlEntities($_GET['q']));

您可以注释掉整个 else 块,它不会再调用 imdb

于 2012-10-03T23:44:18.743 回答
0

用 INSERT 注释掉查询

// $insertData = "INSERT INTO `imdb`  (...)
//    mysql_query($insertData);
于 2012-10-03T23:51:14.197 回答