TagCloudPlugin.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. const PLUGIN_VERSION = '2.0.0';
  15. public function onRouterInitialized(URLMapper $m)
  16. {
  17. $m->connect('tags/', array('action' => 'publictagcloud'));
  18. $m->connect('tag/', array('action' => 'publictagcloud'));
  19. $m->connect('tags', array('action' => 'publictagcloud'));
  20. $m->connect('tag', array('action' => 'publictagcloud'));
  21. }
  22. public function onEndPublicGroupNav(Menu $menu)
  23. {
  24. // TRANS: Menu item in search group navigation panel.
  25. $menu->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'),
  26. // TRANS: Menu item title in search group navigation panel.
  27. _('Recent tags'), $menu->actionName === 'publictagcloud', 'nav_recent-tags');
  28. }
  29. public function onEndShowSections(Action $action)
  30. {
  31. $cloud = null;
  32. switch (true) {
  33. case $action instanceof AllAction:
  34. $cloud = new InboxTagCloudSection($action, $action->getTarget());
  35. break;
  36. case $action instanceof AttachmentAction:
  37. $cloud = new AttachmentTagCloudSection($action);
  38. break;
  39. case $action instanceof PublicAction:
  40. $cloud = new PublicTagCloudSection($action);
  41. break;
  42. case $action instanceof ShowstreamAction:
  43. $cloud = new PersonalTagCloudSection($action, $action->getTarget());
  44. break;
  45. case $action instanceof GroupAction:
  46. $cloud = new GroupTagCloudSection($action, $action->getGroup());
  47. }
  48. if (!is_null($cloud)) {
  49. $cloud->show();
  50. }
  51. }
  52. public function onPluginVersion(array &$versions)
  53. {
  54. $versions[] = array('name' => 'TagCloud',
  55. 'version' => self::PLUGIN_VERSION,
  56. 'author' => 'Mikael Nordfeldth',
  57. 'homepage' => 'https://gnu.io/social',
  58. 'description' =>
  59. // TRANS: Plugin description.
  60. _m('Adds tag clouds to stream pages'));
  61. return true;
  62. }
  63. }