]> git.mxchange.org Git - friendica.git/blobdiff - mod/parse_url.php
photos-albms widget: add some classes
[friendica.git] / mod / parse_url.php
index 7f4bd29a08b292728e2c07b3bb0f457c796420c3..ef051d9f6b433c0e8152c39168c0debd8cfbee0a 100644 (file)
@@ -50,6 +50,21 @@ function completeurl($url, $scheme) {
        return($complete);
 }
 
+function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = true) {
+
+       $data = Cache::get("parse_url:".$no_guessing.":".$do_oembed.":".$url);
+       if (!is_null($data)) {
+               $data = unserialize($data);
+               return $data;
+       }
+
+       $data = parseurl_getsiteinfo($url, $no_guessing, $do_oembed);
+
+       Cache::set("parse_url:".$no_guessing.":".$do_oembed.":".$url,serialize($data), CACHE_DAY);
+
+       return $data;
+}
+
 function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1) {
        require_once("include/network.php");
 
@@ -97,6 +112,14 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
                return($siteinfo);
        }
 
+       // 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);
+
        if ($do_oembed) {
                require_once("include/oembed.php");
 
@@ -104,15 +127,16 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
 
                if ($oembed_data->type != "error")
                        $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);
+               if (($oembed_data->type == "link") AND ($siteinfo["type"] != "photo")) {
+                       if (isset($oembed_data->title))
+                               $siteinfo["title"] = $oembed_data->title;
+                       if (isset($oembed_data->description))
+                               $siteinfo["text"] = trim($oembed_data->description);
+                       if (isset($oembed_data->thumbnail_url))
+                               $siteinfo["image"] = $oembed_data->thumbnail_url;
+               }
+       }
 
        $stamp1 = microtime(true);
 
@@ -256,7 +280,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
        if (isset($keywords)) {
                $siteinfo["keywords"] = array();
                foreach ($keywords as $keyword)
-                       $siteinfo["keywords"][] = trim($keyword);
+                       if (!in_array(trim($keyword), $siteinfo["keywords"]))
+                               $siteinfo["keywords"][] = trim($keyword);
        }
 
        //$list = $xpath->query("head/meta[@property]");
@@ -283,15 +308,6 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
                        }
        }
 
-       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) != ""))
-                       $siteinfo["text"] = trim($oembed_data->description);
-               if (isset($oembed_data->thumbnail_url) AND (trim($oembed_data->thumbnail_url) != ""))
-                       $siteinfo["image"] = $oembed_data->thumbnail_url;
-       }
-
        if ((@$siteinfo["image"] == "") AND !$no_guessing) {
            $list = $xpath->query("//img[@src]");
            foreach ($list as $node) {