Ensure ParseUrl::getSiteinfo always returns the url and type keys

This commit is contained in:
Hypolite Petovan 2020-07-17 19:18:27 -04:00
parent 25b3fa83fc
commit 886cf40036

View file

@ -57,12 +57,11 @@ class ParseUrl
* @return array which contains needed data for embedding * @return array which contains needed data for embedding
* string 'url' => The url of the parsed page * string 'url' => The url of the parsed page
* string 'type' => Content type * string 'type' => Content type
* string 'title' => The title of the content * string 'title' => (optional) The title of the content
* string 'text' => The description for the content * string 'text' => (optional) The description for the content
* string 'image' => A preview image of the content (only available * string 'image' => (optional) A preview image of the content (only available if $no_geuessing = false)
* if $no_geuessing = false * array 'images' => (optional) Array of preview pictures
* array'images' = Array of preview pictures * string 'keywords' => (optional) The tags which belong to the content
* string 'keywords' => The tags which belong to the content
* *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @see ParseUrl::getSiteinfo() for more information about scraping * @see ParseUrl::getSiteinfo() for more information about scraping
@ -117,12 +116,11 @@ class ParseUrl
* @return array which contains needed data for embedding * @return array which contains needed data for embedding
* string 'url' => The url of the parsed page * string 'url' => The url of the parsed page
* string 'type' => Content type * string 'type' => Content type
* string 'title' => The title of the content * string 'title' => (optional) The title of the content
* string 'text' => The description for the content * string 'text' => (optional) The description for the content
* string 'image' => A preview image of the content (only available * string 'image' => (optional) A preview image of the content (only available if $no_guessing = false)
* if $no_geuessing = false * array 'images' => (optional) Array of preview pictures
* array'images' = Array of preview pictures * string 'keywords' => (optional) The tags which belong to the content
* string 'keywords' => The tags which belong to the content
* *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @todo https://developers.google.com/+/plugins/snippet/ * @todo https://developers.google.com/+/plugins/snippet/
@ -140,28 +138,27 @@ class ParseUrl
*/ */
public static function getSiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1) public static function getSiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1)
{ {
$siteinfo = [];
// Check if the URL does contain a scheme // Check if the URL does contain a scheme
$scheme = parse_url($url, PHP_URL_SCHEME); $scheme = parse_url($url, PHP_URL_SCHEME);
if ($scheme == '') { if ($scheme == '') {
$url = 'http://' . trim($url, '/'); $url = 'http://' . ltrim($url, '/');
} }
$url = trim($url, "'\"");
$url = Network::stripTrackingQueryParams($url);
$siteinfo = [
'url' => $url,
'type' => 'link',
];
if ($count > 10) { if ($count > 10) {
Logger::log('Endless loop detected for ' . $url, Logger::DEBUG); Logger::log('Endless loop detected for ' . $url, Logger::DEBUG);
return $siteinfo; return $siteinfo;
} }
$url = trim($url, "'");
$url = trim($url, '"');
$url = Network::stripTrackingQueryParams($url);
$siteinfo['url'] = $url;
$siteinfo['type'] = 'link';
$curlResult = Network::curl($url); $curlResult = Network::curl($url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return $siteinfo; return $siteinfo;