Group.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Component\Group;
  20. use App\Core\Event;
  21. use function App\Core\I18n\_m;
  22. use App\Core\Modules\Component;
  23. use App\Core\Router\RouteLoader;
  24. use App\Core\Router\Router;
  25. use App\Entity\Actor;
  26. use App\Util\Common;
  27. use App\Util\HTML;
  28. use App\Util\Nickname;
  29. use Component\Group\Controller as C;
  30. use Component\Tag\Controller\Tag as TagController;
  31. use Symfony\Component\HttpFoundation\Request;
  32. class Group extends Component
  33. {
  34. public function onAddRoute(RouteLoader $r): bool
  35. {
  36. $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']);
  37. $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]);
  38. $r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]);
  39. return Event::next;
  40. }
  41. /**
  42. * Add an <a href=group_settings> to the profile card for groups, if the current actor can access them
  43. */
  44. public function onAppendCardProfile(array $vars, array &$res): bool
  45. {
  46. $actor = Common::actor();
  47. $group = $vars['actor'];
  48. if (!\is_null($actor) && $group->isGroup() && $actor->canAdmin($group)) {
  49. $url = Router::url('group_settings', ['nickname' => $group->getNickname()]);
  50. $res[] = HTML::html(['hr' => '', 'a' => ['attrs' => ['href' => $url, 'title' => _m('Edit group settings')], 'p' => _m('Group settings')]]);
  51. }
  52. return Event::next;
  53. }
  54. public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs)
  55. {
  56. if ($section === 'profile' && $request->get('_route') === 'group_settings') {
  57. $nickname = $request->get('nickname');
  58. $group = Actor::getByNickname($nickname, type: Actor::GROUP);
  59. $tabs[] = [
  60. 'title' => 'Self tags',
  61. 'desc' => 'Add or remove tags on this group',
  62. 'id' => 'settings-self-tags',
  63. 'controller' => TagController::settingsSelfTags($request, $group, 'settings-self-tags-details'),
  64. ];
  65. }
  66. return Event::next;
  67. }
  68. }