groupsnav.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Menu for streams
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Cache
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Menu for streams you follow
  37. *
  38. * @category General
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class GroupsNav extends MoreMenu
  46. {
  47. protected $user;
  48. protected $groups;
  49. function __construct($action, $user)
  50. {
  51. parent::__construct($action);
  52. $this->user = $user;
  53. $this->groups = $user->getGroups();
  54. }
  55. function haveGroups()
  56. {
  57. return ($this->groups instanceof User_group && $this->groups->N > 0);
  58. }
  59. function tag()
  60. {
  61. return 'groups';
  62. }
  63. function getItems()
  64. {
  65. $items = array();
  66. while ($this->groups instanceof User_group && $this->groups->fetch()) {
  67. $items[] = array('placeholder',
  68. array('nickname' => $this->groups->getNickname(),
  69. 'mainpage' => $this->groups->homeUrl()),
  70. $this->groups->getNickname(),
  71. $this->groups->getBestName()
  72. );
  73. }
  74. return $items;
  75. }
  76. function seeAllItem() {
  77. return array('usergroups',
  78. array('nickname' => $this->user->nickname),
  79. // TRANS: Link description for seeing all groups.
  80. _('See all'),
  81. // TRANS: Link title for seeing all groups.
  82. _('See all groups you belong to.'));
  83. }
  84. function item($actionName, array $args, $label, $description, $id=null, $cls=null)
  85. {
  86. if ($actionName != 'placeholder') {
  87. return parent::item($actionName, $args, $label, $description, $id, $cls);
  88. }
  89. if (empty($id)) {
  90. $id = $this->menuItemID('showgroup', array('nickname' => $args['nickname']));
  91. }
  92. $url = $args['mainpage'];
  93. $this->out->menuItem($url,
  94. $label,
  95. $description,
  96. $this->isCurrent($actionName, $args),
  97. $id,
  98. $cls);
  99. }
  100. }