From 50b1de5959c6e664715e53e2d8f61cb848c8d92b Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 5 Apr 2024 07:35:21 +0000 Subject: [PATCH 1/2] Menu option to display the search text --- src/Content/Item.php | 2 + src/Model/Post/Engagement.php | 8 ++ src/Module/Item/Searchtext.php | 72 ++++++++++++++++++ src/Object/Post.php | 1 + static/routes.config.php | 3 + view/js/main.js | 6 ++ view/lang/C/messages.po | 93 ++++++++++++----------- view/theme/frio/templates/search_item.tpl | 4 + view/theme/frio/templates/wall_thread.tpl | 7 ++ 9 files changed, 152 insertions(+), 44 deletions(-) create mode 100644 src/Module/Item/Searchtext.php diff --git a/src/Content/Item.php b/src/Content/Item.php index 721eba3320..823660969c 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -443,6 +443,8 @@ class Item $menu[$this->l10n->t('Languages')] = 'javascript:alert(\'' . ItemModel::getLanguageMessage($item) . '\');'; } + $menu[$this->l10n->t('Search Text')] = 'javascript:displaySearchText(' . $item['uri-id'] . ');'; + if ((($cid == 0) || ($rel == Contact::FOLLOWER)) && in_array($item['network'], Protocol::FEDERATED) ) { diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index f37aa3571c..9b2f1c27d1 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -418,4 +418,12 @@ class Engagement } return $fullTextSearch; } + + public static function unescapeKeywords(string $fullTextSearch): string + { + foreach (self::KEYWORDS as $keyword) { + $fullTextSearch = preg_replace('~(' . $keyword . ')_(.[\w\*@\.-]+)~', '$1:$2', $fullTextSearch); + } + return $fullTextSearch; + } } diff --git a/src/Module/Item/Searchtext.php b/src/Module/Item/Searchtext.php new file mode 100644 index 0000000000..9d9c594823 --- /dev/null +++ b/src/Module/Item/Searchtext.php @@ -0,0 +1,72 @@ +. + * + */ + +namespace Friendica\Module\Item; + +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Core\L10n; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Database\DBA; +use Friendica\Model\Post; +use Friendica\Module\Api\ApiResponse; +use Friendica\Network\HTTPException; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +/** + * Return the search text of a given item id + */ +class Searchtext extends BaseModule +{ + /** @var IHandleUserSessions */ + private $session; + + public function __construct(IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = []) + { + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->session = $session; + } + + protected function rawContent(array $request = []) + { + if (!$this->session->isAuthenticated()) { + throw new HttpException\ForbiddenException($this->l10n->t('Access denied.')); + } + + if (empty($this->parameters['id'])) { + throw new HTTPException\BadRequestException(); + } + + $item = Post::selectFirstForUser($this->session->getLocalUserId(), ['uri-id'], ['uid' => [0, $this->session->getLocalUserId()], 'uri-id' => $this->parameters['id']]); + if (empty($item)) { + throw new HTTPException\NotFoundException(); + } + + $search = DBA::selectFirst('post-searchindex', [], ['uri-id' => $item['uri-id']]); + if (empty($search)) { + throw new HTTPException\NotFoundException(); + } + + $this->httpExit(Post\Engagement::unescapeKeywords($search['searchtext'])); + } +} diff --git a/src/Object/Post.php b/src/Object/Post.php index f4210e4511..2bf76924a4 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -600,6 +600,7 @@ class Post 'tagger' => $tagger, 'filer' => $filer, 'language' => $languages, + 'searchtext' => DI::l10n()->t('Search Text'), 'drop' => $drop, 'block' => $block, 'ignore_author' => $ignore, diff --git a/static/routes.config.php b/static/routes.config.php index 559d87fca7..bc812e4c38 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -390,6 +390,8 @@ return [ '/event/{mode:edit|copy}/{id:\d+}' => [Module\Calendar\Event\Form::class, [R::GET ]], ], +// '/callback/searchtext', + '/channel[/{content}]' => [Module\Conversation\Channel::class, [R::GET]], '/community[/{content}]' => [Module\Conversation\Community::class, [R::GET]], @@ -482,6 +484,7 @@ return [ '/ignore' => [Module\Item\Ignore::class, [ R::POST]], '/pin' => [Module\Item\Pin::class, [ R::POST]], '/star' => [Module\Item\Star::class, [ R::POST]], + '/searchtext' => [Module\Item\Searchtext::class, [R::GET]], ], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], diff --git a/view/js/main.js b/view/js/main.js index 5363e3df16..27ae9b278c 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -797,6 +797,12 @@ function getPosition(e) { return cursor; } +function displaySearchText(id) { + $.get('item/' + id + '/searchtext', function(data) { + alert(data); + }); +} + var lockvisible = false; function lockview(event, type, id) { diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index b09b544fdb..76744231e0 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2024.06-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-03 07:49+0000\n" +"POT-Creation-Date: 2024-04-05 07:28+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -292,7 +292,7 @@ msgstr "" #: mod/message.php:201 mod/message.php:357 mod/photos.php:1297 #: src/Content/Conversation.php:400 src/Content/Conversation.php:1583 #: src/Module/Item/Compose.php:206 src/Module/Post/Edit.php:145 -#: src/Object/Post.php:624 +#: src/Object/Post.php:625 msgid "Please wait" msgstr "" @@ -314,7 +314,7 @@ msgstr "" #: src/Module/Moderation/Report/Create.php:263 #: src/Module/Profile/Profile.php:274 src/Module/Settings/Profile/Index.php:257 #: src/Module/Settings/Server/Action.php:79 src/Module/User/Delegation.php:189 -#: src/Object/Post.php:1169 view/theme/duepuntozero/config.php:85 +#: src/Object/Post.php:1170 view/theme/duepuntozero/config.php:85 #: view/theme/frio/config.php:150 view/theme/quattro/config.php:87 #: view/theme/vier/config.php:135 msgid "Submit" @@ -599,25 +599,25 @@ msgstr "" #: mod/photos.php:1135 mod/photos.php:1191 mod/photos.php:1271 #: src/Module/Contact.php:618 src/Module/Item/Compose.php:188 -#: src/Object/Post.php:1166 +#: src/Object/Post.php:1167 msgid "This is you" msgstr "" #: mod/photos.php:1137 mod/photos.php:1193 mod/photos.php:1273 -#: src/Module/Moderation/Reports.php:95 src/Object/Post.php:618 -#: src/Object/Post.php:1168 +#: src/Module/Moderation/Reports.php:95 src/Object/Post.php:619 +#: src/Object/Post.php:1169 msgid "Comment" msgstr "" #: mod/photos.php:1139 mod/photos.php:1195 mod/photos.php:1275 #: src/Content/Conversation.php:414 src/Module/Calendar/Event/Form.php:248 #: src/Module/Item/Compose.php:201 src/Module/Post/Edit.php:165 -#: src/Object/Post.php:1182 +#: src/Object/Post.php:1183 msgid "Preview" msgstr "" #: mod/photos.php:1140 src/Content/Conversation.php:368 -#: src/Module/Post/Edit.php:130 src/Object/Post.php:1170 +#: src/Module/Post/Edit.php:130 src/Object/Post.php:1171 msgid "Loading..." msgstr "" @@ -1244,7 +1244,7 @@ msgid "Visible to everybody" msgstr "" #: src/Content/Conversation.php:338 src/Module/Item/Compose.php:200 -#: src/Object/Post.php:1181 +#: src/Object/Post.php:1182 msgid "Please enter a image/video/audio/webpage URL:" msgstr "" @@ -1289,52 +1289,52 @@ msgid "attach file" msgstr "" #: src/Content/Conversation.php:373 src/Module/Item/Compose.php:190 -#: src/Module/Post/Edit.php:171 src/Object/Post.php:1171 +#: src/Module/Post/Edit.php:171 src/Object/Post.php:1172 msgid "Bold" msgstr "" #: src/Content/Conversation.php:374 src/Module/Item/Compose.php:191 -#: src/Module/Post/Edit.php:172 src/Object/Post.php:1172 +#: src/Module/Post/Edit.php:172 src/Object/Post.php:1173 msgid "Italic" msgstr "" #: src/Content/Conversation.php:375 src/Module/Item/Compose.php:192 -#: src/Module/Post/Edit.php:173 src/Object/Post.php:1173 +#: src/Module/Post/Edit.php:173 src/Object/Post.php:1174 msgid "Underline" msgstr "" #: src/Content/Conversation.php:376 src/Module/Item/Compose.php:193 -#: src/Module/Post/Edit.php:174 src/Object/Post.php:1175 +#: src/Module/Post/Edit.php:174 src/Object/Post.php:1176 msgid "Quote" msgstr "" #: src/Content/Conversation.php:377 src/Module/Item/Compose.php:194 -#: src/Module/Post/Edit.php:175 src/Object/Post.php:1176 +#: src/Module/Post/Edit.php:175 src/Object/Post.php:1177 msgid "Add emojis" msgstr "" #: src/Content/Conversation.php:378 src/Module/Item/Compose.php:195 -#: src/Object/Post.php:1174 +#: src/Object/Post.php:1175 msgid "Content Warning" msgstr "" #: src/Content/Conversation.php:379 src/Module/Item/Compose.php:196 -#: src/Module/Post/Edit.php:176 src/Object/Post.php:1177 +#: src/Module/Post/Edit.php:176 src/Object/Post.php:1178 msgid "Code" msgstr "" #: src/Content/Conversation.php:380 src/Module/Item/Compose.php:197 -#: src/Object/Post.php:1178 +#: src/Object/Post.php:1179 msgid "Image" msgstr "" #: src/Content/Conversation.php:381 src/Module/Item/Compose.php:198 -#: src/Module/Post/Edit.php:177 src/Object/Post.php:1179 +#: src/Module/Post/Edit.php:177 src/Object/Post.php:1180 msgid "Link" msgstr "" #: src/Content/Conversation.php:382 src/Module/Item/Compose.php:199 -#: src/Module/Post/Edit.php:178 src/Object/Post.php:1180 +#: src/Module/Post/Edit.php:178 src/Object/Post.php:1181 msgid "Link or Media" msgstr "" @@ -1887,7 +1887,7 @@ msgstr "" msgid "View Status" msgstr "" -#: src/Content/Item.php:431 src/Content/Item.php:452 src/Model/Contact.php:1177 +#: src/Content/Item.php:431 src/Content/Item.php:454 src/Model/Contact.php:1177 #: src/Model/Contact.php:1233 src/Model/Contact.php:1243 #: src/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:259 msgid "View Profile" @@ -1942,13 +1942,17 @@ msgstr "" msgid "Languages" msgstr "" -#: src/Content/Item.php:449 src/Content/Widget.php:80 +#: src/Content/Item.php:446 src/Object/Post.php:603 +msgid "Search Text" +msgstr "" + +#: src/Content/Item.php:451 src/Content/Widget.php:80 #: src/Model/Contact.php:1236 src/Model/Contact.php:1248 #: src/Module/Contact/Follow.php:167 view/theme/vier/theme.php:195 msgid "Connect/Follow" msgstr "" -#: src/Content/Item.php:883 +#: src/Content/Item.php:885 msgid "Unable to fetch user." msgstr "" @@ -6653,7 +6657,8 @@ msgstr[1] "" #: src/Module/Item/Display.php:96 src/Module/Item/Feed.php:59 #: src/Module/Item/Follow.php:41 src/Module/Item/Ignore.php:41 #: src/Module/Item/Pin.php:41 src/Module/Item/Pin.php:56 -#: src/Module/Item/Star.php:42 src/Module/Update/Display.php:37 +#: src/Module/Item/Searchtext.php:53 src/Module/Item/Star.php:42 +#: src/Module/Update/Display.php:37 msgid "Access denied." msgstr "" @@ -12466,101 +12471,101 @@ msgstr "" msgid "via Wall-To-Wall:" msgstr "" -#: src/Object/Post.php:619 +#: src/Object/Post.php:620 #, php-format msgid "Reply to %s" msgstr "" -#: src/Object/Post.php:622 +#: src/Object/Post.php:623 msgid "More" msgstr "" -#: src/Object/Post.php:641 +#: src/Object/Post.php:642 msgid "Notifier task is pending" msgstr "" -#: src/Object/Post.php:642 +#: src/Object/Post.php:643 msgid "Delivery to remote servers is pending" msgstr "" -#: src/Object/Post.php:643 +#: src/Object/Post.php:644 msgid "Delivery to remote servers is underway" msgstr "" -#: src/Object/Post.php:644 +#: src/Object/Post.php:645 msgid "Delivery to remote servers is mostly done" msgstr "" -#: src/Object/Post.php:645 +#: src/Object/Post.php:646 msgid "Delivery to remote servers is done" msgstr "" -#: src/Object/Post.php:667 +#: src/Object/Post.php:668 #, php-format msgid "%d comment" msgid_plural "%d comments" msgstr[0] "" msgstr[1] "" -#: src/Object/Post.php:668 +#: src/Object/Post.php:669 msgid "Show more" msgstr "" -#: src/Object/Post.php:669 +#: src/Object/Post.php:670 msgid "Show fewer" msgstr "" -#: src/Object/Post.php:706 +#: src/Object/Post.php:707 #, php-format msgid "Reshared by: %s" msgstr "" -#: src/Object/Post.php:711 +#: src/Object/Post.php:712 #, php-format msgid "Viewed by: %s" msgstr "" -#: src/Object/Post.php:716 +#: src/Object/Post.php:717 #, php-format msgid "Read by: %s" msgstr "" -#: src/Object/Post.php:721 +#: src/Object/Post.php:722 #, php-format msgid "Liked by: %s" msgstr "" -#: src/Object/Post.php:726 +#: src/Object/Post.php:727 #, php-format msgid "Disliked by: %s" msgstr "" -#: src/Object/Post.php:731 +#: src/Object/Post.php:732 #, php-format msgid "Attended by: %s" msgstr "" -#: src/Object/Post.php:736 +#: src/Object/Post.php:737 #, php-format msgid "Maybe attended by: %s" msgstr "" -#: src/Object/Post.php:741 +#: src/Object/Post.php:742 #, php-format msgid "Not attended by: %s" msgstr "" -#: src/Object/Post.php:746 +#: src/Object/Post.php:747 #, php-format msgid "Commented by: %s" msgstr "" -#: src/Object/Post.php:751 +#: src/Object/Post.php:752 #, php-format msgid "Reacted with %s by: %s" msgstr "" -#: src/Object/Post.php:774 +#: src/Object/Post.php:775 #, php-format msgid "Quote shared by: %s" msgstr "" diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index f23e71d995..2472bfa27b 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -225,6 +225,10 @@ {{/if}} +
  • +  {{$item.searchtext}} +
  • + {{if $item.browsershare}} {{/if}} +
  • +  {{$item.searchtext}} +
  • + {{if $item.browsershare}} {{/if}} +
  • +  {{$item.searchtext}} +
  • {{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread) && ($item.ignore || ($item.drop && $item.drop.dropping))}} From b40687081e1a520eca21a20ce0eeefce8df5de2d Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 5 Apr 2024 09:57:43 +0000 Subject: [PATCH 2/2] The data for the language display is now fetched on demand --- src/Content/Item.php | 2 +- src/Module/Item/Language.php | 67 +++++++++++++++++++++++ src/Object/Post.php | 2 +- static/routes.config.php | 5 +- view/js/main.js | 6 ++ view/theme/frio/templates/search_item.tpl | 2 +- view/theme/frio/templates/wall_thread.tpl | 4 +- 7 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/Module/Item/Language.php diff --git a/src/Content/Item.php b/src/Content/Item.php index 823660969c..aa8662705c 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -440,7 +440,7 @@ class Item ]; if (!empty($item['language'])) { - $menu[$this->l10n->t('Languages')] = 'javascript:alert(\'' . ItemModel::getLanguageMessage($item) . '\');'; + $menu[$this->l10n->t('Languages')] = 'javascript:displayLanguage(' . $item['uri-id'] . ');'; } $menu[$this->l10n->t('Search Text')] = 'javascript:displaySearchText(' . $item['uri-id'] . ');'; diff --git a/src/Module/Item/Language.php b/src/Module/Item/Language.php new file mode 100644 index 0000000000..519a6bf4d1 --- /dev/null +++ b/src/Module/Item/Language.php @@ -0,0 +1,67 @@ +. + * + */ + +namespace Friendica\Module\Item; + +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Core\L10n; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Model\Item; +use Friendica\Model\Post; +use Friendica\Module\Api\ApiResponse; +use Friendica\Network\HTTPException; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +/** + * Return the language of a given item uri-id + */ +class Language extends BaseModule +{ + /** @var IHandleUserSessions */ + private $session; + + public function __construct(IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = []) + { + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->session = $session; + } + + protected function rawContent(array $request = []) + { + if (!$this->session->isAuthenticated()) { + throw new HttpException\ForbiddenException($this->l10n->t('Access denied.')); + } + + if (empty($this->parameters['id'])) { + throw new HTTPException\BadRequestException(); + } + + $item = Post::selectFirstForUser($this->session->getLocalUserId(), ['language'], ['uid' => [0, $this->session->getLocalUserId()], 'uri-id' => $this->parameters['id']]); + if (empty($item)) { + throw new HTTPException\NotFoundException(); + } + + $this->httpExit(Item::getLanguageMessage($item)); + } +} diff --git a/src/Object/Post.php b/src/Object/Post.php index 2bf76924a4..b341612e8c 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -521,7 +521,7 @@ class Post $languages = []; if (!empty($item['language'])) { - $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)]; + $languages = DI::l10n()->t('Languages'); } if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($item['network'], Protocol::FEDERATED)) { diff --git a/static/routes.config.php b/static/routes.config.php index bc812e4c38..0f603b7e3b 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -390,8 +390,6 @@ return [ '/event/{mode:edit|copy}/{id:\d+}' => [Module\Calendar\Event\Form::class, [R::GET ]], ], -// '/callback/searchtext', - '/channel[/{content}]' => [Module\Conversation\Channel::class, [R::GET]], '/community[/{content}]' => [Module\Conversation\Community::class, [R::GET]], @@ -482,9 +480,10 @@ return [ '/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], '/follow' => [Module\Item\Follow::class, [ R::POST]], '/ignore' => [Module\Item\Ignore::class, [ R::POST]], + '/language' => [Module\Item\Language::class, [R::GET]], '/pin' => [Module\Item\Pin::class, [ R::POST]], - '/star' => [Module\Item\Star::class, [ R::POST]], '/searchtext' => [Module\Item\Searchtext::class, [R::GET]], + '/star' => [Module\Item\Star::class, [ R::POST]], ], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], diff --git a/view/js/main.js b/view/js/main.js index 27ae9b278c..89ca7607d1 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -803,6 +803,12 @@ function displaySearchText(id) { }); } +function displayLanguage(id) { + $.get('item/' + id + '/language', function(data) { + alert(data); + }); +} + var lockvisible = false; function lockview(event, type, id) { diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 2472bfa27b..d2baaa56d7 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -221,7 +221,7 @@ {{if $item.language}}
  • -  {{$item.language.0}} +  {{$item.language}}
  • {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 63cddb99e1..b88da822bb 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -433,7 +433,7 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.language}}
  • -  {{$item.language.0}} +  {{$item.language}}
  • {{/if}} @@ -620,7 +620,7 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.language}}
  • -  {{$item.language.0}} +  {{$item.language}}
  • {{/if}}