X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=7ab71a2fc520d7f7ae68a07711a7cc35fe947633;hb=1940905454b311fc5999a0d8020832bb92ee52f5;hp=a0608f636340cfe8e88b41f5c1bae123204974f6;hpb=12866209e889cea0e2c3e1659d0845388bc4090b;p=friendica.git diff --git a/mod/parse_url.php b/mod/parse_url.php index a0608f6363..7ab71a2fc5 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -50,9 +50,15 @@ function completeurl($url, $scheme) { return($complete); } -function parseurl_getsiteinfo($url, $no_guessing = false) { +function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1) { + $siteinfo = array(); + if ($count > 10) { + logger("parseurl_getsiteinfo: Endless loop detected for ".$url, LOGGER_DEBUG); + return($siteinfo); + } + $url = trim($url, "'"); $url = trim($url, '"'); $siteinfo["url"] = $url; @@ -65,7 +71,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false) { curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch,CURLOPT_USERAGENT,' Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'); + //curl_setopt($ch,CURLOPT_USERAGENT,' Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'); + curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)"); $header = curl_exec($ch); $curl_info = @curl_getinfo($ch); @@ -75,18 +82,20 @@ function parseurl_getsiteinfo($url, $no_guessing = false) { if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302") OR ($curl_info['http_code'] == "303") OR ($curl_info['http_code'] == "307")) AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) { if ($curl_info['redirect_url'] != "") - $siteinfo = parseurl_getsiteinfo($curl_info['redirect_url']); + $siteinfo = parseurl_getsiteinfo($curl_info['redirect_url'], $no_guessing, $do_oembed, ++$count); else - $siteinfo = parseurl_getsiteinfo($curl_info['location']); + $siteinfo = parseurl_getsiteinfo($curl_info['location'], $no_guessing, $do_oembed, ++$count); return($siteinfo); } - require_once("include/oembed.php"); + if ($do_oembed) { + require_once("include/oembed.php"); - $oembed_data = oembed_fetch_url($url); + $oembed_data = oembed_fetch_url($url); - if ($oembed_data->type != "error") - $siteinfo["type"] = $oembed_data->type; + if ($oembed_data->type != "error") + $siteinfo["type"] = $oembed_data->type; + } // Fetch the first mentioned charset. Can be in body or header $charset = ""; @@ -139,7 +148,7 @@ function parseurl_getsiteinfo($url, $no_guessing = false) { $content = substr($value, 4); } if ($content != "") { - $siteinfo = parseurl_getsiteinfo($content); + $siteinfo = parseurl_getsiteinfo($content, $no_guessing, $do_oembed, ++$count); return($siteinfo); } } @@ -172,7 +181,7 @@ function parseurl_getsiteinfo($url, $no_guessing = false) { $siteinfo["image"] = $attr["content"]; break; case "twitter:card": - if ($siteinfo["type"] == "") + if (($siteinfo["type"] == "") OR ($attr["content"] == "photo")) $siteinfo["type"] = $attr["content"]; break; case "twitter:description": @@ -216,7 +225,7 @@ function parseurl_getsiteinfo($url, $no_guessing = false) { } } - if ($oembed_data->type == "link") { + if (isset($oembed_data) AND ($oembed_data->type == "link") AND ($siteinfo["type"] != "photo")) { if (isset($oembed_data->title) AND (trim($oembed_data->title) != "")) $siteinfo["title"] = $oembed_data->title; if (isset($oembed_data->description) AND (trim($oembed_data->description) != "")) @@ -440,3 +449,4 @@ function parse_url_content(&$a) { killme(); } +?>