]> git.mxchange.org Git - friendica.git/blobdiff - mod/parse_url.php
Merge pull request #1055 from annando/master
[friendica.git] / mod / parse_url.php
index 481b26533d25da5586a8f9f135f90ea0e7b96ec6..7ab71a2fc520d7f7ae68a07711a7cc35fe947633 100644 (file)
@@ -50,10 +50,15 @@ function completeurl($url, $scheme) {
         return($complete);
 }
 
-function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true) {
+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;
@@ -66,7 +71,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true) {
        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);
@@ -76,9 +82,9 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true) {
        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);
        }
 
@@ -142,7 +148,7 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true) {
                                         $content = substr($value, 4);
                         }
                         if ($content != "") {
-                                $siteinfo = parseurl_getsiteinfo($content);
+                                $siteinfo = parseurl_getsiteinfo($content, $no_guessing, $do_oembed, ++$count);
                                 return($siteinfo);
                         }
                 }
@@ -219,7 +225,7 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true) {
                        }
        }
 
-       if (isset($oembed_data) AND ($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) != ""))