X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Foembed.php;h=5c3c595f57e910ba47577746e7afd53d89c8b1e0;hb=d647dbc6af33689d0baf4bafd72031d06dcf7577;hp=924e61289ed5ac787f571c3534e9ab7490a5603c;hpb=2905df527f2fbc9b426ebc89a53adc5c6cf1ee47;p=friendica.git diff --git a/include/oembed.php b/include/oembed.php old mode 100644 new mode 100755 index 924e61289e..5c3c595f57 --- a/include/oembed.php +++ b/include/oembed.php @@ -1,32 +1,42 @@ width,$j->height); + + } 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); + } } } } @@ -52,6 +62,7 @@ function oembed_fetch_url($embedurl){ function oembed_format_object($j){ $embedurl = $j->embedurl; + $jhtml = oembed_iframe($j->embedurl,$j->width,$j->height ); $ret=""; switch ($j->type) { case "video": { @@ -64,14 +75,14 @@ function oembed_format_object($j){ $tpl=get_markup_template('oembed_video.tpl'); $ret.=replace_macros($tpl, array( '$embedurl'=>$embedurl, - '$escapedhtml'=>urlencode($j->html), + '$escapedhtml'=>base64_encode($jhtml), '$tw'=>$tw, '$th'=>$th, '$turl'=>$j->thumbnail_url, )); } else { - $ret=$j->html; + $ret=$jhtml; } $ret.="
"; }; break; @@ -84,12 +95,12 @@ function oembed_format_object($j){ }; break; case "rich": { // not so safe.. - $ret.= $j->html; + $ret.= $jhtml; }; break; } // add link to source if not present in "rich" type - if ( $j->type!='rich' || !strpos($ret,$embedurl) ){ + if ( $j->type!='rich' || !strpos($j->html,$embedurl) ){ $embedlink = (isset($j->title))?$j->title:$embedurl; $ret .= "$embedlink"; if (isset($j->author_name)) $ret.=" by ".$j->author_name; @@ -102,6 +113,24 @@ function oembed_format_object($j){ return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret)); } +function oembed_iframe($src,$width,$height) { + if(! $width || strstr($width,'%')) + $width = '640'; + if(! $height || strstr($height,'%')) + $height = '300'; + // try and leave some room for the description line. + $height = intval($height) + 80; + $width = intval($width) + 40; + + $a = get_app(); + + $s = $a->get_baseurl()."/oembed/".base64url_encode($src); + return ''; + +} + + + function oembed_bbcode2html($text){ $stopoembed = get_config("system","no_oembed"); if ($stopoembed == true){