subgroupnav.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Local navigation for subscriptions group of pages
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Subs
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2011 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR.'/lib/widget.php';
  33. /**
  34. * Local nav menu for subscriptions, subscribers
  35. *
  36. * @category Subs
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. */
  42. class SubGroupNav extends Menu
  43. {
  44. var $user = null;
  45. /**
  46. * Construction
  47. *
  48. * @param Action $action current action, used for output
  49. * @param User $user Current user or NULL if "guest"
  50. */
  51. function __construct(Action $action=null, User $user=null)
  52. {
  53. parent::__construct($action);
  54. $this->user = $user;
  55. }
  56. /**
  57. * Show the menu
  58. *
  59. * @return void
  60. */
  61. function show()
  62. {
  63. $cur = common_current_user();
  64. $action = $this->action->trimmed('action');
  65. $this->out->elementStart('ul', array('class' => 'nav'));
  66. if (Event::handle('StartSubGroupNav', array($this))) {
  67. $this->out->menuItem(common_local_url('showstream', array('nickname' =>
  68. $this->user->nickname)),
  69. // TRANS: Menu item in local navigation menu.
  70. _m('MENU','Profile'),
  71. (empty($profile)) ? $this->user->nickname : $profile->getBestName(),
  72. $action == 'showstream',
  73. 'nav_profile');
  74. $this->out->menuItem(common_local_url('subscriptions',
  75. array('nickname' =>
  76. $this->user->nickname)),
  77. // TRANS: Menu item in local navigation menu.
  78. _m('MENU','Subscriptions'),
  79. // TRANS: Menu item title in local navigation menu.
  80. // TRANS: %s is a user nickname.
  81. sprintf(_('People %s subscribes to.'),
  82. $this->user->nickname),
  83. $action == 'subscriptions',
  84. 'nav_subscriptions');
  85. $this->out->menuItem(common_local_url('subscribers',
  86. array('nickname' =>
  87. $this->user->nickname)),
  88. // TRANS: Menu item in local navigation menu.
  89. _m('MENU','Subscribers'),
  90. // TRANS: Menu item title in local navigation menu.
  91. // TRANS: %s is a user nickname.
  92. sprintf(_('People subscribed to %s.'),
  93. $this->user->nickname),
  94. $action == 'subscribers',
  95. 'nav_subscribers');
  96. if ($cur && $cur->id == $this->user->id) {
  97. // Possibly site admins should be able to get in here too
  98. $pending = $this->countPendingSubs();
  99. if ($pending || $cur->subscribe_policy == User::SUBSCRIBE_POLICY_MODERATE) {
  100. $this->out->menuItem(common_local_url('subqueue',
  101. array('nickname' =>
  102. $this->user->nickname)),
  103. // TRANS: Menu item in local navigation menu.
  104. // TRANS: %d is the number of pending subscription requests.
  105. sprintf(_m('MENU','Pending (%d)'), $pending),
  106. // TRANS: Menu item title in local navigation menu.
  107. sprintf(_('Approve pending subscription requests.'),
  108. $this->user->nickname),
  109. $action == 'subqueueaction',
  110. 'nav_subscribers');
  111. }
  112. }
  113. $this->out->menuItem(common_local_url('usergroups',
  114. array('nickname' =>
  115. $this->user->nickname)),
  116. // TRANS: Menu item in local navigation menu.
  117. _m('MENU','Groups'),
  118. // TRANS: Menu item title in local navigation menu.
  119. // TRANS: %s is a user nickname.
  120. sprintf(_('Groups %s is a member of.'),
  121. $this->user->nickname),
  122. $action == 'usergroups',
  123. 'nav_usergroups');
  124. $this->out->menuItem(common_local_url('peopletagsubscriptions',
  125. array('nickname' =>
  126. $this->user->nickname)),
  127. // TRANS: Menu item title in local navigation menu.
  128. _m('MENU','Lists'),
  129. // TRANS: Menu item title in local navigation menu.
  130. // TRANS: %s is a user nickname.
  131. sprintf(_('List subscriptions by %s.'),
  132. $this->user->nickname),
  133. in_array($action, array('peopletagsbyuser', 'peopletagsubscriptions', 'peopletagsforuser')),
  134. 'nav_timeline_peopletags');
  135. if (common_config('invite', 'enabled') && !is_null($cur) && $this->user->id === $cur->id) {
  136. $this->out->menuItem(common_local_url('invite'),
  137. // TRANS: Menu item in local navigation menu.
  138. _m('MENU','Invite'),
  139. // TRANS: Menu item title in local navigation menu.
  140. // TRANS: %s is the StatusNet sitename.
  141. sprintf(_('Invite friends and colleagues to join you on %s.'),
  142. common_config('site', 'name')),
  143. $action == 'invite',
  144. 'nav_invite');
  145. }
  146. Event::handle('EndSubGroupNav', array($this));
  147. }
  148. $this->out->elementEnd('ul');
  149. }
  150. function countPendingSubs()
  151. {
  152. $req = new Subscription_queue();
  153. $req->subscribed = $this->user->id;
  154. return $req->count();
  155. }
  156. }