From d0a2357fbdd45c7e3301dfb64a23614ebe372a4b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 26 Jul 2023 07:15:24 +0200 Subject: [PATCH] Add constants for the Fetch Further Information field --- database.sql | 2 +- .../Entity/LocalRelationship.php | 9 ++++++++- .../Factory/LocalRelationship.php | 2 +- src/Module/Contact/Profile.php | 8 ++++---- src/Protocol/Feed.php | 16 ++++++++++++---- static/dbstructure.config.php | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/database.sql b/database.sql index 5a8cee23c..5af28131a 100644 --- a/database.sql +++ b/database.sql @@ -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 '', diff --git a/src/Contact/LocalRelationship/Entity/LocalRelationship.php b/src/Contact/LocalRelationship/Entity/LocalRelationship.php index 8a9c48745..287768b8c 100644 --- a/src/Contact/LocalRelationship/Entity/LocalRelationship.php +++ b/src/Contact/LocalRelationship/Entity/LocalRelationship.php @@ -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; diff --git a/src/Contact/LocalRelationship/Factory/LocalRelationship.php b/src/Contact/LocalRelationship/Factory/LocalRelationship.php index 455dbe1c3..6885d68b2 100644 --- a/src/Contact/LocalRelationship/Factory/LocalRelationship.php +++ b/src/Contact/LocalRelationship/Factory/LocalRelationship.php @@ -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'] ?? '', diff --git a/src/Module/Contact/Profile.php b/src/Module/Contact/Profile.php index 2f8daf28e..294484a54 100644 --- a/src/Module/Contact/Profile.php +++ b/src/Module/Contact/Profile.php @@ -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') ] ]; } diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index fced3526d..fdfe9be7d 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -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'] ?? ''); } diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 74a65e0ea..09d90e27c 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -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" => ""],