return [];
}
- $contenttype = $curlResult->getContentType();
+ $contenttype = $curlResult->getContentType();
if (empty($contenttype)) {
return ['application', 'octet-stream'];
}
{
if (empty($url)) {
return [
- 'url' => '',
+ 'url' => '',
'type' => 'error',
];
}
$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;
{
if (empty($url)) {
return [
- 'url' => '',
+ 'url' => '',
'type' => 'error',
];
}
$url = Network::stripTrackingQueryParams($url);
$siteinfo = [
- 'url' => $url,
- 'type' => 'link',
+ 'url' => $url,
+ 'type' => 'link',
'expires' => DateTimeFormat::utc(self::DEFAULT_EXPIRATION_FAILURE),
];
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 = '';
if (isset($mediaType->parameters['charset'])) {
$charset = $mediaType->parameters['charset'];
}
- } catch(\InvalidArgumentException $e) {}
+ } catch(\InvalidArgumentException $e) {
+ }
$siteinfo['charset'] = $charset;
}
if (@$meta_tag['http-equiv'] == 'refresh') {
- $path = $meta_tag['content'];
- $pathinfo = explode(';', $path);
+ $path = $meta_tag['content'];
$content = '';
- foreach ($pathinfo as $value) {
+ foreach (explode(';', $path) as $value) {
if (substr(strtolower($value), 0, 4) == 'url=') {
$content = substr($value, 4);
}
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);
* @param array $siteinfo
* @return array
*/
- private static function checkMedia(string $page_url, array $siteinfo) : array
+ private static function checkMedia(string $page_url, array $siteinfo): array
{
if (!empty($siteinfo['images'])) {
array_walk($siteinfo['images'], function (&$image) use ($page_url) {
*/
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'];
- $image['width'] = $photodata[0];
- $image['height'] = $photodata[1];
+ $image['src'] = $image['url'];
+ $image['width'] = $photodata[0];
+ $image['height'] = $photodata[1];
$image['contenttype'] = $photodata['mime'];
- $image['blurhash'] = $photodata['blurhash'] ?? null;
+ $image['blurhash'] = $photodata['blurhash'] ?? null;
unset($image['url']);
ksort($image);
} else {
foreach (['audio', 'video'] as $element) {
if (!empty($siteinfo[$element])) {
array_walk($siteinfo[$element], function (&$media) use ($page_url, &$siteinfo) {
- $url = '';
- $embed = '';
- $content = '';
+ $url = '';
+ $embed = '';
+ $content = '';
$contenttype = '';
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') {
$url = $media[$field];
}
} elseif (!empty($type[0])) {
- $content = $media[$field];
+ $content = $media[$field];
$contenttype = implode('/', $type);
}
}
} elseif (!empty($jsonld['@type'])) {
$siteinfo = self::parseJsonLd($siteinfo, $jsonld);
} elseif (!empty($jsonld)) {
- $keys = array_keys($jsonld);
+ $keys = array_keys($jsonld);
$numeric_keys = true;
foreach ($keys as $key) {
if (!is_int($key)) {
case 'Person':
case 'Patient':
case 'PerformingGroup':
- case 'DanceGroup';
+ case 'DanceGroup':
case 'MusicGroup':
case 'TheaterGroup':
return self::parseJsonLdWebPerson($siteinfo, $jsonld);
$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);
}
}