AttachmentShowRelated.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. class AttachmentShowRelated extends Plugin
  26. {
  27. public function onAppendRightPanelBlock($vars, &$res): bool
  28. {
  29. if ($vars['path'] === 'attachment_show') {
  30. $related_notes = DB::dql('select n from attachment_to_note an '
  31. . 'join note n with n.id = an.note_id '
  32. . 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']], );
  33. $related_tags = DB::dql('select distinct t.tag '
  34. . 'from attachment_to_note an join note_tag t with an.note_id = t.note_id '
  35. . 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']], );
  36. $res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedNotes.html.twig', ['related_notes' => $related_notes, 'have_user' => Common::user() !== null]);
  37. $res[] = Formatting::twigRenderFile('attachmentShowRelated/attachmentRelatedTags.html.twig', ['related_tags' => $related_tags]);
  38. }
  39. return Event::next;
  40. }
  41. /**
  42. * Output our dedicated stylesheet
  43. *
  44. * @param array $styles stylesheets path
  45. *
  46. * @return bool hook value; true means continue processing, false means stop
  47. */
  48. public function onEndShowStyles(array &$styles, string $path): bool
  49. {
  50. if ($path === 'attachment_show') {
  51. $styles[] = '/assets/default_theme/css/pages/feeds.css';
  52. }
  53. return Event::next;
  54. }
  55. }