2021-04-30 09:51:59 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-04-30 09:51:59 +09:00
|
|
|
// {{{ License
|
|
|
|
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
namespace Plugin\AttachmentShowRelated;
|
|
|
|
|
2022-03-27 23:19:09 +09:00
|
|
|
use App\Core\DB;
|
2021-04-30 09:51:59 +09:00
|
|
|
use App\Core\Event;
|
|
|
|
use App\Core\Modules\Plugin;
|
2021-08-12 07:42:08 +09:00
|
|
|
use App\Util\Common;
|
2021-04-30 09:51:59 +09:00
|
|
|
use App\Util\Formatting;
|
2022-04-04 05:40:32 +09:00
|
|
|
use EventResult;
|
2022-01-17 10:36:12 +09:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2021-04-30 09:51:59 +09:00
|
|
|
|
|
|
|
class AttachmentShowRelated extends Plugin
|
|
|
|
{
|
2022-10-20 06:39:17 +09:00
|
|
|
/**
|
|
|
|
* @param array<string, mixed> $vars
|
2022-10-20 06:39:17 +09:00
|
|
|
* @param string[] $res
|
2022-10-20 06:39:17 +09:00
|
|
|
*/
|
|
|
|
public function onAppendRightPanelBlock(Request $request, array $vars, array &$res): EventResult
|
2021-04-30 09:51:59 +09:00
|
|
|
{
|
2021-12-27 11:47:04 +09:00
|
|
|
if ($vars['path'] === 'note_attachment_show') {
|
2021-10-10 17:26:18 +09:00
|
|
|
$related_notes = DB::dql('select n from attachment_to_note an '
|
|
|
|
. 'join note n with n.id = an.note_id '
|
|
|
|
. 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']], );
|
|
|
|
$related_tags = DB::dql('select distinct t.tag '
|
|
|
|
. 'from attachment_to_note an join note_tag t with an.note_id = t.note_id '
|
|
|
|
. 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']], );
|
2021-08-12 07:42:08 +09:00
|
|
|
$res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedNotes.html.twig', ['related_notes' => $related_notes, 'have_user' => Common::user() !== null]);
|
2021-05-01 06:29:42 +09:00
|
|
|
$res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedTags.html.twig', ['related_tags' => $related_tags]);
|
2021-04-30 09:51:59 +09:00
|
|
|
}
|
|
|
|
return Event::next;
|
|
|
|
}
|
2021-10-06 08:34:27 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Output our dedicated stylesheet
|
|
|
|
*
|
2022-10-20 06:39:17 +09:00
|
|
|
* @param string[] $styles stylesheets path
|
2021-10-06 08:34:27 +09:00
|
|
|
*/
|
2022-04-04 05:40:32 +09:00
|
|
|
public function onEndShowStyles(array &$styles, string $path): EventResult
|
2021-10-06 08:34:27 +09:00
|
|
|
{
|
2022-01-04 02:51:19 +09:00
|
|
|
if ($path === 'note_attachment_show') {
|
2022-02-08 23:12:59 +09:00
|
|
|
$styles[] = '/assets/default_theme/pages/feeds.css';
|
2021-10-06 08:34:27 +09:00
|
|
|
}
|
|
|
|
return Event::next;
|
|
|
|
}
|
2021-10-10 17:26:18 +09:00
|
|
|
}
|