]> git.mxchange.org Git - friendica.git/commitdiff
Add constants for the Fetch Further Information field
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 26 Jul 2023 05:15:24 +0000 (07:15 +0200)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 2 Aug 2023 19:53:09 +0000 (21:53 +0200)
database.sql
src/Contact/LocalRelationship/Entity/LocalRelationship.php
src/Contact/LocalRelationship/Factory/LocalRelationship.php
src/Module/Contact/Profile.php
src/Protocol/Feed.php
static/dbstructure.config.php

index 5a8cee23c4a88f50949da1cac4009a3d1e83722e..5af28131a800e2d4aa84bdd822c74acc06b6e270 100644 (file)
@@ -1835,7 +1835,7 @@ CREATE TABLE IF NOT EXISTS `user-contact` (
        `info` mediumtext COMMENT '',
        `notify_new_posts` boolean COMMENT '',
        `remote_self` boolean COMMENT '',
-       `fetch_further_information` tinyint unsigned COMMENT '',
+       `fetch_further_information` tinyint unsigned COMMENT '0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both',
        `ffi_keyword_denylist` text COMMENT '',
        `subhub` boolean COMMENT '',
        `hub-verify` varbinary(383) COMMENT '',
index 8a9c48745f26a5b16d1855217f3c7329d439c3cc..287768b8c2badc7a97d7741bde64bbcdb434056b 100644 (file)
@@ -47,6 +47,12 @@ use Friendica\Model\Contact;
  */
 class LocalRelationship extends \Friendica\BaseEntity
 {
+       // Fetch Further Information options, not a binary flag
+       const FFI_NONE        = 0;
+       const FFI_INFORMATION = 1;
+       const FFI_KEYWORD     = 3;
+       const FFI_BOTH        = 2;
+
        /** @var int */
        protected $userId;
        /** @var int */
@@ -70,6 +76,7 @@ class LocalRelationship extends \Friendica\BaseEntity
        /** @var bool */
        protected $isRemoteSelf;
        /** @var int */
+       /** @var int One of FFI_* */
        protected $fetchFurtherInformation;
        /** @var string */
        protected $ffiKeywordDenylist;
@@ -84,7 +91,7 @@ class LocalRelationship extends \Friendica\BaseEntity
        /** @var int */
        protected $priority;
 
-       public function __construct(int $userId, int $contactId, bool $blocked = false, bool $ignored = false, bool $collapsed = false, bool $hidden = false, bool $pending = false, int $rel = Contact::NOTHING, string $info = '', bool $notifyNewPosts = false, bool $isRemoteSelf = false, int $fetchFurtherInformation = 0, string $ffiKeywordDenylist = '', bool $subhub = false, string $hubVerify = '', string $protocol = Protocol::PHANTOM, ?int $rating = null, ?int $priority = null)
+       public function __construct(int $userId, int $contactId, bool $blocked = false, bool $ignored = false, bool $collapsed = false, bool $hidden = false, bool $pending = false, int $rel = Contact::NOTHING, string $info = '', bool $notifyNewPosts = false, bool $isRemoteSelf = false, int $fetchFurtherInformation = self::FFI_NONE, string $ffiKeywordDenylist = '', bool $subhub = false, string $hubVerify = '', string $protocol = Protocol::PHANTOM, ?int $rating = null, ?int $priority = null)
        {
                $this->userId                  = $userId;
                $this->contactId               = $contactId;
index 455dbe1c3c86ab7d26e70bbd278139d7cf72311c..6885d68b241ed83fe4fce96e62cd230ce34df816 100644 (file)
@@ -46,7 +46,7 @@ class LocalRelationship extends BaseFactory implements ICanCreateFromTableRow
                        $row['info'] ?? '',
                        $row['notify_new_posts'] ?? false,
                        $row['remote_self'] ?? false,
-                       $row['fetch_further_information'] ?? 0,
+                       $row['fetch_further_information'] ?? Entity\LocalRelationship::FFI_NONE,
                        $row['ffi_keyword_denylist'] ?? '',
                        $row['subhub'] ?? false,
                        $row['hub-verify'] ?? '',
index 2f8daf28e2765299d22ec5c4754e73d478963991..294484a54be2489d08182c2d7703fa1fb9955654 100644 (file)
@@ -283,10 +283,10 @@ class Profile extends BaseModule
                                $localRelationship->fetchFurtherInformation,
                                $this->t('Fetch information like preview pictures, title and teaser from the feed item. You can activate this if the feed doesn\'t contain much text. Keywords are taken from the meta header in the feed item and are posted as hash tags.'),
                                [
-                                       '0' => $this->t('Disabled'),
-                                       '1' => $this->t('Fetch information'),
-                                       '3' => $this->t('Fetch keywords'),
-                                       '2' => $this->t('Fetch information and keywords')
+                                       Entity\LocalRelationship::FFI_NONE        => $this->t('Disabled'),
+                                       Entity\LocalRelationship::FFI_INFORMATION => $this->t('Fetch information'),
+                                       Entity\LocalRelationship::FFI_KEYWORD     => $this->t('Fetch keywords'),
+                                       Entity\LocalRelationship::FFI_BOTH        => $this->t('Fetch information and keywords')
                                ]
                        ];
                }
index fced3526d49ff4e96ea4b6648070a03c2c234f6a..fdfe9be7d5e836b57621b65cb6a6f693124ac48c 100644 (file)
@@ -25,6 +25,7 @@ use DOMDocument;
 use DOMElement;
 use DOMXPath;
 use Friendica\App;
+use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
 use Friendica\Content\PageInfo;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
@@ -566,8 +567,10 @@ class Feed
                                continue;
                        }
 
+                       $fetch_further_information = $contact['fetch_further_information'] ?? LocalRelationship::FFI_NONE;
+
                        $preview = '';
-                       if (!empty($contact['fetch_further_information']) && ($contact['fetch_further_information'] < 3)) {
+                       if (in_array($fetch_further_information, [LocalRelationship::FFI_INFORMATION, LocalRelationship::FFI_BOTH])) {
                                // Handle enclosures and treat them as preview picture
                                foreach ($attachments as $attachment) {
                                        if ($attachment['mimetype'] == 'image/jpeg') {
@@ -611,7 +614,12 @@ class Feed
                                        }
                                }
 
-                               $data = PageInfo::queryUrl($item['plink'], false, $preview, ($contact['fetch_further_information'] == 2), $contact['ffi_keyword_denylist'] ?? '');
+                               $data = PageInfo::queryUrl(
+                                       $item['plink'],
+                                       false,
+                                       $fetch_further_information == LocalRelationship::FFI_BOTH,
+                                       $contact['ffi_keyword_denylist'] ?? ''
+                               );
 
                                if (!empty($data)) {
                                        // Take the data that was provided by the feed if the query is empty
@@ -630,7 +638,7 @@ class Feed
                                        // We always strip the title since it will be added in the page information
                                        $item['title'] = '';
                                        $item['body'] = $item['body'] . "\n" . PageInfo::getFooterFromData($data, false);
-                                       $taglist = $contact['fetch_further_information'] == 2 ? PageInfo::getTagsFromUrl($item['plink'], $preview, $contact['ffi_keyword_denylist'] ?? '') : [];
+                                       $taglist = $fetch_further_information == LocalRelationship::FFI_BOTH ? PageInfo::getTagsFromUrl($item['plink'], $preview, $contact['ffi_keyword_denylist'] ?? '') : [];
                                        $item['object-type'] = Activity\ObjectType::BOOKMARK;
                                        $attachments = [];
 
@@ -662,7 +670,7 @@ class Feed
                                        $item['body'] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item['body'];
                                }
 
-                               if (!empty($contact['fetch_further_information']) && ($contact['fetch_further_information'] == 3)) {
+                               if ($fetch_further_information == LocalRelationship::FFI_KEYWORD) {
                                        if (empty($taglist)) {
                                                $taglist = PageInfo::getTagsFromUrl($item['plink'], $preview, $contact['ffi_keyword_denylist'] ?? '');
                                        }
index 74a65e0eaab23ccd2af84146748170f2b890fef6..09d90e27cdcd28254345311b532b73fdd735623e 100644 (file)
@@ -1827,7 +1827,7 @@ return [
                        "info" => ["type" => "mediumtext", "comment" => ""],
                        "notify_new_posts" => ["type" => "boolean", "comment" => ""],
                        "remote_self" => ["type" => "boolean", "comment" => ""],
-                       "fetch_further_information" => ["type" => "tinyint unsigned", "comment" => ""],
+                       "fetch_further_information" => ["type" => "tinyint unsigned", "comment" => "0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both"],
                        "ffi_keyword_denylist" => ["type" => "text", "comment" => ""],
                        "subhub" => ["type" => "boolean", "comment" => ""],
                        "hub-verify" => ["type" => "varbinary(383)", "comment" => ""],