コード例 #1
0
 /** Constructor: Obtain the raw data from IMDB site
  * @constructor imdb_nowplaying
  */
 function __construct()
 {
     $req = new MDB_Request($this->nowplayingpage);
     $req->sendRequest();
     $this->page = $req->getResponseBody();
     $this->revision = preg_replace('|^.*?(\\d+).*$|', '$1', '$Revision: 471 $');
 }
コード例 #2
0
 /** Constructor: Get data from the charts page
  * @constructor imdb_topcharts
  */
 function imdb_topcharts()
 {
     $req = new MDB_Request($this->chartspage);
     $req->sendRequest();
     $this->page = $req->getResponseBody();
     $this->revision = preg_replace('|^.*?(\\d+).*$|', '$1', '$Revision: 269 $');
 }
コード例 #3
0
 /**
  * Constructor: Get data from the charts page
  * @constructor imdb_topcharts
  * @param optional object mdb_config override default config
  */
 function __construct(mdb_config $config = null)
 {
     $req = new MDB_Request($this->chartspage, $config);
     $req->sendRequest();
     $this->page = $req->getResponseBody();
     $this->revision = preg_replace('|^.*?(\\d+).*$|', '$1', '$Revision: 691 $');
 }
コード例 #4
0
 protected function getPage($page, array $context = array())
 {
     if (!empty($this->page[$page])) {
         return $this->page[$page];
     }
     $url = "http://" . $this->imdbsite . $this->set_pagename($page, $context);
     $req = new MDB_Request($url, $this);
     if (!$req->sendRequest()) {
         $this->logger->error("[Page] Failed to connect to server when requesting url [{$url}]");
     } else {
         $this->page[$page] = $req->getResponseBody();
     }
     return $this->page[$page];
 }
コード例 #5
0
ファイル: imdb_page.class.php プロジェクト: Karpec/gizd
 /**
  * Request the page from IMDb
  * @param $url
  * @return string Page html. Empty string on failure
  */
 protected function requestPage($url)
 {
     $this->logger->info("[Page] Requesting [{$url}]");
     $req = new MDB_Request($url, $this->config);
     if (!$req->sendRequest()) {
         $this->logger->error("[Page] Failed to connect to server when requesting url [{$url}]");
         return '';
     }
     if (200 == $req->getStatus()) {
         return $req->getResponseBody();
     } elseif ($redirectUrl = $req->getRedirect()) {
         $this->logger->debug("[Page] Following redirect from [{$url}] to [{$redirectUrl}]");
         return $this->requestPage($redirectUrl);
     } else {
         $this->logger->error("[Page] Failed to retrieve url [{url}]. Response headers:{headers}", array('url' => $url, 'headers' => $req->getLastResponseHeaders()));
         return '';
     }
 }
コード例 #6
0
 /** Save the photo to disk
  * @method savephoto
  * @param string path where to store the file
  * @param optional boolean thumb get the thumbnail (100x140, default) or the
  *        bigger variant (400x600 - FALSE)
  * @return boolean success
  * @see IMDB person page / (Main page)
  */
 public function savephoto($path, $thumb = true)
 {
     $req = new MDB_Request("");
     $photo_url = $this->photo($thumb);
     if (!$photo_url) {
         return FALSE;
     }
     $req->setURL($photo_url);
     $req->sendRequest();
     if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) {
         $fp = $req->getResponseBody();
     } else {
         $this->debug_scalar("<BR>*photoerror* " . $photo_url . ": Content Type is '" . $req->getResponseHeader("Content-Type") . "'<BR>");
         return false;
     }
     $fp2 = fopen($path, "w");
     if (!$fp || !$fp2) {
         $this->debug_scalar("image error...<BR>");
         return false;
     }
     fputs($fp2, $fp);
     return TRUE;
 }
コード例 #7
0
 /** Convert IMDB redirect-URLs of external sites to real URLs
  * @method convertIMDBtoRealURL
  * @param string url redirect-url
  * @return string url real-url
  */
 protected function convertIMDBtoRealURL($url)
 {
     if (preg_match('/^http:\\/\\//', $url)) {
         return $url;
     }
     $req = new MDB_Request("");
     $req->setURL("http://" . $this->imdbsite . $url);
     if ($req->sendRequest() !== FALSE) {
         $head = $req->getLastResponseHeaders();
         foreach ($head as $header) {
             if (preg_match('/:/', $header)) {
                 list($type, $value) = explode(':', $header, 2);
                 if ($type == 'Location') {
                     return preg_replace('/\\s/', '', $value);
                 }
             }
         }
     }
     return false;
 }
コード例 #8
0
 /** Save the photo to disk
  * @method savephoto
  * @param string path where to store the file
  * @param optional boolean thumb get the thumbnail (100x140, default) or the
  *        bigger variant (400x600 - FALSE)
  * @return boolean success
  * @see IMDB person page / (Main page)
  */
 public function savephoto($path, $thumb = TRUE, $rerun = FALSE)
 {
     if ($rerun) {
         $req = new MDB_Request('', '', !$this->trigger_referer);
     } else {
         $req = new MDB_Request('', '', $this->trigger_referer);
     }
     $photo_url = $this->photo($thumb);
     if (!$photo_url) {
         return FALSE;
     }
     $req->setURL($photo_url);
     $req->sendRequest();
     if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) {
         $fp = $req->getResponseBody();
     } else {
         if ($rerun) {
             $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '" . $req->getResponseHeader("Content-Type") . "'<BR>");
             return FALSE;
         } else {
             $this->debug_scalar("<BR>Initiate second run for photo '{$path}'<BR>");
             return $this->savephoto($path, $thumb, TRUE);
         }
     }
     $fp2 = fopen($path, "w");
     if (!$fp || !$fp2) {
         $this->debug_scalar("image error...<BR>");
         return false;
     }
     fputs($fp2, $fp);
     return TRUE;
 }
コード例 #9
0
 /** Obtain page from web server
  * @method protected getWebPage
  * @param string wt internal name of the page
  * @param string url URL to open
  */
 protected function getWebPage($wt, $url)
 {
     $req = new MDB_Request("");
     $req->setURL($url);
     if ($req->sendRequest() !== FALSE) {
         $head = $req->getLastResponseHeaders();
     } else {
         $head[0] = "HTTP/1.1 000";
     }
     $response = explode(" ", $head[0]);
     $this->lastServerResponse = $response[1];
     switch (substr($head[0], 0, 12)) {
         case "HTTP/1.1 000":
             $this->page[$wt] = "cannot open page";
             $this->debug_scalar("cannot open page (could not connect to host): {$url}");
             return false;
             break;
         case "HTTP/1.1 404":
             $this->page[$wt] = "cannot open page";
             $this->debug_scalar("cannot open page (error 404): {$url}");
             $this->debug_object($response);
             return false;
             break;
         case "HTTP/1.1 301":
             // permanent redirect
         // permanent redirect
         case "HTTP/1.1 302":
             // found
         // found
         case "HTTP/1.1 303":
             // see other
         // see other
         case "HTTP/1.1 307":
             // temporary redirect
             // in all these cases, the correct URL is to be found in the 'Location:' header
             foreach ($head as $headline) {
                 if (strpos(trim(strtolower($headline)), 'location') !== 0) {
                     continue;
                 }
                 $aline = explode(': ', $headline);
                 $target = trim($aline[1]);
                 $this->getWebPage($wt, $target);
                 return;
             }
             // echo "<pre>";print_r($head);echo "</pre>\n";
             // $this->debug_object($response);
         // echo "<pre>";print_r($head);echo "</pre>\n";
         // $this->debug_object($response);
         case "HTTP/1.1 200":
             break;
         default:
             $this->debug_scalar("HTTP response code not handled explicitly: '" . $head[0] . "'");
             break;
     }
     $this->page[$wt] = $req->getResponseBody();
     if (strpos(get_class($this), 'imdb') !== FALSE && $this->imdb_utf8recode && function_exists('mb_detect_encoding')) {
         $cur_encoding = mb_detect_encoding($this->page[$wt]);
         if (!($cur_encoding == "UTF-8" && mb_check_encoding($this->page[$wt], "UTF-8"))) {
             $this->page[$wt] = utf8_encode($this->page[$wt]);
         }
     }
 }
コード例 #10
0
ファイル: imdb.class.php プロジェクト: nass600/homeCENTER
 /** Save the photo to disk
  * @method savephoto
  * @param string path where to store the file
  * @param optional boolean thumb get the thumbnail (100x140, default) or the
  *        bigger variant (400x600 - FALSE)
  * @return boolean success
  * @see IMDB page / (TitlePage)
  */
 public function savephoto($path, $thumb = true, $rerun = 0)
 {
     switch ($rerun) {
         case 2:
             $req = new MDB_Request('');
             break;
         case 1:
             $req = new MDB_Request('', '', !$this->trigger_referer);
             break;
         default:
             $req = new MDB_Request('', '', $this->trigger_referer);
             break;
     }
     $photo_url = $this->photo($thumb);
     if (!$photo_url) {
         return FALSE;
     }
     $req->setURL($photo_url);
     $req->sendRequest();
     if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) {
         $fp = $req->getResponseBody();
     } else {
         switch ($rerun) {
             case 2:
                 $ctype = $req->getResponseHeader("Content-Type");
                 $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '{$ctype}'<BR>");
                 if (substr($ctype, 0, 4) == 'text') {
                     $this->debug_scalar("Details: <PRE>" . $req->getResponseBody() . "</PRE>\n");
                 }
                 return FALSE;
                 break;
             case 1:
                 $this->debug_scalar("<BR>Initiate third run for savephoto({$path}) on IMDBID " . $this->imdbID . "<BR>");
                 unset($req);
                 return $this->savephoto($path, $thumb, 2);
                 break;
             default:
                 $this->debug_scalar("<BR>Initiate second run for savephoto({$path}) on IMDBID " . $this->imdbID . "<BR>");
                 unset($req);
                 return $this->savephoto($path, $thumb, 1);
                 break;
         }
     }
     $fp2 = fopen($path, "w");
     if (!$fp || !$fp2) {
         $this->debug_scalar("image error at " . __FILE__ . " line " . __LINE__ . "...<BR>");
         return false;
     }
     fputs($fp2, $fp);
     return TRUE;
 }
コード例 #11
0
ファイル: mdb_base.class.php プロジェクト: n4v/openTracker
 /** Obtain page from web server
  * @method private getWebPage
  * @param string wt internal name of the page
  * @param string url URL to open
  */
 function getWebPage($wt, $url)
 {
     $req = new MDB_Request("");
     $req->setURL($url);
     if ($req->sendRequest() !== FALSE) {
         $head = $req->getLastResponseHeaders();
     } else {
         $head[0] = "HTTP/1.1 000";
     }
     $response = explode(" ", $head[0]);
     $this->lastServerResponse = $response[1];
     switch (substr($head[0], 0, 12)) {
         case "HTTP/1.1 000":
             $this->page[$wt] = "cannot open page";
             $this->debug_scalar("cannot open page (could not connect to host): {$url}");
             return false;
             break;
         case "HTTP/1.1 404":
             $this->page[$wt] = "cannot open page";
             $this->debug_scalar("cannot open page (error 404): {$url}");
             return false;
             break;
         case "HTTP/1.1 301":
         case "HTTP/1.1 302":
         case "HTTP/1.1 200":
             break;
         default:
             $this->debug_scalar("HTTP response code not handled explicitly: '" . $head[0] . "'");
             break;
     }
     $this->page[$wt] = $req->getResponseBody();
     if (strpos(get_class($this), 'imdb') !== FALSE && $this->imdb_utf8recode && function_exists('mb_detect_encoding')) {
         $cur_encoding = mb_detect_encoding($this->page[$wt]);
         if (!($cur_encoding == "UTF-8" && mb_check_encoding($this->page[$wt], "UTF-8"))) {
             $this->page[$wt] = utf8_encode($this->page[$wt]);
         }
     }
 }
コード例 #12
0
 /** Retrieve trailers from azmovietrailers.com
  * @method getAZMovieTrailers
  * @param string url page url as retrieved with imdb::videosites
  * @return array [0..n] of array[url,format] of movie trailers (Flash)
  */
 function getAZMovieTrailers($url)
 {
     $req = new MDB_Request($url);
     $req->sendRequest();
     $this->page = $req->getResponseBody();
     if ($this->page == "" || $this->page == false) {
         return false;
     }
     preg_match('|flashvars\\="file\\=(http.*)\\&|iUms', $this->page, $match);
     preg_match('|\\.(.{3})$|i', $match[1], $format);
     if (!empty($match[1])) {
         return array(array("url" => $match[1], "format" => $format[1]));
     }
 }