groupaction.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Base class for group actions
  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 Action
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2009-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('GNUSOCIAL')) { exit(1); }
  30. define('MEMBERS_PER_SECTION', 27);
  31. /**
  32. * Base class for group actions, similar to ProfileAction
  33. *
  34. * @category Action
  35. * @package StatusNet
  36. * @author Zach Copley <zach@status.net>
  37. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  38. * @link http://status.net/
  39. */
  40. class GroupAction extends ShowstreamAction
  41. {
  42. public $widgetOpts;
  43. public $scoped;
  44. protected $group;
  45. protected function doPreparation()
  46. {
  47. $nickname_arg = $this->arg('nickname');
  48. $nickname = common_canonical_nickname($nickname_arg);
  49. // Permanent redirect on non-canonical nickname
  50. if ($nickname_arg !== $nickname) {
  51. $args = array('nickname' => $nickname);
  52. if ($this->page != 1) {
  53. $args['page'] = $this->page;
  54. }
  55. common_redirect(common_local_url($this->getActionName(), $args), 301);
  56. }
  57. if (!$nickname) {
  58. // TRANS: Client error displayed if no nickname argument was given requesting a group page.
  59. $this->clientError(_('No nickname.'), 404);
  60. }
  61. $local = Local_group::getKV('nickname', $nickname);
  62. if (!$local) {
  63. $alias = Group_alias::getKV('alias', $nickname);
  64. if ($alias) {
  65. $args = array('id' => $alias->group_id);
  66. if ($this->page != 1) {
  67. $args['page'] = $this->page;
  68. }
  69. common_redirect(common_local_url('groupbyid', $args), 301);
  70. } else {
  71. common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
  72. // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
  73. throw new ClientException(_('No such group.'), 404);
  74. }
  75. }
  76. $this->group = User_group::getKV('id', $local->group_id);
  77. $this->target = $this->group->getProfile();
  78. if (!$this->group instanceof User_group) {
  79. // TRANS: Client error displayed if no local group with a given name was found requesting group page.
  80. throw new ClientException(_('No such group.'), 404);
  81. }
  82. }
  83. function showProfileBlock()
  84. {
  85. $block = new GroupProfileBlock($this, $this->group);
  86. $block->show();
  87. }
  88. /**
  89. * Fill in the sidebar.
  90. *
  91. * @return void
  92. */
  93. function showSections()
  94. {
  95. $this->showMembers();
  96. if ($this->scoped instanceof Profile && $this->scoped->isAdmin($this->group)) {
  97. $this->showPending();
  98. $this->showBlocked();
  99. }
  100. $this->showAdmins();
  101. }
  102. /**
  103. * Show mini-list of members
  104. *
  105. * @return void
  106. */
  107. function showMembers()
  108. {
  109. $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
  110. if (!$member) {
  111. return;
  112. }
  113. $this->elementStart('div', array('id' => 'entity_members',
  114. 'class' => 'section'));
  115. if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
  116. $this->elementStart('h2');
  117. $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
  118. $this->group->nickname))),
  119. // TRANS: Header for mini list of group members on a group page (h2).
  120. _('Members'));
  121. $this->text(' ');
  122. $this->text($this->group->getMemberCount());
  123. $this->elementEnd('h2');
  124. $gmml = new GroupMembersMiniList($member, $this);
  125. $cnt = $gmml->show();
  126. if ($cnt == 0) {
  127. // TRANS: Description for mini list of group members on a group page when the group has no members.
  128. $this->element('p', null, _('(None)'));
  129. }
  130. // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
  131. // for example http://identi.ca/group/statusnet. Broken?
  132. if ($cnt > MEMBERS_PER_SECTION) {
  133. $this->element('a', array('href' => common_local_url('groupmembers',
  134. array('nickname' => $this->group->nickname))),
  135. // TRANS: Link to all group members from mini list of group members if group has more than n members.
  136. _('All members'));
  137. }
  138. Event::handle('EndShowGroupMembersMiniList', array($this));
  139. }
  140. $this->elementEnd('div');
  141. }
  142. function showPending()
  143. {
  144. if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
  145. return;
  146. }
  147. $pending = $this->group->getQueueCount();
  148. if (!$pending) {
  149. return;
  150. }
  151. $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
  152. if (!$request) {
  153. return;
  154. }
  155. $this->elementStart('div', array('id' => 'entity_pending',
  156. 'class' => 'section'));
  157. if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
  158. $this->elementStart('h2');
  159. $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
  160. $this->group->nickname))),
  161. // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
  162. _('Pending'));
  163. $this->text(' ');
  164. $this->text($pending);
  165. $this->elementEnd('h2');
  166. $gmml = new ProfileMiniList($request, $this);
  167. $gmml->show();
  168. Event::handle('EndShowGroupPendingMiniList', array($this));
  169. }
  170. $this->elementEnd('div');
  171. }
  172. function showBlocked()
  173. {
  174. $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
  175. $this->elementStart('div', array('id' => 'entity_blocked',
  176. 'class' => 'section'));
  177. if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
  178. $this->elementStart('h2');
  179. $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
  180. $this->group->nickname))),
  181. // TRANS: Header for mini list of users that are blocked in a group page (h2).
  182. _('Blocked'));
  183. $this->text(' ');
  184. $this->text($this->group->getBlockedCount());
  185. $this->elementEnd('h2');
  186. $gmml = new GroupBlockedMiniList($blocked, $this);
  187. $cnt = $gmml->show();
  188. if ($cnt == 0) {
  189. // TRANS: Description for mini list of group members on a group page when the group has no members.
  190. $this->element('p', null, _('(None)'));
  191. }
  192. // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
  193. // for example http://identi.ca/group/statusnet. Broken?
  194. if ($cnt > MEMBERS_PER_SECTION) {
  195. $this->element('a', array('href' => common_local_url('blockedfromgroup',
  196. array('nickname' => $this->group->nickname))),
  197. // TRANS: Link to all group members from mini list of group members if group has more than n members.
  198. _('All members'));
  199. }
  200. Event::handle('EndShowGroupBlockedMiniList', array($this));
  201. }
  202. $this->elementEnd('div');
  203. }
  204. /**
  205. * Show list of admins
  206. *
  207. * @return void
  208. */
  209. function showAdmins()
  210. {
  211. $adminSection = new GroupAdminSection($this, $this->group);
  212. $adminSection->show();
  213. }
  214. function noticeFormOptions()
  215. {
  216. $options = parent::noticeFormOptions();
  217. $cur = common_current_user();
  218. if (!empty($cur) && $cur->isMember($this->group)) {
  219. $options['to_group'] = $this->group;
  220. }
  221. return $options;
  222. }
  223. function getGroup()
  224. {
  225. return $this->group;
  226. }
  227. }