/** Setup search results * @method results * @param optional string URL Replace search URL by your own * @return array results array of objects (instances of the imdb_person class) */ public function results($url = "") { if ($this->page == "") { if (empty($url)) { $url = $this->mkurl(); } $be = new MDB_Request($url); $be->sendrequest(); $fp = $be->getResponseBody(); if (!$fp) { if ($header = $be->getResponseHeader("Location")) { if (strpos($header, $this->imdbsite . "/find?")) { return $this->results($header); break 4; } $url = explode("/", $header); $id = substr($url[count($url) - 2], 2); $this->resu[0] = new imdb_person($id); return $this->resu; } else { return NULL; } } $this->page = $fp; } // end (page="") if ($this->maxresults > 0) { $maxresults = $this->maxresults; } else { $maxresults = 999999; } // make sure to catch col #3, not #1 (pic only) preg_match_all('|<tr>\\s*<td.*>.*</td>\\s*<td.*>.*</td>\\s*<td.*<a href="/name/nm(\\d{7})[^>]*>([^<]+)</a>(.*)</td>|Uims', $this->page, $matches); $mc = count($matches[0]); $mids_checked = array(); for ($i = 0; $i < $mc; ++$i) { if ($i == $maxresults) { break; } // limit result count $pid = $matches[1][$i]; if (in_array($pid, $mids_checked)) { continue; } $mids_checked[] = $pid; $name = $matches[2][$i]; $info = $matches[3][$i]; $tmpres = new imdb_person($pid); $tmpres->fullname = $name; if (!empty($info)) { if (preg_match('|<small>\\((.*),\\s*<a href="/title/tt(\\d{7})/">(.*)</a>\\s*\\((\\d{4})\\)\\)|Ui', $info, $match)) { $role = $match[1]; $mid = $match[2]; $movie = $match[3]; $year = $match[4]; $tmpres->setSearchDetails($role, $mid, $movie, $year); } } $this->resu[$i] = $tmpres; unset($tmpres); } return $this->resu; }
/** * Setup search results * @method results * @param optional string URL Replace search URL by your own * @return array results array of objects (instances of the imdb_person class) */ public function results($url = "") { if ($this->page == "") { if ($this->usecache && empty($url)) { // Try to read from cache $this->cache_read(urlencode(strtolower($this->name)) . '.search', $this->page); } // end cache read if (empty($url)) { $url = $this->mkurl(); } $be = new MDB_Request($url, $this); $be->sendrequest(); $fp = $be->getResponseBody(); if (!$fp) { if ($header = $be->getResponseHeader("Location")) { mdb_base::debug_scalar("No immediate response body - we are redirected.<br>New URL: {$header}"); if (strpos($header, $this->imdbsite . "/find?")) { return $this->results($header); break 4; } $url = explode("/", $header); $id = substr($url[count($url) - 2], 2); $this->resu[0] = new imdb_person($id, $this); return $this->resu; } else { mdb_base::debug_scalar("No result, no redirection -- something's wrong here..."); return NULL; } } $this->page = $fp; if ($this->storecache && $this->page != "cannot open page" && $this->page != "") { //store cache $this->cache_write(urlencode(strtolower($this->name)) . '.search', $this->page); } } // end (page="") if ($this->maxresults > 0) { $maxresults = $this->maxresults; } else { $maxresults = 999999; } // make sure to catch col #3, not #1 (pic only) // photo name 1=id 2=name 3=details preg_match_all('|<tr.*>\\s*<td.*>.*</td>\\s*<td.*<a href="/name/nm(\\d{7})[^>]*>([^<]+)</a>\\s*(.*)</td>|Uims', $this->page, $matches); $mc = count($matches[0]); mdb_base::debug_scalar("{$mc} matches"); $mids_checked = array(); for ($i = 0; $i < $mc; ++$i) { if ($i == $maxresults) { break; } // limit result count $pid = $matches[1][$i]; if (in_array($pid, $mids_checked)) { continue; } $mids_checked[] = $pid; $name = $matches[2][$i]; $info = $matches[3][$i]; $tmpres = new imdb_person($pid); $tmpres->fullname = $name; if (!empty($info)) { if (preg_match('|<small>\\((.*),\\s*<a href="/title/tt(\\d{7}).*"\\s*>(.*)</a>\\s*\\((\\d{4})\\)\\)|Ui', $info, $match)) { $role = $match[1]; $mid = $match[2]; $movie = $match[3]; $year = $match[4]; $tmpres->setSearchDetails($role, $mid, $movie, $year); } } $this->resu[$i] = $tmpres; unset($tmpres); } return $this->resu; }