root/branches/php4-imdbonly/imdb_person.class.php @ 327

Revision 327, 34.1 KB (checked in by izzy, 7 months ago)

! imdb_person::born() and died() have been broken by IMDB changes again - fixed (see ticket #120; backport from trunk)

  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2 #############################################################################
3 # IMDBPHP                              (c) Giorgos Giagas & Itzchak Rehberg #
4 # written by Giorgos Giagas                                                 #
5 # extended & maintained by Itzchak Rehberg <izzysoft AT qumran DOT org>     #
6 # http://www.izzysoft.de/                                                   #
7 # ------------------------------------------------------------------------- #
8 # This program is free software; you can redistribute and/or modify it      #
9 # under the terms of the GNU General Public License (see doc/LICENSE)       #
10 #############################################################################
11
12 /* $Id$ */
13
14 require_once (dirname(__FILE__)."/imdb_base.class.php");
15
16 #=================================================[ The IMDB Person class ]===
17 /** Accessing IMDB staff information
18  * @package Api
19  * @class imdb_person
20  * @extends imdb_base
21  * @author Izzy (izzysoft AT qumran DOT org)
22  * @copyright 2008 by Itzchak Rehberg and IzzySoft
23  * @version $Revision$ $Date$
24  */
25 class imdb_person extends imdb_base {
26
27 #========================================================[ Common methods ]===
28 #-------------------------------------------------------------[ Open Page ]---
29  /** Define page urls
30   * @method private set_pagename
31   * @param string wt internal name of the page
32   * @return string urlname page URL
33   */
34  function set_pagename($wt) {
35   switch ($wt){
36    case "Name"        : $urlname="/"; break;
37    case "Bio"         : $urlname="/bio"; break;
38    case "Publicity"   : $urlname="/publicity"; break;
39    default            :
40      $this->page[$wt] = "unknown page identifier";
41      $this->debug_scalar("Unknown page identifier: $wt");
42      return false;
43   }
44   return $urlname;
45  }
46
47 #--------------------------------------------------[ Start (over) / Reset ]---
48  /** Reset page vars
49   * @method private reset_vars
50   */
51  function reset_vars() {
52   $this->page["Name"] = "";
53   $this->page["Bio"]  = "";
54
55   // "Name" page:
56   $this->main_photo      = "";
57   $this->fullname        = "";
58   $this->birthday        = array();
59   $this->deathday        = array();
60   $this->allfilms        = array();
61   $this->actressfilms    = array();
62   $this->actorsfilms     = array();
63   $this->producersfilms  = array();
64   $this->soundtrackfilms = array();
65   $this->directorsfilms  = array();
66   $this->crewsfilms      = array();
67   $this->thanxfilms      = array();
68   $this->selffilms       = array();
69   $this->archivefilms    = array();
70
71   // "Bio" page:
72   $this->birth_name      = "";
73   $this->nick_name       = array();
74   $this->bodyheight      = array();
75   $this->bio_bio         = array();
76   $this->bio_trivia      = array();
77   $this->bio_tm          = array();
78   $this->bio_salary      = array();
79
80   // "Publicity" page:
81   $this->pub_prints      = array();
82   $this->pub_movies      = array();
83   $this->pub_interviews  = array();
84   $this->pub_articles    = array();
85   $this->pub_pictorial   = array();
86   $this->pub_magcovers   = array();
87
88   // SearchDetails
89   $this->SearchDetails   = array();
90  }
91
92 #-----------------------------------------------------------[ Constructor ]---
93  /** Initialize class
94   * @constructor imdb_person
95   * @param string id IMDBID to use for data retrieval
96   */
97  function imdb_person ($id) {
98   $this->imdb_base($id);
99   $this->revision = preg_replace('|^.*?(\d+).*$|','$1','$Revision$');
100  }
101
102 #-----------------------------------------------[ URL to person main page ]---
103  /** Set up the URL to the movie title page
104   * @method main_url
105   * @return string url full URL to the current movies main page
106   */
107  function main_url(){
108   return "http://".$this->imdbsite."/name/nm".$this->imdbid()."/";
109  }
110
111 #=============================================================[ Main Page ]===
112 #------------------------------------------------------------------[ Name ]---
113  /** Get the name of the person
114   * @method name
115   * @return string name full name of the person
116   * @see IMDB person page / (Main page)
117   */
118  function name() {
119    if (empty($this->fullname)) {
120      if ($this->page["Name"] == "") $this->openpage ("Name","person");
121      if (preg_match("/<title>(.*?)<\/title>/i",$this->page["Name"],$match)) {
122        $this->fullname = trim($match[1]);
123      }
124    }
125    return $this->fullname;
126  }
127
128 #--------------------------------------------------------[ Photo specific ]---
129  /** Get cover photo
130   * @method photo
131   * @param optional boolean thumb get the thumbnail (100x140, default) or the
132   *        bigger variant (400x600 - FALSE)
133   * @return mixed photo (string url if found, FALSE otherwise)
134   * @see IMDB person page / (Main page)
135   */
136  function photo($thumb=true) {
137    if (empty($this->main_photo)) {
138      if ($this->page["Name"] == "") $this->openpage ("Name","person");
139      if (preg_match('/\<a name="headshot".+"(http:\/\/.+\.jpg)".+<\/a>/',$this->page["Name"],$match)) {
140        if ($thumb) $this->main_photo = $match[1];
141        else        $this->main_photo = str_replace('_SY140_SX100', '_SY600_SX400',$match[1]);
142      } else {
143        return FALSE;
144      }
145    }
146    return $this->main_photo;
147  }
148
149  /** Save the photo to disk
150   * @method savephoto
151   * @param string path where to store the file
152   * @param optional boolean thumb get the thumbnail (100x140, default) or the
153   *        bigger variant (400x600 - FALSE)
154   * @return boolean success
155   * @see IMDB person page / (Main page)
156   */
157  function savephoto ($path,$thumb=true) {
158    $req = new IMDB_Request("");
159    $photo_url = $this->photo ($thumb);
160    if (!$photo_url) return FALSE;
161    $req->setURL($photo_url);
162    $req->sendRequest();
163    if (strpos($req->getResponseHeader("Content-Type"),'image/jpeg') === 0
164      || strpos($req->getResponseHeader("Content-Type"),'image/gif') === 0
165      || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0 ){
166        $fp = $req->getResponseBody();
167    }else{
168        $this->debug_scalar("<BR>*photoerror* ".$photo_url.": Content Type is '".$req->getResponseHeader("Content-Type")."'<BR>");
169        return false;
170    }
171    $fp2 = fopen ($path, "w");
172    if ((!$fp) || (!$fp2)){
173      $this->debug_scalar("image error...<BR>");
174      return false;
175    }
176    fputs ($fp2, $fp);
177    return TRUE;
178  }
179
180  /** Get the URL for the movies cover photo
181   * @method photo_localurl
182   * @param optional boolean thumb get the thumbnail (100x140, default) or the
183   *        bigger variant (400x600 - FALSE)
184   * @return mixed url (string URL or FALSE if none)
185   * @see IMDB person page / (Main page)
186   */
187  function photo_localurl($thumb=true){
188    if ($thumb) $ext = ""; else $ext = "_big";
189    if (!is_dir($this->photodir)) {
190      $this->debug_scalar("<BR>***ERROR*** The configured image directory does not exist!<BR>");
191      return false;
192    }
193    $path = $this->photodir."nm".$this->imdbid()."${ext}.jpg";
194    if ( @fopen($path,"r")) return $this->photoroot."nm".$this->imdbid()."${ext}.jpg";
195    if (!is_writable($this->photodir)) {
196      $this->debug_scalar("<BR>***ERROR*** The configured image directory lacks write permission!<BR>");
197      return false;
198    }
199    if ($this->savephoto($path,$thumb)) return $this->photoroot."nm".$this->imdbid()."${ext}.jpg";
200    return false;
201  }
202
203 #----------------------------------------------------------[ Filmographie ]---
204  /** Get filmography
205   * @method private filmograf
206   * @param ref array where to store the filmography
207   * @param string type Which filmografie to retrieve ("actor",)
208   */
209  function filmograf(&$res,$type) {
210    if ($this->page["Name"] == "") $this->openpage ("Name","person");
211    if (preg_match("/<a name=\"$type\"(.*?)<\/div>/msi",$this->page["Name"],$match) || empty($type)) {
212      if (empty($type)) $match[1] = $this->page["Name"];
213      else $match[1] = str_replace("</li><li>","</li>\n<li>",$match[1]); // *!* ugly workaround for long lists, see Sly (mid=0000230)
214      if (preg_match_all('!<a(.*?)href="/title/tt(\d{7})/"[^>]*>(.*?)</a>(.*?)<(/li|br)>!ims',$match[1],$matches)) {
215        $mc = count($matches[0]);
216        for ($i=0;$i<$mc;++$i) {
217          preg_match('|^\s*\((\d{4})\)|',$matches[4][$i],$year);
218          $str = $matches[4][$i]; //preg_replace('|\(\d{4}\)|','',substr($matches[4][$i],0,strpos($matches[4][$i],"<br>")));
219          if ( preg_match('|<a .*href\=\"/character/ch(\d{7})\/\">(.*?)<\/a>|i',$str,$char) ) {
220            $chid   = $char[1];
221            $chname = $char[2];
222          } else {
223            $chid   = '';
224            if ( preg_match('|\.\.\.\. ([^>]+)|',$str,$char) ) $chname = $char[1];
225            else $chname = '';
226          }
227          if ( empty($chname) ) {
228            switch($type) {
229              case 'director' : $chname = 'Director'; break;
230              case 'producer' : $chname = 'Producer'; break;
231            }
232          }
233          $res[] = array("mid"=>$matches[2][$i],"name"=>$matches[3][$i],"year"=>$year[1],"chid"=>$chid,"chname"=>$chname,"addons"=>$addons[1]);
234        }
235      }
236    }
237  }
238
239  /** Get complete filmography
240   *  This method ignores the categories and tries to collect the complete
241   *  filmography. Useful e.g. for pages without categories on. It may, however,
242   *  contain duplicates if there are categories and a movie is listed in more
243   *  than one of them
244   * @method movies_all
245   * @return array array[0..n][mid,name,year,chid,chname,addons], where chid is
246   *         the character IMDB ID, chname the character name, and addons an
247   *         array of additional remarks (the things in parenthesis)
248   * @see IMDB person page / (Main page)
249   */
250  function movies_all() {
251    if (empty($this->allfilms)) $this->filmograf($this->allfilms,"");
252    return $this->allfilms;
253  }
254
255  /** Get actress filmography
256   * @method movies_actress
257   * @return array array[0..n][mid,name,year,chid,chname,addons], where chid is
258   *         the character IMDB ID, chname the character name, and addons an
259   *         array of additional remarks (the things in parenthesis)
260   * @see IMDB person page / (Main page)
261   */
262  function movies_actress() {
263     if (empty($this->actressfilms)) $this->filmograf($this->actressfilms,"actress");
264     return $this->actressfilms;
265   }
266
267  /** Get actors filmography
268   * @method movies_actor
269   * @return array array[0..n][mid,name,year,chid,chname,addons], where chid is
270   *         the character IMDB ID, chname the character name, and addons an
271   *         array of additional remarks (the things in parenthesis)
272   * @see IMDB person page / (Main page)
273   */
274  function movies_actor() {
275    if (empty($this->actorsfilms)) $this->filmograf($this->actorsfilms,"actor");
276    return $this->actorsfilms;
277  }
278
279  /** Get producers filmography
280   * @method movies_producer
281   * @return array array[0..n][mid,name,year,chid,chname,addons], where chid is
282   *         the character IMDB ID, chname the character name, and addons an
283   *         array of additional remarks (the things in parenthesis)
284   * @see IMDB person page / (Main page)
285   */
286  function movies_producer() {
287    if (empty($this->producersfilms)) $this->filmograf($this->producersfilms,"producer");
288    return $this->producersfilms;
289  }
290
291  /** Get directors filmography
292   * @method movies_director
293   * @return array array[0..n][mid,name,year]
294   * @see IMDB person page / (Main page)
295   */
296  function movies_director() {
297    if (empty($this->directorsfilms)) $this->filmograf($this->directorsfilms,"director");
298    return $this->directorsfilms;
299  }
300
301  /** Get soundtrack filmography
302   * @method movies_soundtrack
303   * @return array array[0..n][mid,name,year]
304   * @see IMDB person page / (Main page)
305   */
306  function movies_soundtrack() {
307    if (empty($this->soundtrackfilms)) $this->filmograf($this->soundtrackfilms,"soundtrack");
308    return $this->soundtrackfilms;
309  }
310
311  /** Get "Misc Crew" filmography
312   * @method movies_crew
313   * @return array array[0..n][mid,name,year]
314   * @see IMDB person page / (Main page)
315   */
316  function movies_crew() {
317    if (empty($this->crewsfilms)) $this->filmograf($this->crewsfilms,"miscellaneousX20crew");
318    return $this->crewsfilms;
319  }
320
321  /** Get "Thanx" filmography
322   * @method movies_thanx
323   * @return array array[0..n][mid,name,year]
324   * @see IMDB person page / (Main page)
325   */
326  function movies_thanx() {
327    if (empty($this->thanxfilms)) $this->filmograf($this->thanxfilms,"thanks");
328    return $this->thanxfilms;
329  }
330
331  /** Get "Self" filmography
332   * @method movies_self
333   * @return array array[0..n][mid,name,year,chid,chname], where chid is the
334   *         character IMDB ID, and chname the character name
335   * @see IMDB person page / (Main page)
336   */
337  function movies_self() {
338    if (empty($this->selffilms)) $this->filmograf($this->selffilms,"self");
339    return $this->selffilms;
340  }
341
342  /** Get "Archive Footage" filmography
343   * @method movies_archive
344   * @return array array[0..n][mid,name,year,chid,chname], where chid is the
345   *         character IMDB ID, and chname the character name
346   * @see IMDB person page / (Main page)
347   */
348  function movies_archive() {
349    if (empty($this->archivefilms)) $this->filmograf($this->archivefilms,"archive");
350    return $this->archivefilms;
351  }
352
353 #==================================================================[ /bio ]===
354 #------------------------------------------------------------[ Birth Name ]---
355 /** Get the birth name
356  * @method birthname
357  * @return string birthname
358  * @see IMDB person page /bio
359  */
360 function birthname() {
361   if (empty($this->birth_name)) {
362    if ($this->page["Bio"] == "") $this->openpage ("Bio","person");
363    if (preg_match("/Birth Name<\/h5>\s*\n(.*?)\n/m",$this->page["Bio"],$match))
364      $this->birth_name = trim($match[1]);
365   }
366   return $this->birth_name;
367 }
368
369 #-------------------------------------------------------------[ Nick Name ]---
370 /** Get the nick name
371  * @method nickname
372  * @return array nicknames array[0..n] of strings
373  * @see IMDB person page /bio
374  */
375 function nickname() {
376   if (empty($this->nick_name)) {
377    if ($this->page["Bio"] == "") $this->openpage ("Bio","person");
378    if (preg_match("/Nickname<\/h5>\s*\n(.*?)\n<h5>/ms",$this->page["Bio"],$match)) {
379      $nicks = explode("<br/>",$match[1]);
380      foreach ($nicks as $nick) {
381        $nick = trim($nick);
382        if (!empty($nick)) $this->nick_name[] = $nick;
383      }
384    }
385   }
386   return $this->nick_name;
387 }
388
389 #------------------------------------------------------------------[ Born ]---
390  /** Get Birthday
391   * @method born
392   * @return array birthday [day,month,mon,year,place]
393   *         where month is the month name, and mon the month number
394   * @see IMDB person page /bio
395   */
396  function born() {
397    if (empty($this->birthday)) {
398      if ($this->page["Bio"] == "") $this->openpage ("Bio","person");
399      if ( preg_match('|Date of Birth</h5>\s*(.*)<br|iUms',$this->page["Bio"],$match) ) {
400        preg_match('|/date/(\d+)-(\d+)/.*?>\d+\s+(.*?)<|',$match[1],$daymon);
401        preg_match('|/search/name\?birth_year=(\d{4})|ims',$match[1],$dyear);
402        preg_match('|/search/name\?birth_place=.*?">(.*)<|ims',$match[1],$dloc);
403        $this->birthday = array("day"=>$daymon[2],"month"=>$daymon[3],"mon"=>$$daymon[1],"year"=>$dyear[1],"place"=>$dloc[1]);
404      }
405    }
406    return $this->birthday;
407  }
408
409 #------------------------------------------------------------------[ Died ]---
410  /** Get Deathday
411   * @method died
412   * @return array deathday [day,month.mon,year,place,cause]
413   *         where month is the month name, and mon the month number
414   * @see IMDB person page /bio
415   */
416  function died() {
417    if (empty($this->deathday)) {
418      if ($this->page["Bio"] == "") $this->openpage ("Bio","person");
419      if (preg_match('|Date of Death</h5>(.*)<br|iUms',$this->page["Bio"],$match)) {
420        preg_match('|/date/(\d+)-(\d+)/.*?>\d+\s+(.*?)<|',$match[1],$daymon);
421        preg_match('|/search/name\?death_date=(\d{4})|ims',$match[1],$dyear);
422        preg_match('/(\,\s*([^\(]+))/ims',$match[1],$dloc);
423        preg_match('/\(([^\)]+)\)/ims',$match[1],$dcause);
424        $this->deathday = array("day"=>$daymon[2],"month"=>$daymon[3],"mon"=>$daymon[1],"year"=>$dyear[1],"place"=>$dloc[2],"cause"=>$dcause[1]);
425      }
426    }
427    return $this->deathday;
428  }
429
430 #-----------------------------------------------------------[ Body Height ]---
431 /** Get the body height
432  * @method height
433  * @return array [imperial,metric] height in feet and inch (imperial) an meters (metric)
434  * @see IMDB person page /bio
435  */
436 function height() {
437   if (empty($this->bodyheight)) {
438    if ($this->page["Bio"] == "") $this->openpage ("Bio","person");
439    if (preg_match("/Height<\/h5>\s*\n(.*?)\s*\((.*?)\)/m",$this->page["Bio"],$match)) {
440      $this->bodyheight["imperial"] = trim($match[1]);
441      $this->bodyheight["metric"] = trim($match[2]);
442    }
443   }
444   return $this->bodyheight;
445 }
446
447 #----------------------------------------------------------------[ Spouse ]---
448 /** Get spouse(s)
449  * @method spouse
450  * @return array [0..n] of array spouses [string imdb, string name, array from,
451  *         array to, string comment, string children], where from/to are array
452  *         [day,month,mon,year] (month is the name, mon the number of the month),
453  *         comment usually is "divorced" (ouch), children is the number of children
454  * @see IMDB person page /bio
455  */
456 function spouse() {
457   if (empty($this->spouses)) {
458     if ($this->page["Bio"] == "") $this->openpage ("Bio","person");
459     $pos_s = strpos($this->page["Bio"],"<h5>Spouse</h5>");
460     if (!$pos_s) return $this->spouses;
461     $pos_e = strpos($this->page["Bio"],"</table>",$pos_s);
462     $block = substr($this->page["Bio"],$pos_s,$pos_e - $pos_s +8);
463     if (@preg_match_all("/<tr>.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>/ms",$block,$matches)) { // table lines
464       $mc = count($matches[0]);
465       for ($i=0;$i<$mc;++$i) {
466         unset($tmp);
467         if (preg_match("/href\=\"\/name\/nm(\d{7})\/\">(.*?)<\/a>/i",$matches[1][$i],$match)) { // col#1: MID + name
468           $tmp["imdb"] = trim($match[1]);
469           $tmp["name"] = trim($match[2]);
470         } else {
471           $tmp["name"] = trim($matches[1][$i]);
472         }
473#         if (preg_match("/href\=\"\/OnThisDay\?day\=(\d{1,2}).{1,5}month\=(.*?)\".*\"\/MarriedInYear\?(\d{4})\"/",$matches[2][$i],$match)) { // col#2: date (from)
474#         if (preg_match("/href\=\"\/OnThisDay\?day\=(\d{1,2}).{1,5}month\=(.*?)\".*\"\/MarriedInYear\?(\d{4})\">\d{4}<\/a>(.* href\=\"\/OnThisDay\?day=(\d{1,2}).{1,5}month=(.*?)\".*<\/a>\s*(\d{4})|)/",$matches[2][$i],$match)) { // col#2: date from + to
475#         if (preg_match("/href\=\"\/OnThisDay\?day\=(\d{1,2}).{1,5}month\=(.*?)\".*\"\/MarriedInYear\?(\d{4})\">\d{4}<\/a>(.* href\=\"\/OnThisDay\?day=(\d{1,2}).{1,5}month=(.*?)\".*<\/a>\s*(\d{4})\)|)\s*\((.*?)\)/",$matches[2][$i],$match)) { // col#2: date, comment
476         if (preg_match("/href\=\"\/OnThisDay\?day\=(\d{1,2}).{1,5}month\=(.*?)\".*\"\/MarriedInYear\?(\d{4})\">\d{4}<\/a>(.* href\=\"\/OnThisDay\?day=(\d{1,2}).{1,5}month=(.*?)\".*<\/a>\s*(\d{4})\)|)\s*\((.*?)\)(\s*(\d+) child|)/",$matches[2][$i],$match)) { // col#2: date, children
477           $tmp["from"] = array("day"=>$match[1],"month"=>$match[2],"mon"=>$this->monthNo($match[2]),"year"=>$match[3]);
478           $tmp["to"]   = array("day"=>$match[5],"month"=>$match[6],"mon"=>$this->monthNo($match[6]),"year"=>$match[7]);
479           $tmp["comment"] = $match[8];
480           $tmp["children"] = $match[10];
481         }
482         $this->spouses[] = $tmp;
483       }
484     }
485   }
486   return $this->spouses;
487 }
488
489 #---------------------------------------------------------------[ MiniBio ]---
490 /** Get the person's mini bio
491  * @method bio
492  * @return array bio array [0..n] of array[string desc, array author[url,name]]
493  * @see IMDB person page /bio
494  */
495  function bio () {
496   if (empty($this->bio_bio)) {
497     if ( $this->page["Bio"] == "" ) $this->openpage ("Bio","person");
498     if ( $this->page["Bio"] == "cannot open page" ) return array(); // no such page
499     if (@preg_match_all('|<h5>Mini Biography</h5>\s*(.+)\s+.+\s+(.+)|',$this->page["Bio"],$matches)) {
500       for ($i=0;$i<count($matches[0]);++$i) {
501         $bio_bio["desc"] = str_replace("href=\"/name/nm","href=\"http://".$this->imdbsite."/name/nm",
502                              str_replace("href=\"/title/tt","href=\"http://".$this->imdbsite."/title/tt",
503                                str_replace('/SearchBios','http://'.$this->imdbsite.'/SearchBios',$matches[1][$i])));
504         $author = 'Written by '.(str_replace('/SearchBios','http://'.$this->imdbsite.'/SearchBios',$matches[2][$i]));
505         if (@preg_match("/href\=\"(.*?)\">(.*?)<\/a>/",$author,$match)) {
506           $bio_bio["author"]["url"]  = $match[1][$i];
507           $bio_bio["author"]["name"] = $match[2][$i];
508         }
509         $this->bio_bio[] = $bio_bio;
510         unset($bio_bio,$author);
511       }
512     }
513   }
514   return $this->bio_bio;
515  }
516
517 #-----------------------------------------[ Helper to Trivia, Quotes, ... ]---
518  /** Parse Trivia, Quotes, etc (same structs)
519   * @method private parparse
520   * @param string name
521   * @param ref array res
522   */
523  function parparse($name,&$res) {
524    if ( $this->page["Bio"] == "" ) $this->openpage ("Bio","person");
525    $pos_s = strpos($this->page["Bio"],"<h5>$name</h5>");
526    $pos_e = strpos($this->page["Bio"],"<br",$pos_s);
527    $block = substr($this->page["Bio"],$pos_s,$pos_e - $pos_s);
528    if (preg_match_all("/<p>(.*?)<\/p>/ms",$block,$matches))
529      foreach ($matches[1] as $match)
530        $res[] = str_replace('href="/name/nm', 'href="http://'.$this->imdbsite.'/name/nm',
531                 str_replace('href="/title/tt','href="http://'.$this->imdbsite.'/title/tt',$match));
532  }
533
534 #----------------------------------------------------------------[ Trivia ]---
535  /** Get the Trivia
536   * @method trivia
537   * @return array trivia array[0..n] of string
538   * @see IMDB person page /bio
539   */
540  function trivia() {
541    if (empty($this->bio_trivia)) $this->parparse("Trivia",$this->bio_trivia);
542    return $this->bio_trivia;
543  }
544
545 #----------------------------------------------------------------[ Quotes ]---
546  /** Get the Personal Quotes
547   * @method quotes
548   * @return array quotes array[0..n] of string
549   * @see IMDB person page /bio
550   */
551  function quotes() {
552    if (empty($this->bio_quotes)) $this->parparse("Personal Quotes",$this->bio_quotes);
553    return $this->bio_quotes;
554  }
555
556 #------------------------------------------------------------[ Trademarks ]---
557  /** Get the "trademarks" of the person
558   * @method trademark
559   * @return array trademarks array[0..n] of strings
560   * @see IMDB person page /bio
561   */
562  function trademark() {
563    if (empty($this->bio_tm)) $this->parparse("Trade Mark",$this->bio_tm);
564    return $this->bio_tm;
565  }
566
567 #----------------------------------------------------------------[ Salary ]---
568  /** Get the salary list
569   * @method salary
570   * @return array salary array[0..n] of array movie[strings imdb,name,year], string salary
571   * @see IMDB person page /bio
572   */
573  function salary() {
574    if (empty($this->bio_salary)) {
575      if ( $this->page["Bio"] == "" ) $this->openpage ("Bio","person");
576      $pos_s = strpos($this->page["Bio"],"<h5>Salary</h5>");
577      if (!$pos_s) return $this->bio_salary;
578      $pos_e = strpos($this->page["Bio"],"</table",$pos_s);
579      $block = substr($this->page["Bio"],$pos_s,$pos_e - $pos_s);
580      if (preg_match_all("/<tr.*?<td.*?>(.*?)<\/td>.*?<td.*?>(.*?)<\/td>/ms",$block,$matches)) { // for each table row
581        $mc = count($matches[0]);
582        for ($i=0;$i<$mc;++$i) {
583          if (preg_match("/\/title\/tt(\d{7})\/\">(.*?)<\/a>\s*\((\d{4})\)/",$matches[1][$i],$match)) {
584            $movie["imdb"] = $match[1];
585            $movie["name"] = $match[2];
586            $movie["year"] = $match[3];
587          } else {
588            $movie["name"] = $matches[1][$i];
589          }
590          $this->bio_salary[] = array("movie"=>$movie,"salary"=>$matches[2][$i]);
591        }
592      }
593    }
594    return $this->bio_salary;
595  }
596
597 #============================================================[ /publicity ]===
598 #-----------------------------------------------------------[ Print media ]---
599  /** Print media about this person
600   * @method pubprints
601   * @return array prints array[0..n] of array[author,title,place,publisher,year,isbn,url],
602   *         where "place" refers to the place of publication, and "url" is a link to the ISBN
603   * @see IMDB person page /publicity
604   */
605  function pubprints() {
606    if (empty($this->pub_prints)) {
607      if ( $this->page["Publicity"] == "" ) $this->openpage ("Publicity","person");
608      $pos_s = strpos($this->page["Publicity"],"<h5>Biography (print)</h5>");
609      $pos_e = strpos($this->page["Publicity"],"<br",$pos_s);
610      $block = substr($this->page["Publicity"],$pos_s,$pos_e - $pos_s);
611      $arr = explode("<p>",$block);
612      $pc = count($arr);
613      for ($i=1;$i<$pc;++$i) {
614        if (preg_match('/(.*).\s*<i>(.*)<\/i>\s*((.*):|)((.*),|)\s*((\d+)\.|)\s*ISBN\s*<a href="(.*)">(.*)<\/a>/iU',$arr[$i],$match)) {
615          $this->pub_prints[] = array("author"=>$match[1],"title"=>$match[2],"place"=>trim($match[4]),"publisher"=>trim($match[6]),"year"=>$match[8],"isbn"=>$match[10],"url"=>$match[9]);
616        } elseif (preg_match('/(.*).\s*<i>(.*)<\/i>\s*((.*):|)((.*),|)\s*((\d+)\.)/iU',$arr[$i],$match)) {
617          $this->pub_prints[] = array("author"=>$match[1],"title"=>$match[2],"place"=>trim($match[4]),"publisher"=>trim($match[6]),"year"=>$match[8],"isbn"=>"","url"=>"");
618        }
619      }
620    }
621    return $this->pub_prints;
622  }
623
624 #----------------------------------------------[ Helper for movie parsing ]---
625  /** Parse movie helper
626   * @method private parsepubmovies
627   * @param ref array res where to store the results
628   * @param string page name of the page
629   * @param string header header of the block on the IMDB site
630   * @brief helper to pubmovies() and portrayedmovies()
631   */
632  function parsepubmovies(&$res,$page,$header) {
633    if ( $this->page[$page] == "" ) $this->openpage ($page,"person");
634    $pos_s = strpos($this->page[$page],"<h5>$header</h5>");
635    $pos_e = strpos($this->page[$page],"<h5",$pos_s+5);
636    $skip  = strlen($header)+9;
637    $block = substr($this->page[$page],$pos_s+$skip,$pos_e - $pos_s -$skip);
638    $arr = explode("<br/><br/>",$block);
639    $pc = count($arr);
640    for ($i=0;$i<$pc;++$i) {
641      if (preg_match('/href="\/title\/tt(\d+)\/">(.*)<\/a>\s*(\((\d+)\)|)/',$arr[$i],$match)) {
642        $res[] = array("imdb"=>$match[1],"name"=>$match[2],"year"=>$match[4]);
643      }
644    }
645 }
646
647 #----------------------------------------------------[ Biographical movies ]---
648  /** Biographical Movies
649   * @method pubmovies
650   * @return array pubmovies array[0..n] of array[imdb,name,year]
651   * @see IMDB person page /publicity
652   */
653  function pubmovies() {
654    if (empty($this->pub_movies)) $this->parsepubmovies($this->pub_movies,"Publicity","Biographical movies");
655    return $this->pub_movies;
656  }
657
658 #-----------------------------------------------------------[ Portrayed in ]---
659  /** List of movies protraying the person
660   * @method pubportraits
661   * @return array pubmovies array[0..n] of array[imdb,name,year]
662   * @see IMDB person page /publicity
663   */
664  function pubportraits() {
665    if (empty($this->pub_portraits)) $this->parsepubmovies($this->pub_portraits,"Publicity","Portrayed in");
666    return $this->pub_portraits;
667  }
668
669 #--------------------------------------------[ Helper for Article parsing ]---
670  /** Helper for article parsing
671   * @method private parsearticles
672   * @param ref array res where to store the results
673   * @param string page name of the page
674   * @param string title title of the block
675   * @brief used by interviews(), articles()
676   * @see IMDB person page /publicity
677   */
678  function parsearticles(&$res,$page,$title) {
679    if ( $this->page[$page] == "" ) $this->openpage ($page,"person");
680    $pos_s = strpos($this->page[$page],"<h5>$title</h5>");
681    $pos_e = strpos($this->page[$page],"</table",$pos_s);
682    $block = substr($this->page[$page],$pos_s,$pos_e-$pos_s);
683    @preg_match_all("|<tr>(.*)</tr>|iU",$block,$matches); // get the rows
684    $lc = count($matches[0]);
685    for ($i=0;$i<$lc;++$i) {
686      if (@preg_match('/href="(.*)">(.*)<\/a>.*valign="top">(.*),\s*(.*|)(,\s*by.*"author" href="(.*)">(.*)|)</iU',$matches[1][$i],$match)) {
687        @preg_match('/(\d{1,2}|)\s*(\S+|)\s*(\d{4}|)/i',$match[3],$dat);
688        $datum = array("day"=>$dat[1],"month"=>trim($dat[2]),"mon"=>$this->monthNo(trim($dat[2])),"year"=>trim($dat[3]),"full"=>$match[3]);
689        $res[] = array("inturl"=>$match[1],"name"=>$match[2],"date"=>$datum,"details"=>trim($match[4]),"auturl"=>$match[6],"author"=>$match[7]);
690      }
691    }
692  }
693
694 #-------------------------------------------------------------[ Interviews ]---
695  /** Interviews
696   * @method interviews
697   * @return array interviews array[0..n] of array[inturl,name,date,details,auturl,author]
698   *         where all elements are strings - just date is an array[day,month,mon,year,full]
699   *         (full: as displayed on the IMDB site)
700   * @see IMDB person page /publicity
701   */
702  function interviews() {
703    if (empty($this->pub_interviews)) $this->parsearticles($this->pub_interviews,"Publicity","Interview");
704    return $this->pub_interviews;
705  }
706
707 #--------------------------------------------------------------[ Articles ]---
708  /** Articles
709   * @method articles
710   * @return array articles array[0..n] of array[inturl,name,date,details,auturl,author]
711   *         where all elements are strings - just date is an array[day,month,mon,year,full]
712   *         (full: as displayed on the IMDB site)
713   * @see IMDB person page /publicity
714   */
715  function articles() {
716    if (empty($this->pub_articles)) $this->parsearticles($this->pub_articles,"Publicity","Article");
717    return $this->pub_articles;
718  }
719
720 #--------------------------------------------------------------[ Articles ]---
721  /** Pictorials
722   * @method pictorials
723   * @return array pictorials array[0..n] of array[inturl,name,date,details,auturl,author]
724   *         where all elements are strings - just date is an array[day,month,mon,year,full]
725   *         (full: as displayed on the IMDB site)
726   * @see IMDB person page /publicity
727   */
728  function pictorials() {
729    if (empty($this->pub_pictorials)) $this->parsearticles($this->pub_pictorials,"Publicity","Pictorial");
730    return $this->pub_pictorials;
731  }
732
733 #--------------------------------------------------------------[ Articles ]---
734  /** Magazine cover photos
735   * @method magcovers
736   * @return array magcovers array[0..n] of array[inturl,name,date,details,auturl,author]
737   *         where all elements are strings - just date is an array[day,month,mon,year,full]
738   *         (full: as displayed on the IMDB site)
739   * @see IMDB person page /publicity
740   */
741  function magcovers() {
742    if (empty($this->pub_magcovers)) $this->parsearticles($this->pub_magcovers,"Publicity","Magazine cover photo");
743    return $this->pub_magcovers;
744  }
745
746 #---------------------------------------------------------[ Search Details ]---
747  /** Set some search details
748   * @method setSearchDetails
749   * @param string role
750   * @param integer mid IMDB ID
751   * @param string name movie-name
752   * @param integer year
753   */
754  function setSearchDetails($role,$mid,$name,$year) {
755    $this->SearchDetails = array("role"=>$role,"mid"=>$mid,"moviename"=>$name,"year"=>$year);
756  }
757  /** Get the search details
758   *  They are just set when the imdb_person object has been initialized by the
759   *  imdbpsearch class
760   * @method getSearchDetails
761   * @return array SearchDetails (mid,name,role,moviename,year)
762   */
763  function getSearchDetails() {
764    return $this->SearchDetails;
765  }
766
767 } // end class imdb_person
768
769 #==========================================[ The IMDB Person search class ]===
770 /** Searching IMDB staff information
771  * @package Api
772  * @class imdbpsearch
773  * @extends imdbsearch
774  * @author Izzy (izzysoft AT qumran DOT org)
775  * @copyright 2008-2009 by Itzchak Rehberg and IzzySoft
776  * @version $Revision$ $Date$
777  */
778 class imdbpsearch extends imdbsearch {
779 #-----------------------------------------------------------[ Constructor ]---
780  /** Initialize class (read config etc.)
781   * @constructor imdbpsearch
782   */
783   function imdbpsearch() {
784     $this->imdbsearch();
785   }
786
787 #-------------------------------------------------------[ private helpers ]---
788  /** Create the IMDB URL for the name search
789   * @method private mkurl
790   * @return string url
791   */
792  function mkurl () {
793   if ($this->url !== NULL) {
794    $url = $this->url;
795   } else {
796     $query = ";s=nm";
797     if (!isset($this->maxresults)) $this->maxresults = 20;
798     if ($this->maxresults > 0) $query .= ";mx=20";
799     $url = "http://".$this->imdbsite."/find?q=".urlencode($this->name).$query;
800   }
801   return $url;
802  }
803
804 #-----------------------------------------------------------[ get results ]---
805  /** Setup search results
806   * @method results
807   * @param optional string URL Replace search URL by your own
808   * @return array results array of objects (instances of the imdb_person class)
809   */
810  function results ($url="") {
811   if ($this->page == "") {
812     if (empty($url)) $url = $this->mkurl();
813     $be = new IMDB_Request($url);
814     $be->sendrequest();
815     $fp = $be->getResponseBody();
816     if ( !$fp ){
817       if ($header = $be->getResponseHeader("Location")){
818        if (strpos($header,$this->imdbsite."/find?")) {
819          return $this->results($header);
820          break(4);
821        }
822        $url = explode("/",$header);
823        $id  = substr($url[count($url)-2],2);
824        $this->resu[0] = new imdb_person($id);
825        return $this->resu;
826       }else{
827        return NULL;
828       }
829     }
830     $this->page = $fp;
831   } // end (page="")
832
833   if ($this->maxresults > 0) $maxresults = $this->maxresults; else $maxresults = 999999;
834   // make sure to catch col #3, not #1 (pic only)
835   preg_match_all('|<tr>\s*<td.*>.*</td>\s*<td.*>.*</td>\s*<td.*<a href="/name/nm(\d{7})[^>]*>([^<]+)</a>(.*)</td>|Uims',$this->page,$matches);
836   $mc = count($matches[0]);
837   $mids_checked = array();
838   for ($i=0;$i<$mc;++$i) {
839     if ($i == $maxresults) break; // limit result count
840     $pid = $matches[1][$i];
841     if (in_array($pid,$mids_checked)) continue;
842     $mids_checked[] = $pid;
843     $name    = $matches[2][$i];
844     $info    = $matches[3][$i];
845     $tmpres  = new imdb_person($pid);
846     $tmpres->fullname = $name;
847     if (!empty($info)) {
848       if (preg_match('|<small>\((.*),\s*<a href="/title/tt(\d{7})/">(.*)</a>\s*\((\d{4})\)\)|Ui',$info,$match)) {
849         $role = $match[1];
850         $mid  = $match[2];
851         $movie= $match[3];
852         $year = $match[4];
853         $tmpres->setSearchDetails($role,$mid,$movie,$year);
854       }
855     }
856     $this->resu[$i] = $tmpres;
857     unset($tmpres);
858   }
859   return $this->resu;
860  }
861 }
862
863?>
Note: See TracBrowser for help on using the browser.