diff --git a/database.sql b/database.sql index 5d9cc2abb0..b59a3fc0d2 100644 --- a/database.sql +++ b/database.sql @@ -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`), diff --git a/doc/database/db_post-media.md b/doc/database/db_post-media.md index 02c9a7d98a..acbd1f75cb 100644 --- a/doc/database/db_post-media.md +++ b/doc/database/db_post-media.md @@ -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 ------------ diff --git a/src/Factory/Api/Mastodon/Card.php b/src/Factory/Api/Mastodon/Card.php index 32388b4776..f4f69045e8 100644 --- a/src/Factory/Api/Mastodon/Card.php +++ b/src/Factory/Api/Mastodon/Card.php @@ -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); } diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 9ef6eef9ea..af5895557b 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -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; } diff --git a/src/Object/Api/Mastodon/Card.php b/src/Object/Api/Mastodon/Card.php index 0de3f9c499..7a1983ff8b 100644 --- a/src/Object/Api/Mastodon/Card.php +++ b/src/Object/Api/Mastodon/Card.php @@ -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; } diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index f717d17d8b..ad50269186 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -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); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 18990c36fc..183b2281d3 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -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"],