]> git.mxchange.org Git - friendica.git/commitdiff
Support for language and publification date
authorMichael <heluecht@pirati.ca>
Sun, 2 Mar 2025 14:38:54 +0000 (14:38 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 2 Mar 2025 16:47:21 +0000 (16:47 +0000)
database.sql
doc/database/db_post-media.md
src/Factory/Api/Mastodon/Card.php
src/Model/Post/Media.php
src/Object/Api/Mastodon/Card.php
src/Util/ParseUrl.php
static/dbstructure.config.php

index 5d9cc2abb0e9231e2dda39f0e3df44f184679d41..b59a3fc0d244eb7694d293f6510381548be8a759 100644 (file)
@@ -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`),
index 02c9a7d98aa106f2e896767ea35c2b7e1d3a6a56..acbd1f75cb97a24bd191c905ba034ef4ff76c952 100644 (file)
@@ -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
 ------------
index 32388b4776a084ca76c8d28d15692260284c9a7a..f4f69045e88b3188f9aa99289e9844dd621f7ee4 100644 (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);
        }
index 9ef6eef9eab3433d4406b0d8cd085d73ea630244..af5895557b8f6124826715416c0a829702baae78 100644 (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;
        }
index 0de3f9c499c1647cdd1188578df8756a2807cb75..7a1983ff8b35a56b300450ea89e2fe1404c13e96 100644 (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;
        }
 
index f717d17d8b1d02a22f10624670aab927d0b38562..ad50269186d832fa6afd04958b364a98166dc024 100644 (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);
index 18990c36fcd89811d4a99e992d1f40a8bc7def7d..183b2281d38d330f719664c51f3b5eb488a5a06b 100644 (file)
@@ -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"],