TagCloudPlugin.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * GNU social plugin for "tag clouds" in the UI
  4. *
  5. * @category UI
  6. * @package GNUsocial
  7. * @author Mikael Nordfeldth <mmn@hethane.se>
  8. * @copyright 2016 Free Software Foundation, Inc.
  9. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  10. * @link http://gnu.io/social/
  11. */
  12. if (!defined('GNUSOCIAL')) { exit(1); }
  13. class TagCloudPlugin extends Plugin {
  14. public function onRouterInitialized(URLMapper $m)
  15. {
  16. $m->connect('tags/', array('action' => 'publictagcloud'));
  17. $m->connect('tag/', array('action' => 'publictagcloud'));
  18. $m->connect('tags', array('action' => 'publictagcloud'));
  19. $m->connect('tag', array('action' => 'publictagcloud'));
  20. }
  21. public function onEndPublicGroupNav(Menu $menu)
  22. {
  23. // TRANS: Menu item in search group navigation panel.
  24. $menu->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'),
  25. // TRANS: Menu item title in search group navigation panel.
  26. _('Recent tags'), $menu->actionName === 'publictagcloud', 'nav_recent-tags');
  27. }
  28. public function onEndShowSections(Action $action)
  29. {
  30. $cloud = null;
  31. switch (true) {
  32. case $action instanceof AllAction:
  33. $cloud = new InboxTagCloudSection($action, $action->getTarget());
  34. break;
  35. case $action instanceof AttachmentAction:
  36. $cloud = new AttachmentTagCloudSection($action);
  37. break;
  38. case $action instanceof PublicAction:
  39. $cloud = new PublicTagCloudSection($action);
  40. break;
  41. case $action instanceof ShowstreamAction:
  42. $cloud = new PersonalTagCloudSection($action, $action->getTarget());
  43. break;
  44. case $action instanceof GroupAction:
  45. $cloud = new GroupTagCloudSection($action, $action->getGroup());
  46. }
  47. if (!is_null($cloud)) {
  48. $cloud->show();
  49. }
  50. }
  51. public function onPluginVersion(array &$versions)
  52. {
  53. $versions[] = array('name' => 'TagCloud',
  54. 'version' => GNUSOCIAL_VERSION,
  55. 'author' => 'Mikael Nordfeldth',
  56. 'homepage' => 'https://gnu.io/social',
  57. 'description' =>
  58. // TRANS: Plugin description.
  59. _m('Adds tag clouds to stream pages'));
  60. return true;
  61. }
  62. }