X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=ef051d9f6b433c0e8152c39168c0debd8cfbee0a;hb=89c5989cfb679449fb776df7380e972d0f676d8d;hp=cd2263dbe2622d8ae532ab87dcce935ac037b916;hpb=35f623ae4f82ac8167ad98b38fab39e449ffa1ea;p=friendica.git diff --git a/mod/parse_url.php b/mod/parse_url.php index cd2263dbe2..ef051d9f6b 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -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) { @@ -407,6 +423,15 @@ function parse_url_content(&$a) { } } + // add url scheme if missing + $arrurl = parse_url($url); + if (!x($arrurl, 'scheme')) { + if (x($arrurl, 'host')) + $url = "http:".$url; + else + $url = "http://".$url; + } + logger('parse_url: ' . $url); if($textmode) @@ -462,10 +487,7 @@ function parse_url_content(&$a) { $sitedata = ""; - if($siteinfo["title"] == "") { - $sitedata .= sprintf($template,$url,$url,'') . $str_tags; - killme(); - } else { + if($siteinfo["title"] != "") { $text = $siteinfo["text"]; $title = $siteinfo["title"]; }