1
0
Fork 0

Merge remote-tracking branch 'upstream/develop' into issue-12097

This commit is contained in:
Michael 2022-11-03 20:15:53 +00:00
commit a89f235044
7 changed files with 218 additions and 184 deletions

View file

@ -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) {
foreach (explode(',', Tag::getCSVByURIId($link_item['uri-id'])) as $tag_name) {
if ($tag_name) {
$tag_arr[] = [
'name' => $tag['name'],
'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag['name'])
'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]');
}
}

View file

@ -1,131 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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 .= '<h3>' . DI::l10n()->t('Remove Item Tag') . '</h3>';
$o .= '<p id="tag-remove-desc">' . DI::l10n()->t('Select a tag to remove: ') . '</p>';
$o .= '<form id="tagrm" action="tagrm" method="post" >';
$o .= '<input type="hidden" name="item" value="' . $item_id . '" />';
$o .= '<ul>';
foreach ($arr as $x) {
$o .= '<li><input type="checkbox" name="tag[]" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
}
$o .= '</ul>';
$o .= '<input id="tagrm-submit" type="submit" name="submit" value="' . DI::l10n()->t('Remove') .'" />';
$o .= '<input id="tagrm-cancel" type="submit" name="submit" value="' . DI::l10n()->t('Cancel') .'" />';
$o .= '</form>';
return $o;
}

View file

@ -68,7 +68,6 @@ class Mode
'objects',
'outbox',
'poco',
'post',
'pubsub',
'pubsubhubbub',
'receive',

View file

@ -0,0 +1,140 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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]);
}
}
}
}

View file

@ -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]],

View file

@ -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

View file

@ -0,0 +1,19 @@
<div class="generic-page-wrapper">
<h3>{{$l10n.header}}</h3>
<p id="tag-remove-desc">{{$l10n.desc}}</p>
<form id="tagrm" action="post/{{$item_id}}/tag/remove?return={{$return}}" method="post">
<ul>
{{foreach $tag_checkboxes as $tag_checkbox}}
<li>
{{include file="field_checkbox.tpl" field=$tag_checkbox}}
</li>
{{/foreach}}
</ul>
<p>
<button type="submit" id="tagrm-submit" class="btn btn-primary" name="submit">{{$l10n.remove}}</button>
<button type="submit" id="tagrm-submit" class="btn" name="cancel">{{$l10n.cancel}}</button>
</p>
</form>
</div>