groupaction.php 9.4 KB

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