GroupFavoritedPlugin.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * The GroupFavorited plugin adds a menu item for popular notices in groups.
  18. *
  19. * @package GroupFavoritedPlugin
  20. * @author Brion Vibber <brion@status.net>
  21. * @author Diogo Cordeiro <diogo@fc.up.pt>
  22. * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. class GroupFavoritedPlugin extends Plugin
  27. {
  28. const PLUGIN_VERSION = '2.0.1';
  29. /**
  30. * Hook for RouterInitialized event.
  31. *
  32. * @param URLMapper $m path-to-action mapper
  33. * @return boolean hook return
  34. * @throws Exception
  35. */
  36. public function onRouterInitialized(URLMapper $m)
  37. {
  38. $m->connect(
  39. 'group/:nickname/favorited',
  40. ['action' => 'groupfavorited'],
  41. ['nickname' => '[a-zA-Z0-9]+']
  42. );
  43. return true;
  44. }
  45. public function onEndGroupActionsList(GroupProfileBlock $nav, User_group $group)
  46. {
  47. $nav->out->elementStart('li', 'entity_popular');
  48. $nav->out->element(
  49. 'a',
  50. [
  51. 'href' => common_local_url(
  52. 'groupfavorited',
  53. ['nickname' => $group->nickname]
  54. ),
  55. // TRANS: Tooltip for menu item in the group navigation page.
  56. // TRANS: %s is the nickname of the group.
  57. 'title' => sprintf(_m('TOOLTIP', 'Popular notices in %s group'), $group->nickname)
  58. ],
  59. // TRANS: Menu item in the group navigation page.
  60. _m('MENU', 'Popular')
  61. );
  62. $nav->out->elementEnd('li');
  63. }
  64. /**
  65. * Provide plugin version information.
  66. *
  67. * This data is used when showing the version page.
  68. *
  69. * @param array &$versions array of version data arrays; see EVENTS.txt
  70. *
  71. * @return bool hook value
  72. */
  73. public function onPluginVersion(array &$versions): bool
  74. {
  75. $url = 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/GroupFavorited';
  76. $versions[] = ['name' => 'GroupFavorited',
  77. 'version' => self::PLUGIN_VERSION,
  78. 'author' => 'Brion Vibber',
  79. 'homepage' => $url,
  80. 'rawdescription' =>
  81. // TRANS: Plugin description.
  82. _m('This plugin adds a menu item for popular notices in groups.')
  83. ];
  84. return true;
  85. }
  86. }