]> git.mxchange.org Git - friendica.git/commitdiff
oembed: don't try to fetch media files and add Accept request header to fetch_url
authorFabio Comuni <fabrix.xm@gmail.com>
Thu, 17 Nov 2011 12:40:11 +0000 (13:40 +0100)
committerFabio Comuni <fabrix.xm@gmail.com>
Thu, 17 Nov 2011 12:40:11 +0000 (13:40 +0100)
include/network.php
include/oembed.php

index a9ee3f0a54deece8d4624e337c8569a758a0a448..e89eb94da24dc5b26c042a75a76b8b1cb8efb9a3 100644 (file)
@@ -5,7 +5,7 @@
 // results. 
 
 if(! function_exists('fetch_url')) {
-function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0) {
+function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
 
        $a = get_app();
 
@@ -14,9 +14,17 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0) {
                return false;
 
        @curl_setopt($ch, CURLOPT_HEADER, true);
+       
+       if (!is_null($accept_content)){
+               curl_setopt($ch,CURLOPT_HTTPHEADER, array (
+                       "Accept: "+$accept_content
+               ));
+       }
+       
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        @curl_setopt($ch, CURLOPT_USERAGENT, "Friendika");
 
+
        if(intval($timeout)) {
                @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        }
index 7c0da459409c2859ac543cfa88cf79f6a4450cf4..118f7fa4a39f45fdb5b91819f864f199df40365b 100644 (file)
@@ -13,24 +13,30 @@ function oembed_replacecb($matches){
 function oembed_fetch_url($embedurl){
        
        $txt = Cache::get($embedurl);
+
+       $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm");
+       $ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION);
+       
                                
        if(is_null($txt)){
                $txt = "";
                
-               // try oembed autodiscovery
-               $redirects = 0;
-               $html_text = fetch_url($embedurl, false, $redirects, 15);
-               if($html_text){
-                       $dom = @DOMDocument::loadHTML($html_text);
-                       if ($dom){
-                               $xpath = new DOMXPath($dom);
-                               $attr = "oembed";
-                       
-                               $xattr = oe_build_xpath("class","oembed");
-                               $entries = $xpath->query("//link[@type='application/json+oembed']");
-                               foreach($entries as $e){
-                                       $href = $e->getAttributeNode("href")->nodeValue;
-                                       $txt = fetch_url($href);
+               if (!in_array($ext, $noexts)){
+                       // try oembed autodiscovery
+                       $redirects = 0;
+                       $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");
+                       if($html_text){
+                               $dom = @DOMDocument::loadHTML($html_text);
+                               if ($dom){
+                                       $xpath = new DOMXPath($dom);
+                                       $attr = "oembed";
+                               
+                                       $xattr = oe_build_xpath("class","oembed");
+                                       $entries = $xpath->query("//link[@type='application/json+oembed']");
+                                       foreach($entries as $e){
+                                               $href = $e->getAttributeNode("href")->nodeValue;
+                                               $txt = fetch_url($href);
+                                       }
                                }
                        }
                }