Merge pull request #14708 from annando/exception

Fix exception "Argument #2 ($jsonld) must be of type array, string given"
pull/14714/head
Tobias Diekershoff 2025-01-19 17:36:54 +01:00 committed by GitHub
commit ee25c69cd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 26 deletions

View File

@ -116,9 +116,7 @@ class ParseUrl
$urlHash = hash('sha256', $url);
$parsed_url = DBA::selectFirst('parsed_url', ['content'],
['url_hash' => $urlHash, 'oembed' => false]
);
$parsed_url = DBA::selectFirst('parsed_url', ['content'], ['url_hash' => $urlHash, 'oembed' => false]);
if (!empty($parsed_url['content'])) {
$data = unserialize($parsed_url['content']);
return $data;
@ -246,11 +244,13 @@ class ParseUrl
if ($cacheControlHeader = $curlResult->getHeader('Cache-Control')[0] ?? '') {
if (preg_match('/max-age=([0-9]+)/i', $cacheControlHeader, $matches)) {
$maxAge = max(86400, (int)array_pop($matches));
$siteinfo['expires'] = DateTimeFormat::utc("now + $maxAge seconds");
}
}
$body = $curlResult->getBodyString();
$siteinfo['size'] = mb_strlen($body);
$charset = '';
@ -260,7 +260,8 @@ class ParseUrl
if (isset($mediaType->parameters['charset'])) {
$charset = $mediaType->parameters['charset'];
}
} catch(\InvalidArgumentException $e) {}
} catch(\InvalidArgumentException $e) {
}
$siteinfo['charset'] = $charset;
@ -307,9 +308,8 @@ class ParseUrl
if (@$meta_tag['http-equiv'] == 'refresh') {
$path = $meta_tag['content'];
$pathinfo = explode(';', $path);
$content = '';
foreach ($pathinfo as $value) {
foreach (explode(';', $path) as $value) {
if (substr(strtolower($value), 0, 4) == 'url=') {
$content = substr($value, 4);
}
@ -455,7 +455,8 @@ class ParseUrl
$list = $xpath->query("//script[@type='application/ld+json']");
foreach ($list as $node) {
if (!empty($node->nodeValue)) {
if ($jsonld = json_decode($node->nodeValue, true)) {
$jsonld = json_decode($node->nodeValue, true);
if (is_array($jsonld)) {
$siteinfo = self::parseParts($siteinfo, $jsonld);
}
}
@ -488,6 +489,7 @@ class ParseUrl
if (!empty($siteinfo['text']) && mb_strlen($siteinfo['text']) > self::MAX_DESC_COUNT) {
$siteinfo['text'] = mb_substr($siteinfo['text'], 0, self::MAX_DESC_COUNT) . '…';
$pos = mb_strrpos($siteinfo['text'], '.');
if ($pos > self::MIN_DESC_COUNT) {
$siteinfo['text'] = mb_substr($siteinfo['text'], 0, $pos + 1);
@ -522,6 +524,7 @@ class ParseUrl
*/
if (!empty($image['url'])) {
$image['url'] = self::completeUrl($image['url'], $page_url);
$photodata = Images::getInfoFromURLCached($image['url']);
if (($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) {
$image['src'] = $image['url'];
@ -552,6 +555,7 @@ class ParseUrl
foreach (['embed', 'content', 'url'] as $field) {
if (!empty($media[$field])) {
$media[$field] = self::completeUrl($media[$field], $page_url);
$type = self::getContentType($media[$field]);
if (($type[0] ?? '') == 'text') {
if ($field == 'embed') {
@ -811,7 +815,7 @@ class ParseUrl
case 'Person':
case 'Patient':
case 'PerformingGroup':
case 'DanceGroup';
case 'DanceGroup':
case 'MusicGroup':
case 'TheaterGroup':
return self::parseJsonLdWebPerson($siteinfo, $jsonld);
@ -954,8 +958,7 @@ class ParseUrl
$content = JsonLD::fetchElement($jsonld, 'keywords');
if (!empty($content)) {
$siteinfo['keywords'] = [];
$keywords = explode(',', $content);
foreach ($keywords as $keyword) {
foreach (explode(',', $content) as $keyword) {
$siteinfo['keywords'][] = trim($keyword);
}
}