]> git.mxchange.org Git - friendica.git/blobdiff - include/oembed.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[friendica.git] / include / oembed.php
old mode 100644 (file)
new mode 100755 (executable)
index 3e86627..5c3c595
@@ -11,26 +11,32 @@ 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);
+                                       }
                                }
                        }
                }
@@ -56,7 +62,7 @@ function oembed_fetch_url($embedurl){
        
 function oembed_format_object($j){
        $embedurl = $j->embedurl;
-       $jhtml = oembed_iframe($j->html,$j->width,$j->height );
+       $jhtml = oembed_iframe($j->embedurl,$j->width,$j->height );
        $ret="<span class='oembed ".$j->type."'>";
        switch ($j->type) {
                case "video": {
@@ -116,7 +122,9 @@ function oembed_iframe($src,$width,$height) {
        $height = intval($height) + 80;
        $width  = intval($width) + 40;
 
-       $s = 'data:text/html;base64,' . base64_encode('<html><body>' . $src . '</body></html>');
+       $a = get_app();
+
+       $s = $a->get_baseurl()."/oembed/".base64url_encode($src);
        return '<iframe height="' . $height . '" width="' . $width . '" src="' . $s . '" frameborder="no" >' . t('Embedded content') . '</iframe>'; 
 
 }