Support for language and publification date

pull/14835/head
Michael 2025-03-02 14:38:54 +00:00
rodzic 1ced848827
commit fc8946cf02
7 zmienionych plików z 46 dodań i 2 usunięć
doc/database
src
Factory/Api/Mastodon
Model/Post
Object/Api/Mastodon

Wyświetl plik

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2025.02-dev (Interrupted Fern)
-- DB_UPDATE_VERSION 1579
-- DB_UPDATE_VERSION 1580
-- ------------------------------------------
@ -1441,6 +1441,9 @@ CREATE TABLE IF NOT EXISTS `post-media` (
`publisher-url` varbinary(383) COMMENT 'URL of the publisher of the media',
`publisher-name` varchar(255) COMMENT 'Name of the publisher of the media',
`publisher-image` varbinary(383) COMMENT 'Image of the publisher of the media',
`language` char(3) COMMENT 'Language information about this media in the ISO 639 format',
`published` datetime COMMENT 'Publification date of this media',
`modified` datetime COMMENT 'Modification date of this media',
PRIMARY KEY(`id`),
UNIQUE INDEX `uri-id-url` (`uri-id`,`url`(512)),
INDEX `uri-id-id` (`uri-id`,`id`),

Wyświetl plik

@ -30,6 +30,9 @@ Fields
| publisher-url | URL of the publisher of the media | varbinary(383) | YES | | NULL | |
| publisher-name | Name of the publisher of the media | varchar(255) | YES | | NULL | |
| publisher-image | Image of the publisher of the media | varbinary(383) | YES | | NULL | |
| language | Language information about this media in the ISO 639 format | char(3) | YES | | NULL | |
| published | Publification date of this media | datetime | YES | | NULL | |
| modified | Modification date of this media | datetime | YES | | NULL | |
Indexes
------------

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -44,7 +44,7 @@ use Friendica\Database\DBA;
// This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1579);
define('DB_UPDATE_VERSION', 1580);
}
return [
@ -1447,6 +1447,9 @@ return [
"publisher-url" => ["type" => "varbinary(383)", "comment" => "URL of the publisher of the media"],
"publisher-name" => ["type" => "varchar(255)", "comment" => "Name of the publisher of the media"],
"publisher-image" => ["type" => "varbinary(383)", "comment" => "Image of the publisher of the media"],
"language" => ["type" => "char(3)", "comment" => "Language information about this media in the ISO 639 format"],
"published" => ["type" => "datetime", "comment" => "Publification date of this media"],
"modified" => ["type" => "datetime", "comment" => "Modification date of this media"],
],
"indexes" => [
"PRIMARY" => ["id"],