PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/library/imdb/imdb_person.class.php

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