]> git.mxchange.org Git - friendica.git/blobdiff - mod/parse_url.php
Merge pull request #1399 from annando/1502-profile-link-avatar-picture
[friendica.git] / mod / parse_url.php
index 4830be5d6f078b9d7e8700f1b8d81cf6351a9172..9f7b31be302b05576ea6111db14755f6ff32eeeb 100644 (file)
@@ -73,7 +73,7 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
-       curl_setopt($ch, CURLOPT_NOBODY, 0);
+       curl_setopt($ch, CURLOPT_NOBODY, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 3);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
@@ -102,6 +102,28 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
                        $siteinfo["type"] = $oembed_data->type;
        }
 
+       // if the file is too large then exit
+       if ($curl_info["download_content_length"] > 1000000)
+               return($siteinfo);
+
+       // if it isn't a HTML file then exit
+       if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html"))
+               return($siteinfo);
+
+       // Now fetch the body as well
+       $ch = curl_init();
+       curl_setopt($ch, CURLOPT_URL, $url);
+       curl_setopt($ch, CURLOPT_HEADER, 1);
+       curl_setopt($ch, CURLOPT_NOBODY, 0);
+       curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+       curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
+
+       $header = curl_exec($ch);
+       $curl_info = @curl_getinfo($ch);
+        $http_code = $curl_info['http_code'];
+       curl_close($ch);
+
        // Fetch the first mentioned charset. Can be in body or header
        $charset = "";
        if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches))
@@ -187,6 +209,9 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
                                case "description":
                                        $siteinfo["text"] = $attr["content"];
                                        break;
+                               case "thumbnail":
+                                       $siteinfo["image"] = $attr["content"];
+                                       break;
                                case "twitter:image":
                                        $siteinfo["image"] = $attr["content"];
                                        break;
@@ -333,6 +358,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
 
        logger("parseurl_getsiteinfo: Siteinfo for ".$url." ".print_r($siteinfo, true), LOGGER_DEBUG);
 
+       call_hooks('getsiteinfo', $siteinfo);
+
        return($siteinfo);
 }
 
@@ -410,8 +437,21 @@ function parse_url_content(&$a) {
 
        $siteinfo = parseurl_getsiteinfo($url);
 
+//     if ($textmode) {
+//             require_once("include/items.php");
+//
+//             echo add_page_info_data($siteinfo);
+//             killme();
+//     }
+
        $url= $siteinfo["url"];
 
+       // If the link contains BBCode stuff, make a short link out of this to avoid parsing problems
+       if (strpos($url, '[') OR strpos($url, ']')) {
+               require_once("include/network.php");
+               $url = short_link($url);
+       }
+
        $sitedata = "";
 
        if($siteinfo["title"] == "") {