Example #1
0
 /** Open an IMDB page
  * @method openpage
  * @param string wt
  */
 function openpage($wt)
 {
     if (strlen($this->imdbID) != 7) {
         echo "not valid imdbID: " . $this->imdbID . "<BR>" . strlen($this->imdbID);
         $this->page[$wt] = "cannot open page";
         return;
     }
     // try to block all new request
     /*$this->page[$wt] = "cannot open page";
       return;*/
     switch ($wt) {
         case "Title":
             $urlname = "/";
             break;
         case "Credits":
             $urlname = "/fullcredits";
             break;
         case "Plot":
             $urlname = "/plotsummary";
             break;
         case "Taglines":
             $urlname = "/taglines";
             break;
     }
     if ($this->usecache) {
         @($fp = fopen("{$this->cachedir}/{$this->imdbID}.{$wt}", "r"));
         if ($fp) {
             $temp = "";
             while (!feof($fp)) {
                 $temp .= fread($fp, 1024);
             }
             if ($temp) {
                 $this->page[$wt] = $temp;
                 return;
             }
         }
     }
     // end cache
     $req = new IMDB_Request("");
     $req->setURL("http://" . $this->imdbsite . "/title/tt" . $this->imdbID . $urlname);
     $response = $req->send();
     $responseBody = $response->getBody();
     if ($responseBody) {
         $this->page[$wt] = utf8_encode($responseBody);
     }
     if ($this->page[$wt]) {
         //storecache
         if ($this->storecache) {
             $fp = fopen("{$this->cachedir}/{$this->imdbID}.{$wt}", "w");
             fputs($fp, $this->page[$wt]);
             fclose($fp);
         }
         return;
     }
     $this->page[$wt] = "cannot open page";
     //echo "page not found";
 }
Example #2
0
 /** Save the photo to disk
  * @method savephoto
  * @param string path
  * @return boolean success
  */
 function savephoto($path)
 {
     $req = new IMDB_Request("");
     $photo_url = $this->photo();
     if (!$photo_url) {
         return FALSE;
     }
     $req->setUrl($photo_url);
     $response = $req->send();
     if (strpos($response->getHeader("Content-Type"), 'image/jpeg') === 0 || strpos($response->getHeader("Content-Type"), 'image/gif') === 0 || strpos($response->getHeader("Content-Type"), 'image/bmp') === 0) {
         $fp = $response->getBody();
     } else {
         //echo "<BR>*photoerror* ".$photo_url.": Content Type is '".$req->getResponseHeader("Content-Type")."'<BR>";
         return false;
     }
     $fp2 = fopen($path, "w");
     if (!$fp || !$fp2) {
         echo "image error...<BR>";
         return false;
     }
     fputs($fp2, $fp);
     return TRUE;
 }