]> git.mxchange.org Git - friendica.git/blobdiff - include/oembed.php
Merge branch 'master' of https://github.com/friendica/friendica
[friendica.git] / include / oembed.php
index 3e86627e4dd384683a96e834bd8ec56503ce90a3..1f45d2814325449ce5816e564fd7545b9ea2a4c9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 function oembed_replacecb($matches){
-       logger('oembedcb');
+//     logger('oembedcb');
        $embedurl=$matches[1];
        $j = oembed_fetch_url($embedurl);
        $s =  oembed_format_object($j);
@@ -11,33 +11,43 @@ function oembed_replacecb($matches){
 
 
 function oembed_fetch_url($embedurl){
-       
+
        $txt = Cache::get($embedurl);
+
+       // These media files should now be caught in bbcode.php
+       // left here as a fallback in case this is called from another source
+
+       $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 . '&maxwidth=425');
+                                               break;
+                                       }
                                }
                        }
                }
                
                if ($txt==false || $txt==""){
                        // try oohembed service
-                       $ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl);  
+                       $ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl).'&maxwidth=425';  
                        $txt = fetch_url($ourl);
                }
                
@@ -56,7 +66,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,(isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null) );
        $ret="<span class='oembed ".$j->type."'>";
        switch ($j->type) {
                case "video": {
@@ -116,7 +126,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>'; 
 
 }