diff --git a/mod/photos.php b/mod/photos.php index 2d7516be93..ccf0525cb0 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1250,15 +1250,17 @@ function photos_content(App $a) if (!empty($link_item['id'])) { // parse tags and add links $tag_arr = []; - foreach (Tag::getByURIId($link_item['uri-id']) as $tag) { - $tag_arr[] = [ - 'name' => $tag['name'], - 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag['name']) - ]; + foreach (explode(',', Tag::getCSVByURIId($link_item['uri-id'])) as $tag_name) { + if ($tag_name) { + $tag_arr[] = [ + 'name' => BBCode::toPlaintext($tag_name), + 'removeurl' => 'post/' . $link_item['id'] . '/tag/remove/' . bin2hex($tag_name) . '?return=' . urlencode(DI::args()->getCommand()), + ]; + } } $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr]; if ($cmd === 'edit') { - $tags['removeanyurl'] = 'tagrm/' . $link_item['id']; + $tags['removeanyurl'] = 'post/' . $link_item['id'] . '/tag/remove?return=' . urlencode(DI::args()->getCommand()); $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]'); } } diff --git a/mod/tagrm.php b/mod/tagrm.php deleted file mode 100644 index 26d2c905fd..0000000000 --- a/mod/tagrm.php +++ /dev/null @@ -1,131 +0,0 @@ -. - * - */ - -use Friendica\App; -use Friendica\Content\Text\BBCode; -use Friendica\Database\DBA; -use Friendica\DI; -use Friendica\Model\Post; -use Friendica\Model\Tag; - -function tagrm_post(App $a) -{ - if (!DI::userSession()->getLocalUserId()) { - DI::baseUrl()->redirect($_SESSION['photo_return']); - } - - if (!empty($_POST['submit']) && ($_POST['submit'] === DI::l10n()->t('Cancel'))) { - DI::baseUrl()->redirect($_SESSION['photo_return']); - } - - $tags = []; - foreach ($_POST['tag'] ?? [] as $tag) { - $tags[] = hex2bin(trim($tag)); - } - - $item_id = $_POST['item'] ?? 0; - update_tags($item_id, $tags); - - DI::baseUrl()->redirect($_SESSION['photo_return']); - // NOTREACHED -} - -/** - * Updates tags from an item - * - * @param $item_id - * @param $tags array - * @throws Exception - */ -function update_tags($item_id, $tags) -{ - if (empty($item_id) || empty($tags)) { - return; - } - - $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => DI::userSession()->getLocalUserId()]); - if (!DBA::isResult($item)) { - return; - } - - foreach ($tags as $new_tag) { - if (preg_match_all('/([#@!])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism', $new_tag, $results, PREG_SET_ORDER)) { - foreach ($results as $tag) { - Tag::removeByHash($item['uri-id'], $tag[1], $tag[3], $tag[2]); - } - } - } -} - -function tagrm_content(App $a) -{ - $o = ''; - - $photo_return = $_SESSION['photo_return'] ?? ''; - - if (!DI::userSession()->getLocalUserId()) { - DI::baseUrl()->redirect($photo_return); - // NOTREACHED - } - - if (DI::args()->getArgc()== 3) { - update_tags(DI::args()->getArgv()[1], [trim(hex2bin(DI::args()->getArgv()[2]))]); - DI::baseUrl()->redirect($photo_return); - } - - $item_id = ((DI::args()->getArgc()> 1) ? intval(DI::args()->getArgv()[1]) : 0); - if (!$item_id) { - DI::baseUrl()->redirect($photo_return); - // NOTREACHED - } - - $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => DI::userSession()->getLocalUserId()]); - if (!DBA::isResult($item)) { - DI::baseUrl()->redirect($photo_return); - } - - $tag_text = Tag::getCSVByURIId($item['uri-id']); - - $arr = explode(',', $tag_text); - - if (empty($arr)) { - DI::baseUrl()->redirect($photo_return); - } - - $o .= '

' . DI::l10n()->t('Remove Item Tag') . '

'; - - $o .= '

' . DI::l10n()->t('Select a tag to remove: ') . '

'; - - $o .= '
'; - $o .= ''; - $o .= ''; - $o .= ''; - $o .= ''; - $o .= '
'; - - return $o; -} diff --git a/src/App/Mode.php b/src/App/Mode.php index 5d6bd759f2..59a47d8284 100644 --- a/src/App/Mode.php +++ b/src/App/Mode.php @@ -68,7 +68,6 @@ class Mode 'objects', 'outbox', 'poco', - 'post', 'pubsub', 'pubsubhubbub', 'receive', diff --git a/src/Module/Post/Tag/Remove.php b/src/Module/Post/Tag/Remove.php new file mode 100644 index 0000000000..94a1ecfe49 --- /dev/null +++ b/src/Module/Post/Tag/Remove.php @@ -0,0 +1,140 @@ +. + * + */ + +namespace Friendica\Module\Post\Tag; + +use Friendica\App; +use Friendica\Content\Text\BBCode; +use Friendica\Core\L10n; +use Friendica\Core\Renderer; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Model\Post; +use Friendica\Model\Tag; +use Friendica\Module\Response; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +class Remove extends \Friendica\BaseModule +{ + /** @var IHandleUserSessions */ + private $session; + + public function __construct(IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) + { + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->session = $session; + } + + protected function post(array $request = []) + { + if (!$this->session->getLocalUserId()) { + $this->baseUrl->redirect($request['return'] ?? ''); + } + + + if (isset($request['cancel'])) { + $this->baseUrl->redirect($request['return'] ?? ''); + } + + $tags = []; + foreach ($request['tag'] ?? [] as $tag => $checked) { + if ($checked) { + $tags[] = hex2bin(trim($tag)); + } + } + + $this->removeTagsFromItem($this->parameters['item_id'], $tags); + $this->baseUrl->redirect($request['return'] ?? ''); + } + + protected function content(array $request = []): string + { + $returnUrl = $request['return'] ?? ''; + + if (!$this->session->getLocalUserId()) { + $this->baseUrl->redirect($returnUrl); + } + + if (isset($this->parameters['tag_name'])) { + $this->removeTagsFromItem($this->parameters['item_id'], [trim(hex2bin($this->parameters['tag_name']))]); + $this->baseUrl->redirect($returnUrl); + } + + $item_id = intval($this->parameters['item_id']); + if (!$item_id) { + $this->baseUrl->redirect($returnUrl); + } + + $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => $this->session->getLocalUserId()]); + if (!$item) { + $this->baseUrl->redirect($returnUrl); + } + + $tag_text = Tag::getCSVByURIId($item['uri-id']); + + $tags = explode(',', $tag_text); + if (empty($tags)) { + $this->baseUrl->redirect($returnUrl); + } + + $tag_checkboxes = array_map(function ($tag_text) { + return ['tag[' . bin2hex($tag_text) . ']', BBCode::toPlaintext($tag_text)]; + }, $tags); + + $tpl = Renderer::getMarkupTemplate('post/tag/remove.tpl'); + return Renderer::replaceMacros($tpl, [ + '$l10n' => [ + 'header' => $this->t('Remove Item Tag'), + 'desc' => $this->t('Select a tag to remove: '), + 'remove' => $this->t('Remove'), + 'cancel' => $this->t('Cancel'), + ], + + '$item_id' => $item_id, + '$return' => $returnUrl, + '$tag_checkboxes' => $tag_checkboxes, + ]); + } + + /** + * @param int $item_id + * @param array $tags + * @throws \Exception + */ + private function removeTagsFromItem(int $item_id, array $tags) + { + if (empty($item_id) || empty($tags)) { + return; + } + + $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => $this->session->getLocalUserId()]); + if (empty($item)) { + return; + } + + foreach ($tags as $tag) { + if (preg_match('~([#@!])\[url=([^\[\]]*)]([^\[\]]*)\[/url]~im', $tag, $results)) { + Tag::removeByHash($item['uri-id'], $results[1], $results[3], $results[2]); + } + } + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 53bbf3eb7f..9066c48762 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -531,6 +531,11 @@ return [ ], '/ping' => [Module\Notifications\Ping::class, [R::GET]], + + '/post' => [ + '/{item_id}/tag/remove[/{tag_name}]' => [Module\Post\Tag\Remove::class, [R::GET, R::POST]], + ], + '/pretheme' => [Module\ThemeDetails::class, [R::GET]], '/probe' => [Module\Debug\Probe::class, [R::GET]], diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index c3e5f12313..c38783a502 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -148,7 +148,7 @@ msgstr "" msgid "Save" msgstr "" -#: mod/editpost.php:92 mod/photos.php:1333 src/Content/Conversation.php:341 +#: mod/editpost.php:92 mod/photos.php:1335 src/Content/Conversation.php:341 #: src/Object/Post.php:987 msgid "Loading..." msgstr "" @@ -213,7 +213,7 @@ msgid "clear location" msgstr "" #: mod/editpost.php:107 mod/message.php:203 mod/message.php:360 -#: mod/photos.php:1484 src/Content/Conversation.php:371 +#: mod/photos.php:1486 src/Content/Conversation.php:371 #: src/Content/Conversation.php:717 src/Module/Item/Compose.php:204 #: src/Module/Profile/UnkMail.php:155 src/Object/Post.php:537 msgid "Please wait" @@ -245,16 +245,16 @@ msgstr "" msgid "Example: bob@example.com, mary@example.com" msgstr "" -#: mod/editpost.php:128 mod/events.php:514 mod/photos.php:1332 -#: mod/photos.php:1388 mod/photos.php:1462 src/Content/Conversation.php:386 +#: mod/editpost.php:128 mod/events.php:514 mod/photos.php:1334 +#: mod/photos.php:1390 mod/photos.php:1464 src/Content/Conversation.php:386 #: src/Module/Item/Compose.php:199 src/Object/Post.php:997 msgid "Preview" msgstr "" #: mod/editpost.php:130 mod/fbrowser.php:119 mod/fbrowser.php:146 -#: mod/photos.php:999 mod/photos.php:1100 mod/tagrm.php:35 mod/tagrm.php:127 -#: src/Content/Conversation.php:389 src/Module/Contact/Follow.php:171 -#: src/Module/Contact/Revoke.php:109 src/Module/Contact/Unfollow.php:126 +#: mod/photos.php:999 mod/photos.php:1100 src/Content/Conversation.php:389 +#: src/Module/Contact/Follow.php:171 src/Module/Contact/Revoke.php:109 +#: src/Module/Contact/Unfollow.php:126 src/Module/Post/Tag/Remove.php:109 #: src/Module/Profile/RemoteFollow.php:134 #: src/Module/Security/TwoFactor/SignOut.php:125 msgid "Cancel" @@ -307,7 +307,7 @@ msgid "Browser" msgstr "" #: mod/editpost.php:145 mod/events.php:519 mod/photos.php:934 -#: mod/photos.php:1286 src/Content/Conversation.php:373 +#: mod/photos.php:1288 src/Content/Conversation.php:373 msgid "Permissions" msgstr "" @@ -390,8 +390,8 @@ msgid "Share this event" msgstr "" #: mod/events.php:516 mod/message.php:204 mod/message.php:359 -#: mod/photos.php:916 mod/photos.php:1020 mod/photos.php:1290 -#: mod/photos.php:1331 mod/photos.php:1387 mod/photos.php:1461 +#: mod/photos.php:916 mod/photos.php:1020 mod/photos.php:1292 +#: mod/photos.php:1333 mod/photos.php:1389 mod/photos.php:1463 #: src/Module/Admin/Item/Source.php:60 src/Module/Contact/Advanced.php:132 #: src/Module/Contact/Profile.php:328 #: src/Module/Debug/ActivityPubConversion.php:140 @@ -785,11 +785,11 @@ msgstr "" msgid "Photo Albums" msgstr "" -#: mod/photos.php:108 mod/photos.php:1579 +#: mod/photos.php:108 mod/photos.php:1581 msgid "Recent Photos" msgstr "" -#: mod/photos.php:110 mod/photos.php:1068 mod/photos.php:1581 +#: mod/photos.php:110 mod/photos.php:1068 mod/photos.php:1583 msgid "Upload New Photos" msgstr "" @@ -910,7 +910,7 @@ msgstr "" msgid "Show Oldest First" msgstr "" -#: mod/photos.php:1053 mod/photos.php:1564 +#: mod/photos.php:1053 mod/photos.php:1566 msgid "View Photo" msgstr "" @@ -926,7 +926,7 @@ msgstr "" msgid "Do you really want to delete this photo?" msgstr "" -#: mod/photos.php:1099 mod/photos.php:1291 +#: mod/photos.php:1099 mod/photos.php:1293 msgid "Delete Photo" msgstr "" @@ -954,84 +954,84 @@ msgstr "" msgid "View Full Size" msgstr "" -#: mod/photos.php:1259 +#: mod/photos.php:1261 msgid "Tags: " msgstr "" -#: mod/photos.php:1262 +#: mod/photos.php:1264 msgid "[Select tags to remove]" msgstr "" -#: mod/photos.php:1277 +#: mod/photos.php:1279 msgid "New album name" msgstr "" -#: mod/photos.php:1278 +#: mod/photos.php:1280 msgid "Caption" msgstr "" -#: mod/photos.php:1279 +#: mod/photos.php:1281 msgid "Add a Tag" msgstr "" -#: mod/photos.php:1279 +#: mod/photos.php:1281 msgid "Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping" msgstr "" -#: mod/photos.php:1280 +#: mod/photos.php:1282 msgid "Do not rotate" msgstr "" -#: mod/photos.php:1281 +#: mod/photos.php:1283 msgid "Rotate CW (right)" msgstr "" -#: mod/photos.php:1282 +#: mod/photos.php:1284 msgid "Rotate CCW (left)" msgstr "" -#: mod/photos.php:1328 mod/photos.php:1384 mod/photos.php:1458 +#: mod/photos.php:1330 mod/photos.php:1386 mod/photos.php:1460 #: src/Module/Contact.php:547 src/Module/Item/Compose.php:188 #: src/Object/Post.php:983 msgid "This is you" msgstr "" -#: mod/photos.php:1330 mod/photos.php:1386 mod/photos.php:1460 +#: mod/photos.php:1332 mod/photos.php:1388 mod/photos.php:1462 #: src/Object/Post.php:531 src/Object/Post.php:985 msgid "Comment" msgstr "" -#: mod/photos.php:1419 src/Content/Conversation.php:633 src/Object/Post.php:255 +#: mod/photos.php:1421 src/Content/Conversation.php:633 src/Object/Post.php:255 msgid "Select" msgstr "" -#: mod/photos.php:1420 mod/settings.php:350 src/Content/Conversation.php:634 +#: mod/photos.php:1422 mod/settings.php:350 src/Content/Conversation.php:634 #: src/Module/Admin/Users/Active.php:139 src/Module/Admin/Users/Blocked.php:140 #: src/Module/Admin/Users/Index.php:153 msgid "Delete" msgstr "" -#: mod/photos.php:1481 src/Object/Post.php:378 +#: mod/photos.php:1483 src/Object/Post.php:378 msgid "Like" msgstr "" -#: mod/photos.php:1482 src/Object/Post.php:378 +#: mod/photos.php:1484 src/Object/Post.php:378 msgid "I like this (toggle)" msgstr "" -#: mod/photos.php:1483 src/Object/Post.php:379 +#: mod/photos.php:1485 src/Object/Post.php:379 msgid "Dislike" msgstr "" -#: mod/photos.php:1485 src/Object/Post.php:379 +#: mod/photos.php:1487 src/Object/Post.php:379 msgid "I don't like this (toggle)" msgstr "" -#: mod/photos.php:1507 +#: mod/photos.php:1509 msgid "Map" msgstr "" -#: mod/photos.php:1570 +#: mod/photos.php:1572 msgid "View Album" msgstr "" @@ -1346,19 +1346,6 @@ msgstr "" msgid "%1$s tagged %2$s's %3$s with %4$s" msgstr "" -#: mod/tagrm.php:113 -msgid "Remove Item Tag" -msgstr "" - -#: mod/tagrm.php:115 -msgid "Select a tag to remove: " -msgstr "" - -#: mod/tagrm.php:126 src/Module/Settings/Delegation.php:178 -#: src/Module/Settings/TwoFactor/Trusted.php:143 -msgid "Remove" -msgstr "" - #: src/App.php:490 msgid "No system theme config value set." msgstr "" @@ -8228,6 +8215,19 @@ msgstr "" msgid "Invalid photo with id %s." msgstr "" +#: src/Module/Post/Tag/Remove.php:106 +msgid "Remove Item Tag" +msgstr "" + +#: src/Module/Post/Tag/Remove.php:107 +msgid "Select a tag to remove: " +msgstr "" + +#: src/Module/Post/Tag/Remove.php:108 src/Module/Settings/Delegation.php:178 +#: src/Module/Settings/TwoFactor/Trusted.php:143 +msgid "Remove" +msgstr "" + #: src/Module/Profile/Attachment/Upload.php:80 #: src/Module/Profile/Attachment/Upload.php:102 #: src/Module/Profile/Photos/Upload.php:113 diff --git a/view/templates/post/tag/remove.tpl b/view/templates/post/tag/remove.tpl new file mode 100644 index 0000000000..86c54af911 --- /dev/null +++ b/view/templates/post/tag/remove.tpl @@ -0,0 +1,19 @@ +
+

{{$l10n.header}}

+ +

{{$l10n.desc}}

+ +
+ +

+ + +

+
+