Ejemplo n.º 1
0
 /**
  * @param $url
  * @param $destination
  * @return bool|null
  */
 public function fetch($url, $destination)
 {
     try {
         $ret = null;
         $url = $this->addhttp($url);
         $ch = curl_init($url . '/favicon.ico');
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         $contents = curl_exec($ch);
         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         if ($httpCode == 200) {
             $fp = fopen($destination, 'w+');
             fwrite($fp, $contents);
             fclose($fp);
             $ret = true;
             if ($this->converter) {
                 $ret = $this->converter->convert($destination);
             }
         }
         curl_close($ch);
         return $ret;
     } catch (\Exception $e) {
         // hmm ok, let the next Fetcher try its luck
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function fetch($url, $destination)
 {
     /* needs fully quallified url e.q with http:// */
     if ($this->skipDefaultImage) {
         $url .= '?defaulticon=none';
         //        none: no default icon will be returned (and an HTTP 204 "No content" response code)
     }
     try {
         $ch = parent::fetch($url, $destination);
         if ($ch && $this->converter) {
             //convert to png
             return $this->converter->convert($destination);
         }
         return $ch;
     } catch (\Exception $e) {
         // hmm ok, let the next Fetcher try its luck
     }
     return null;
 }