Support for language and publification date

This commit is contained in:
Michael 2025-03-02 14:38:54 +00:00
parent 1ced848827
commit fc8946cf02
7 changed files with 46 additions and 2 deletions

View file

@ -48,6 +48,7 @@ class Card extends BaseFactory
$data['url'] = $media[0]['url'];
$data['title'] = $media[0]['name'];
$data['description'] = $media[0]['description'];
$data['language'] = $media[0]['language'];
$data['type'] = 'link';
$data['author_name'] = $media[0]['author-name'];
$data['author_url'] = $media[0]['author-url'];
@ -57,6 +58,7 @@ class Card extends BaseFactory
$data['width'] = $media[0]['preview-width'];
$data['height'] = $media[0]['preview-height'];
$data['blurhash'] = $media[0]['blurhash'];
$data['published'] = $media[0]['published'];
return new \Friendica\Object\Api\Mastodon\Card($data, $history);
}

View file

@ -362,6 +362,13 @@ class Media
$media['publisher-name'] = $gserver['site_name'] ?? null;
$media['publisher-image'] = null;
if (!empty($item['language'])) {
$media['language'] = array_key_first(json_decode($item['language'], true));
}
$media['published'] = $item['created'];
$media['modified'] = $item['changed'];
DI::logger()->debug('Activity detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'plink' => $item['plink'], 'uri' => $item['uri']]);
return $media;
}
@ -403,6 +410,9 @@ class Media
$media['publisher-url'] = $gserver['url'] ?? null;
$media['publisher-name'] = $gserver['site_name'] ?? null;
$media['publisher-image'] = null;
$media['language'] = null;
$media['published'] = $contact['created'];
$media['modified'] = $contact['updated'];
DI::logger()->debug('Account detected', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'uri' => $contact['url']]);
return $media;
@ -439,6 +449,9 @@ class Media
$media['publisher-url'] = $data['publisher_url'] ?? null;
$media['publisher-name'] = $data['publisher_name'] ?? null;
$media['publisher-image'] = $data['publisher_img'] ?? null;
$media['language'] = $data['language'] ?? null;
$media['published'] = $data['published'] ?? null;
$media['modified'] = $data['modified'] ?? null;
return $media;
}

View file

@ -8,6 +8,7 @@
namespace Friendica\Object\Api\Mastodon;
use Friendica\BaseDataTransferObject;
use Friendica\Util\DateTimeFormat;
/**
* Class Card
@ -23,6 +24,8 @@ class Card extends BaseDataTransferObject
/** @var string */
protected $description;
/** @var string */
protected $language;
/** @var string */
protected $type;
/** @var string */
protected $author_name;
@ -64,6 +67,7 @@ class Card extends BaseDataTransferObject
$this->url = $attachment['url'] ?? '';
$this->title = $attachment['title'] ?? '';
$this->description = $attachment['description'] ?? '';
$this->language = $attachment['language'] ?? '';
$this->type = $attachment['type'] ?? '';
$this->author_name = $attachment['author_name'] ?? '';
$this->author_url = $attachment['author_url'] ?? '';
@ -75,6 +79,7 @@ class Card extends BaseDataTransferObject
$this->image = $attachment['image'] ?? '';
$this->embed_url = '';
$this->blurhash = $attachment['blurhash'] ?? '';
$this->published_at = !empty($attachment['published']) ? DateTimeFormat::utc($attachment['published'], DateTimeFormat::JSON) : null;
$this->history = $history;
}

View file

@ -296,6 +296,17 @@ class ParseUrl
$xpath = new DOMXPath($doc);
$list = $xpath->query('//html[@lang]');
foreach ($list as $node) {
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
if ($attribute->name == 'lang') {
$siteinfo['language'] = $attribute->value;
}
}
}
}
$list = $xpath->query('//meta[@content]');
foreach ($list as $node) {
$meta_tag = [];
@ -495,6 +506,10 @@ class ParseUrl
}
}
if (!empty($siteinfo['language'])) {
$siteinfo['language'] = explode('_', str_replace('-', '_', $siteinfo['language']))[0];
}
DI::logger()->info('Siteinfo fetched', ['url' => $url, 'siteinfo' => $siteinfo]);
Hook::callAll('getsiteinfo', $siteinfo);