subgroupnav.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/ui/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. public $widgetOpts;
  45. public $scoped;
  46. var $user = null;
  47. /**
  48. * Construction
  49. *
  50. * @param Action $action current action, used for output
  51. * @param User $user Current user or NULL if "guest"
  52. */
  53. function __construct(Action $action=null, User $user=null)
  54. {
  55. parent::__construct($action);
  56. $this->user = $user;
  57. }
  58. /**
  59. * Show the menu
  60. *
  61. * @return void
  62. */
  63. function show()
  64. {
  65. $cur = common_current_user();
  66. $action = $this->action->trimmed('action');
  67. $this->out->elementStart('ul', array('class' => 'nav'));
  68. if (Event::handle('StartSubGroupNav', array($this))) {
  69. $this->out->menuItem(common_local_url('showstream', array('nickname' =>
  70. $this->user->nickname)),
  71. // TRANS: Menu item in local navigation menu.
  72. _m('MENU','Profile'),
  73. (empty($profile)) ? $this->user->nickname : $profile->getBestName(),
  74. $action == 'showstream',
  75. 'nav_profile');
  76. $this->out->menuItem(common_local_url('subscriptions',
  77. array('nickname' =>
  78. $this->user->nickname)),
  79. // TRANS: Menu item in local navigation menu.
  80. _m('MENU','Subscriptions'),
  81. // TRANS: Menu item title in local navigation menu.
  82. // TRANS: %s is a user nickname.
  83. sprintf(_('People %s subscribes to.'),
  84. $this->user->nickname),
  85. $action == 'subscriptions',
  86. 'nav_subscriptions');
  87. $this->out->menuItem(common_local_url('subscribers',
  88. array('nickname' =>
  89. $this->user->nickname)),
  90. // TRANS: Menu item in local navigation menu.
  91. _m('MENU','Subscribers'),
  92. // TRANS: Menu item title in local navigation menu.
  93. // TRANS: %s is a user nickname.
  94. sprintf(_('People subscribed to %s.'),
  95. $this->user->nickname),
  96. $action == 'subscribers',
  97. 'nav_subscribers');
  98. if ($cur && $cur->id == $this->user->id) {
  99. // Possibly site admins should be able to get in here too
  100. $pending = $this->countPendingSubs();
  101. if ($pending || $cur->subscribe_policy == User::SUBSCRIBE_POLICY_MODERATE) {
  102. $this->out->menuItem(common_local_url('subqueue',
  103. array('nickname' =>
  104. $this->user->nickname)),
  105. // TRANS: Menu item in local navigation menu.
  106. // TRANS: %d is the number of pending subscription requests.
  107. sprintf(_m('MENU','Pending (%d)'), $pending),
  108. // TRANS: Menu item title in local navigation menu.
  109. sprintf(_('Approve pending subscription requests.'),
  110. $this->user->nickname),
  111. $action == 'subqueueaction',
  112. 'nav_subscribers');
  113. }
  114. }
  115. $this->out->menuItem(common_local_url('usergroups',
  116. array('nickname' =>
  117. $this->user->nickname)),
  118. // TRANS: Menu item in local navigation menu.
  119. _m('MENU','Groups'),
  120. // TRANS: Menu item title in local navigation menu.
  121. // TRANS: %s is a user nickname.
  122. sprintf(_('Groups %s is a member of.'),
  123. $this->user->nickname),
  124. $action == 'usergroups',
  125. 'nav_usergroups');
  126. $this->out->menuItem(common_local_url('peopletagsubscriptions',
  127. array('nickname' =>
  128. $this->user->nickname)),
  129. // TRANS: Menu item title in local navigation menu.
  130. _m('MENU','Lists'),
  131. // TRANS: Menu item title in local navigation menu.
  132. // TRANS: %s is a user nickname.
  133. sprintf(_('List subscriptions by %s.'),
  134. $this->user->nickname),
  135. in_array($action, array('peopletagsbyuser', 'peopletagsubscriptions', 'peopletagsforuser')),
  136. 'nav_timeline_peopletags');
  137. if (common_config('invite', 'enabled') && !is_null($cur) && $this->user->id === $cur->id) {
  138. $this->out->menuItem(common_local_url('invite'),
  139. // TRANS: Menu item in local navigation menu.
  140. _m('MENU','Invite'),
  141. // TRANS: Menu item title in local navigation menu.
  142. // TRANS: %s is the StatusNet sitename.
  143. sprintf(_('Invite friends and colleagues to join you on %s.'),
  144. common_config('site', 'name')),
  145. $action == 'invite',
  146. 'nav_invite');
  147. }
  148. Event::handle('EndSubGroupNav', array($this));
  149. }
  150. $this->out->elementEnd('ul');
  151. }
  152. function countPendingSubs()
  153. {
  154. $req = new Subscription_queue();
  155. $req->subscribed = $this->user->id;
  156. return $req->count();
  157. }
  158. }