AttachmentShowRelated.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Plugin\AttachmentShowRelated;
  20. use App\Core\DB\DB;
  21. use App\Core\Event;
  22. use App\Core\Modules\Plugin;
  23. use App\Util\Common;
  24. use App\Util\Formatting;
  25. use Symfony\Component\HttpFoundation\Request;
  26. class AttachmentShowRelated extends Plugin
  27. {
  28. public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
  29. {
  30. if ($vars['path'] === 'note_attachment_show') {
  31. $related_notes = DB::dql('select n from attachment_to_note an '
  32. . 'join note n with n.id = an.note_id '
  33. . 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']], );
  34. $related_tags = DB::dql('select distinct t.tag '
  35. . 'from attachment_to_note an join note_tag t with an.note_id = t.note_id '
  36. . 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']], );
  37. $res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedNotes.html.twig', ['related_notes' => $related_notes, 'have_user' => Common::user() !== null]);
  38. $res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedTags.html.twig', ['related_tags' => $related_tags]);
  39. }
  40. return Event::next;
  41. }
  42. /**
  43. * Output our dedicated stylesheet
  44. *
  45. * @param array $styles stylesheets path
  46. *
  47. * @return bool hook value; true means continue processing, false means stop
  48. */
  49. public function onEndShowStyles(array &$styles, string $path): bool
  50. {
  51. if ($path === 'note_attachment_show') {
  52. $styles[] = '/assets/default_theme/css/pages/feeds.css';
  53. }
  54. return Event::next;
  55. }
  56. }