diff options
author | friendica <info@friendica.com> | 2011-11-18 21:56:17 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2011-11-18 21:56:17 -0800 |
commit | 0d77ca1caa784a5fb7e809e896101c82a7ec552f (patch) | |
tree | 13cfc7dde6b2761de0d9144972ba4eeb3b88a492 | |
parent | d53db63d41d2f253c9aff806d9830167c9dd7a8d (diff) | |
parent | 32f17e7e24d52bed1b5a5d8ed01d101522b26a9f (diff) | |
download | volse-hubzilla-0d77ca1caa784a5fb7e809e896101c82a7ec552f.tar.gz volse-hubzilla-0d77ca1caa784a5fb7e809e896101c82a7ec552f.tar.bz2 volse-hubzilla-0d77ca1caa784a5fb7e809e896101c82a7ec552f.zip |
Merge branch 'pull'
-rw-r--r-- | include/network.php | 10 | ||||
-rw-r--r-- | include/oembed.php | 34 |
2 files changed, 29 insertions, 15 deletions
diff --git a/include/network.php b/include/network.php index a9ee3f0a5..e89eb94da 100644 --- a/include/network.php +++ b/include/network.php @@ -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); } diff --git a/include/oembed.php b/include/oembed.php index 7c0da4594..118f7fa4a 100644 --- a/include/oembed.php +++ b/include/oembed.php @@ -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); + } } } } |