groupaction.php 9.5 KB

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