/** 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 class)
  */
 function results($url = "")
 {
     if ($this->page == "") {
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new IMDB_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($id);
                 return $this->resu;
             } else {
                 return NULL;
             }
         }
         $this->page = $fp;
     }
     // end (page="")
     $searchstring = array('<A HREF="/title/tt', '<A href="/title/tt', '<a href="/Title?', '<a href="/title/tt');
     $i = 0;
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     foreach ($searchstring as $srch) {
         $res_e = 0;
         $res_s = 0;
         $mids_checked = array();
         $len = strlen($srch);
         while (($res_s = strpos($this->page, $srch, $res_e)) > 10) {
             if ($i == $maxresults) {
                 break 2;
             }
             // limit result count
             $res_e = strpos($this->page, "(", $res_s);
             $imdb_id = substr($this->page, $res_s + $len, 7);
             $ts = strpos($this->page, ">", $res_s) + 1;
             // >movie title</a>
             $te = strpos($this->page, "<", $ts);
             $title = substr($this->page, $ts, $te - $ts);
             if ($title == "" || in_array($imdb_id, $mids_checked)) {
                 continue;
             }
             // empty titles just come from the images
             $mids_checked[] = $imdb_id;
             $tmpres = new imdb($imdb_id);
             // make a new imdb object by id
             $tmpres->main_title = $title;
             $ts = strpos($this->page, "(", $te) + 1;
             $te = strpos($this->page, ")", $ts);
             $tmpres->main_year = substr($this->page, $ts, $te - $ts);
             $i++;
             $this->resu[$i] = $tmpres;
         }
     }
     return $this->resu;
 }
Example #2
0
 /** Setup search results
  * @method results
  * @return array results
  */
 function results($url = "")
 {
     if ($this->page == "") {
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new IMDB_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;
                 }
                 #--- @moonface variant (not tested)
                 # $idpos = strpos($header, "/Title?") + 7;
                 # $this->resu[0] = new imdb( substr($header, $idpos,7));
                 #--- end @moonface / start sevec variant
                 $url = explode("/", $header);
                 $id = substr($url[count($url) - 2], 2);
                 $this->resu[0] = new imdb($id);
                 #--- end Sevec variant
                 return $this->resu;
             } else {
                 return NULL;
             }
         }
         $this->page = $fp;
     }
     // end (page="")
     $searchstring = array('<A HREF="/title/tt', '<A href="/title/tt', '<a href="/Title?', '<a href="/title/tt');
     $i = 0;
     foreach ($searchstring as $srch) {
         $res_e = 0;
         $res_s = 0;
         $len = strlen($srch);
         while (($res_s = strpos($this->page, $srch, $res_e)) > 10) {
             $res_e = strpos($this->page, "(", $res_s);
             $tmpres = new imdb(substr($this->page, $res_s + $len, 7));
             // make a new imdb object by id
             $ts = strpos($this->page, ">", $res_s) + 1;
             // >movie title</a>
             $te = strpos($this->page, "<", $ts);
             $tmpres->main_title = substr($this->page, $ts, $te - $ts);
             $ts = strpos($this->page, "(", $te) + 1;
             $te = strpos($this->page, ")", $ts);
             $tmpres->main_year = substr($this->page, $ts, $te - $ts);
             $i++;
             $this->resu[$i] = $tmpres;
         }
     }
     return $this->resu;
 }
Example #3
0
 /** 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)
  */
 function results($url = "")
 {
     if ($this->page == "") {
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new IMDB_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;
 }