Exemple #1
0
 public function load($url)
 {
     //@todo extract url validation
     if (empty($url)) {
         throw new \Exception('Empty url');
     }
     if ($this->cached($url)) {
         $content = $this->load_cache($url);
     } else {
         $content = parent::load($url);
         if (!empty($content)) {
             $this->save_cache($url, $content);
         }
     }
     return $content;
 }
 public static function file_get_contents($fileurl, $allow_curl = TRUE)
 {
     $max_redirects = 5;
     if (defined('OEMBED_USE_CURL') && OEMBED_USE_CURL && defined('CURLOPT_URL')) {
         $ch = curl_init();
         $timeout = 5;
         // 0 wenn kein Timeout
         curl_setopt($ch, CURLOPT_URL, $fileurl);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         //curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
         //curl_setopt($ch, CURLOPT_MAXREDIRS, $max_redirects );
         //$file_content = curl_exec($ch);
         $file_content = CurlFetcher::curl_exec_follow($ch, $max_redirects);
         curl_close($ch);
     } else {
         $context = array('http' => array('method' => 'GET', 'max_redirects' => $max_redirects));
         $file_content = file_get_contents($fileurl, null, stream_context_create($context));
     }
     return $file_content;
 }
 private function file_get_contents($fileurl)
 {
     $allow_curl = defined('OEMBED_USE_CURL') && OEMBED_USE_CURL && defined('CURLOPT_URL');
     return CurlFetcher::file_get_contents($fileurl, $allow_curl);
 }
 public function testValidUrl()
 {
     $fetcher = new CurlFetcher();
     $content = $fetcher->fetch('http://httpbin.org/html');
     $this->assertContains('Herman Melville', $content);
 }