Merge pull request #7 from fabrixxm/master

Fix possibile fatal error with oembed
This commit is contained in:
fabrixxm 2011-11-17 04:53:22 -08:00
commit 32f17e7e24
2 changed files with 29 additions and 15 deletions

View file

@ -5,7 +5,7 @@
// results. // results.
if(! function_exists('fetch_url')) { 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(); $a = get_app();
@ -14,9 +14,17 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0) {
return false; return false;
@curl_setopt($ch, CURLOPT_HEADER, true); @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_RETURNTRANSFER,true);
@curl_setopt($ch, CURLOPT_USERAGENT, "Friendika"); @curl_setopt($ch, CURLOPT_USERAGENT, "Friendika");
if(intval($timeout)) { if(intval($timeout)) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
} }

View file

@ -14,12 +14,17 @@ function oembed_fetch_url($embedurl){
$txt = Cache::get($embedurl); $txt = Cache::get($embedurl);
$noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm");
$ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION);
if(is_null($txt)){ if(is_null($txt)){
$txt = ""; $txt = "";
if (!in_array($ext, $noexts)){
// try oembed autodiscovery // try oembed autodiscovery
$redirects = 0; $redirects = 0;
$html_text = fetch_url($embedurl, false, $redirects, 15); $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");
if($html_text){ if($html_text){
$dom = @DOMDocument::loadHTML($html_text); $dom = @DOMDocument::loadHTML($html_text);
if ($dom){ if ($dom){
@ -34,6 +39,7 @@ function oembed_fetch_url($embedurl){
} }
} }
} }
}
if ($txt==false || $txt==""){ if ($txt==false || $txt==""){
// try oohembed service // try oohembed service