The vB Geek

Go Back   The vB Geek > vB Geek Commons > Lizard Lounge

Lizard Lounge The place to post off topic stuff.

Advertisement
This is an HTML example. Isn't it just wonderful?!?!
  Learn how to remove ads

Reply
 
Thread Tools Display Modes
  #1  
Old 10-07-2005, 12:13 PM
Lizard King's Avatar
Lizard King Lizard King is offline
Senior Member
 
Join Date: Oct 2005
Location: Istanbul
Posts: 555
Geek Article and Review System License Holder Geek Gazette License Holder 
Default Trying To Figure Out How

I know it is not the regular place to ask how to do it but i am trying to make an IMDB module for GAR.
I am going to use it for my movie section in my board.
There are couple things in my mind. Like when someone is creating a topic this section has to be filled.
When you are creating a topic the user will only have to fill the movies IMDB id. Then we can add a script like this to check if the imdb ID has been entered or not.
Code:
<script language='JavaScript' type="text/javascript"><!-- function ValidateForm_imdb_id() { var Check = 0; if (document.form_imdb_id.imdb_id.lenght < 5) { Check = 1; } if (Check == 1) { alert("You have to enter movie imdb ID"); return false; } else { document.form_imdb_id.submit.disabled = true; return true; } } --></script>
The imdb id is really easy to do . All moviews urls in imdb are like http://www.imdb.com/title/tt0082198/ the last section is the movies ID number without the TT in this case it will be 0082198 .

Now what i am still thinking is how to enter this imdb id tag to the database and how can we recall it so that in the module there will be 2 section. One will have the Imdb movie name and link to imdb and the second one will show movies IMDB rating.

I prepared a screenshot of the module i am thinkin in my mind. If someone can help it is really appriciated
Attached Images
File Type: jpg imdbmodule.jpg (7.9 KB, 10 views)

Last edited by Lizard King; 10-07-2005 at 12:17 PM..
Reply With Quote
  #2  
Old 10-07-2005, 12:23 PM
The Geek's Avatar
The Geek The Geek is offline
Senior Member
 
Join Date: Aug 2005
Posts: 6,717
Geek Article and Review System License Holder GeekMart License Holder Geek Auto-Linker Pro License Holder Geek Advertising Banner License Holder Geek Gazette License Holder 
Default

Ill see if I can get the mod tutorial done today as this is easily accomplished. Everything is already in place
Reply With Quote
  #3  
Old 10-07-2005, 12:56 PM
Lizard King's Avatar
Lizard King Lizard King is offline
Senior Member
 
Join Date: Oct 2005
Location: Istanbul
Posts: 555
Geek Article and Review System License Holder Geek Gazette License Holder 
Default

I hope it will be as easy as you say
Reply With Quote
  #4  
Old 10-07-2005, 01:44 PM
DerTobi75 DerTobi75 is offline
Member
 
Join Date: Sep 2005
Posts: 68
Geek Article and Review System License Holder GeekMart License Holder Geek Auto-Linker Pro License Holder Geek Advertising Banner License Holder Geek Gazette License Holder 
Default

Hi,

do not know if it helps, but while looking for some webfetching phpscripts I just found a php class for getting informations out of imdb.com!

http://sourceforge.net/projects/imdbphp/

Regrads,

Tobi
Reply With Quote
  #5  
Old 11-17-2005, 02:56 AM
Lizard King's Avatar
Lizard King Lizard King is offline
Senior Member
 
Join Date: Oct 2005
Location: Istanbul
Posts: 555
Geek Article and Review System License Holder Geek Gazette License Holder 
Default

Geek i found a fetch script i dont know if it works but it might help me to create the imdb module. Is there anyway to integrate this fetching script into a module in gars
Code:
<?php
/** fetch-script: imdb.com
 *
 * $Id: fetch-imdb.php,v 1.2 2004/01/07 22:13:33 michasch Exp $
 *
 * create your own fetch-scripts for other webpages like this one
 * but please don't make any changes at this file, always make first
 * a copy of it.
 *
 * please send us your fetch-scripts, so we can add them to the
 * powermovielist! you can also export them with the export-settings-feature
 * 
 * @package fetch
 */

//first check if the class exists allready, if so return and don't include it again
if(class_exists("pmlfetch_imdb")) return;

//IMPORTANT: the class-name (pmlfetch_*) has to be the same as the file-name (fetch-*.php)
class pmlfetch_imdb extends pml_fetch {
	
	/**
	 * FieldNames
	 * IMPORTANT: Add new fields here and in function DoFetch
	 *
	 * @access private	 
	 **/
	var $FieldNames = array("Title",
		                    "Year",
		                    "Poster",
		                    "Director",
	                        "Genre",
							"Rating",
							"Starring",
							"Plot",
							"Release",
                            "Runtime",
                            "MPAA",
							"imdbid");
	/**
	 * actorLimit
	 *
	 * @access private
	 * @var int
	 **/
	var $actorLimit;

	/**
	 * doSearch - perform the search on the page to fetch from
	 *
	 * @param &$out return-string: the HTML-code displayed when searching
	 * @param $SearchString string: the string sent to the page to search for
	 * @param $EntryUrl string: url used for links in HTML-code
	 * @access public
	 * @return const PML_FETCH_SEARCHERROR, PML_FETCH_SEARCHDONE or PML_FETCH_EXACTMATCH
	 **/
	function doSearch(&$out, $SearchString, $EntryUrl) {		

		$out .= $GLOBALS['strSearchingInfoFor'] . $SearchString . "...";
		$Name = rawurlencode($SearchString);
		//$Name = str_replace("%20", "+", $SearchString);

		$data = "GET /find?tt=on;mx=20;q=$Name HTTP/1.0\r\n";
		$data .= "Accept: text/html, image/png, image/x-xbitmap, image/gif, image/jpeg, */*\r\n";
		$data .= "Referer: http://us.imdb.com/Find\r\n";
		$data .= "Accept-Language: de\r\n";
		$data .= "Content-type: application/x-www-form-urlencoded\r\n";
		$data .= "Accept-Encoding: gzip, deflate, x-gzip, identity, *;q=0\r\n";
		$data .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)\r\n";
		$data .= "Host: us.imdb.com\r\n";
		$data .= "Connection: Keep-Alive\r\n";
		$data .= "Cache-Control: no-cache\r\n";
		$data .= "\r\n";
		$data .= $request;

		$site = $this->FetchPage($data, "us.imdb.com:80");

		//when you use the search-form on imdb.com and you search for a title that was exactly found
		//imdb uses a 302-found-page to redirect to the Title-page of this movie.
		//if this happens, we can use this imdb-id too
		if(strstr($site, "HTTP/1.0 302") || strstr($site, "HTTP/1.1 302")) { //exact match?
			$out .= $GLOBALS['strExactMatch'];
			ereg("Location: /title/tt([0-9]*)", $site, $x);
            //ereg("Location: http://us.imdb.com/title/tt([0-9]*)/, $site, $x);
			$this->FetchID = $x[1];	      //save the id in $FetchID
			return(PML_FETCH_EXACTMATCH); //return to editentry that it can fetch now the data - search is allready done
		}

		$y=preg_split('/<b>(.+?)<\/b> \(\d+ match.*?\)/msi', $site);

		$anz=0;
		$SearchData = array();
		for($i=1;$i<sizeof($y);$i++) {
			$site = $y[$i];
			$cat=" -$i- ";
			while(ereg('<a href=\"\/title\/tt([0-9]+)\/\">([^\<]*)</a>', $site, $x)) {
            //while(ereg('<LI><A HREF=\"\/title\/tt([0-9]+)\/\">([^\<]*)</A>', $site, $x)) {
			//while(ereg('<LI><A HREF=\"\/Title\?([0-9]+)\">([^\<]*)</A>', $site, $x)) {
				$anz++;
				$site = substr($site,strpos($site,$x[0])+strlen($x[0]));
				$rest = substr($site,0,strpos($site,"</LI>"));

				$help = str_replace("...aka","<br>&nbsp;&nbsp;&nbsp;&nbsp;",strip_tags($rest)); 
				$SearchData[] = array("id"   => $x[1],
					                  "name" => $x[2],
					                  "help" => $help,
					                  "cat"  => $cat);
			}
		}

		if($anz==0) {
			$out .= $GLOBALS['strErrNothingFoundEnterNewString'];			
			return(PML_FETCH_SEARCHDONE);
		}

		$out .= $GLOBALS['strFoundMore'];
		//print out all the movies found:
		$out .= "<table>";
		
		$Page = basename(__FILE__);
		$Page = substr($Page, 6);
		$Page = substr($Page, 0, -4);

		$LastCat = "";
		foreach($SearchData as $Dat) {
			if($Dat['cat']!=$LastCat) {
				$out .= "<tr class='top'><td colspan=2 align='left'>$Dat[cat]:</td></tr>\n";
				$j=1;
			}
			$LastCat = $Dat['cat'];
			$out .= "<tr class='row";
			if($j++%2) $out .= "1"; else $out .= "2";
			$out .= "'><td width='20'>&nbsp;</td><td>";
			$out .= "<a href=\"$EntryUrl&" . urlencode("fid[{$Page}]")."=".urlencode($Dat['id'])."\">$Dat[name]</a>";
			$out .= " - <a href=\"http://us.imdb.com/Title?$Dat[id]\" target=_blank>$GLOBALS[strInfo]</a>\n";
			if(strlen($Dat['help'])>2) $out .= $Dat['help'];
			$out .= "</td></tr>\n";														   
		}
		$out .= "</table>";


		return(PML_FETCH_SEARCHDONE);
	}

    /**
     * GetCachedPage
     *
     * downloaded a given url with a given referrer, uses caching from fetch-class
     *
     * @param string the url to fetch
     * @param string the Referrer (default-value is set here)
     **/
	function GetCachedPage($Url, $Referer="http://us.imdb.com/") {
        return($this->fetchCachedUrl($Url, "us.imdb.com", $Referer));
	}

	/**
	 * DoFetch - perform the search on the page to fetch from
	 *
	 * IMPORTANT if you want to add some feilds:
	 * if you add new fields, add them to var $FieldNames on top of this file
	 *
	 * @param string the fetched value (return-string)
	 * @param string the FieldName
	 * @access public
	 * @return const PML_FETCH_ERROR, PML_FETCH_OK or PML_FETCH_ITEMNOTFOUND
	 **/
    function DoFetch(&$ret, $FieldName) {
		global $CFG;
		
		switch($FieldName) {
			case "Title": //fetch Title

				//get this url, cached if allready used:
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");

				//regular-expresstion to filter out the field
                if(!eregi("<STRONG CLASS=\"title\">([^\<]*) <SMALL>\(<A HREF=\"/Sections/Years/([0-9]{4})", $site, $x)) {

					//if eregi fails, print error-message and return error					
					return(PML_FETCH_ERROR);
				}

				//else set $ret (will be returned)
                $ret = $x[1];
                $ret = addslashes($ret);				
				
				//and break
				break;
			case "Year":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!eregi("<STRONG CLASS=\"title\">([^\<]*) <SMALL>\(<A HREF=\"/Sections/Years/([0-9]{4})", $site, $x)) {
					return(PML_FETCH_ERROR);
				}
                $ret = $x[2];
                if($ret=="") $ret=0;                
				break;				
			case "Poster":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!preg_match('/<img alt="cover" align="left" src="([^"]+)"/is', $site, $x)) {
					return(PML_FETCH_ERROR);
				}
                $ret = $x[1];
                $ret= addslashes($ret);
				break;
			case "Director":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!preg_match('#Directed by.*\n[^<]*<a href="/Name?[^"]*">([^<]*)</a>#i', $site, $x)) {
					return(PML_FETCH_ERROR);
				}
                $ret = $x[1];
                $ret = addslashes($ret);				
                break;
			case "Genre":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!preg_match('#Genre:</b>(.*?)<br>#msi', $site, $gen)) {                    
                    return(PML_FETCH_ERROR);
				}
                $gen = $gen[1];
                $ret = array();
                while(eregi("<A HREF=\"/Sections/Genres/[a-zA-Z\\-]*/\">([a-zA-Z\\-]*)</A>", $gen, $x)) {
                        $gen = substr($gen,strpos($gen,$x[0])+strlen($x[0]));
						$ret[] = addslashes($x[1]);
                }
				if(sizeof($ret)==0) {
					return(PML_FETCH_ERROR);
				}
				break;
			case "Rating":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!eregi("<B>([0-9]).([0-9])/10</B> \([0-9,]+ votes\)", $site, $x)) {
					return(PML_FETCH_ERROR);
				}
                $ret = $x[1].$x[2];
				$ret = $ret/10;
				break;
			case "Starring":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
				$ret = array();
				$i=0;
                while(eregi('<td valign="top"><a href="/name/nm([^"]+)">([^<]*)</a></td>', $site, $x)) {
					$i++;
					if($i>$this->actorLimit) break;
					$site = substr($site,strpos($site,$x[0])+strlen($x[0]));
					$ret[] = addslashes($x[2]);
                }
				if(sizeof($ret)==0) {
					return(PML_FETCH_ERROR);
				}
				break;
			case "Plot":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/plotsummary/", "http://us.imdb.com/title/tt$this->FetchID/");
				if(eregi('<p class="plotpar">([^<]*)</p>', $site, $x)) {
					//plot exists:
					$ret = addslashes($x[1]);
				} else {
					//plot doesn't exist, use plot-outline from title-page:
					$site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
					preg_match("#Plot Outline:</b>([^<]*)#", $site, $x);
					$ret = @addslashes($x[1]);
					// if there's no plot outline fetch tagline.
					if(!$ret) {
						$x = array();
						if(!preg_match("#Tagline:</b>([^<]*)#", $site, $x)) {
									return(PML_FETCH_ERROR);
						}
						$ret = addslashes($x[1]);
					}

				}
				break;
			case "Release":
				$site = $this->GetCachedPage("/title/tt$this->FetchID/releaseinfo", "http://us.imdb.com/title/tt$this->FetchID/");

                $convert["January"]="01";
                $convert["February"]="02";
                $convert["March"]="03";
                $convert["April"]="04";
                $convert["May"]="05";
                $convert["June"]="06";
                $convert["July"]="07";
                $convert["August"]="08";
                $convert["September"]="09";
                $convert["October"]="10";
                $convert["November"]="11";
                $convert["December"]="12";

                if(!eregi('<a href="/BusinessThisDay[^>]*>([0-9]+) ([A-Za-z]+)</a>', $site, $date)) {
					return(PML_FETCH_ERROR);
				}

                if(!eregi("<a href=\"/Sections/Years[^>]*>([^<]*)</A>", $site, $year)) {
					return(PML_FETCH_ERROR);
				}

                $ret = $year[1] . "-" . $convert[$date[2]] . "-" . $date[1];
				break;
			case "imdbid":
				$ret = $this->FetchID;
				break;
            case "Runtime":
                $site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!preg_match('#<b class="ch">Runtime:</b>\n([0-9]+) min#i', $site,$x)) {                    
                    return(PML_FETCH_ERROR);
                }
                $ret = $x[1];
                $ret = addslashes($ret);
                break;                
            case "MPAA":
                $site = $this->GetCachedPage("/title/tt$this->FetchID/", "http://us.imdb.com/Find");
                if(!preg_match('#<b class="ch"><a href="/mpaa">MPAA</a>:</b> Rated ([^ ]+) for (.+).<br>#i', $site,$x)) {                    
                    return(PML_FETCH_ERROR);
                }
                $ret = $x[1];
                $ret = addslashes($ret);
				break;
			default:
				return(PML_FETCH_ITEMNOTFOUND);
		}//end switch $FieldName
        if(is_array($ret)) {
            foreach($ret as $k=>$i) {
                $ret[$k] = $this->ReplaceUnicodeChars($i);
            }
        } else {
            $ret = $this->ReplaceUnicodeChars($ret);
        }
		
		return(PML_FETCH_OK);
	}//end function DoFetch
    

	/**
	 * getUseSettings
	 *
	 * returns if this field has additional settings
	 *
	 * @access public	 
	 * @param string the field
	 * @return boolean
	 **/
	function getUseSettings($field) {
		switch($field) {
			case "Starring":
				return(true);
			default:
				return(false);
		}
	}

	/**
	 * printSettings
	 *
	 * print out here the HTML-code for your custom settings
	 *
	 * @access public
	 * @param string the field
	 * @param string the current setting from the database	 
	 * @return the HTML-code
	 **/
	function printSettings($field, $set) {
		global $HTTP_GET_VARS;
		switch($field) {
			case "Starring":
				if($set=="") $set="3";
				$out = "<input type=\"text\" name=\"set{$field}\" size=\"3\" value=\"$set\"> Actors to fetch\n";
				return($out);
		}
	}
	/**
	 * saveSettings
	 *
	 * processes the $_GET-stuff and validates it and then moves it into
	 * one string that will be saved in the database (only one field is
	 * avaliable for saving the data!
	 *
	 * @access public
	 * @param  string the field
	 * @return string the string that will be saved in the db
	 **/
	function saveSettings($field) {
		global $HTTP_POST_VARS;		
		switch($field) {
			case "Starring":
				return($HTTP_POST_VARS['set'.$field]);
			default:
				return("");
		}
	}

	/**
	 * setSetting
	 *
	 * will be called from editentry.php bevore calling DoFetch
	 * (only if $set is not empty)
	 * There shoud the setting be processed and saved into some
	 * class-vars...
	 *
	 * @access public
	 * @param  string 
	 * @param  string the field
	 **/
	function setSettings($field, $set) {
		switch($field) {
			case "Starring":
				if($set=="" || $set==0) $set="3";
				$this->actorLimit = $set;
				break;
		}
	}
}

?>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I can't figure out how to assign each review system to each forum cookiepants Geek Article and Review System 1 10-21-2006 08:05 AM


All times are GMT. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.