groupaction.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. define('MEMBERS_PER_SECTION', 27);
  33. /**
  34. * Base class for group actions, similar to ProfileAction
  35. *
  36. * @category Action
  37. * @package StatusNet
  38. * @author Zach Copley <zach@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 GroupAction extends Action
  43. {
  44. protected $group;
  45. protected function prepare(array $args=array())
  46. {
  47. parent::prepare($args);
  48. $nickname_arg = $this->arg('nickname');
  49. $nickname = common_canonical_nickname($nickname_arg);
  50. // Permanent redirect on non-canonical nickname
  51. if ($nickname_arg != $nickname) {
  52. $args = array('nickname' => $nickname);
  53. if ($this->page != 1) {
  54. $args['page'] = $this->page;
  55. }
  56. common_redirect(common_local_url('showgroup', $args), 301);
  57. }
  58. if (!$nickname) {
  59. // TRANS: Client error displayed if no nickname argument was given requesting a group page.
  60. $this->clientError(_('No nickname.'), 404);
  61. }
  62. $local = Local_group::getKV('nickname', $nickname);
  63. if (!$local) {
  64. $alias = Group_alias::getKV('alias', $nickname);
  65. if ($alias) {
  66. $args = array('id' => $alias->group_id);
  67. if ($this->page != 1) {
  68. $args['page'] = $this->page;
  69. }
  70. common_redirect(common_local_url('groupbyid', $args), 301);
  71. } else {
  72. common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
  73. // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
  74. $this->clientError(_('No such group.'), 404);
  75. }
  76. }
  77. $this->group = User_group::getKV('id', $local->group_id);
  78. if (!$this->group) {
  79. // TRANS: Client error displayed if no local group with a given name was found requesting group page.
  80. $this->clientError(_('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. $cur = common_current_user();
  97. if ($cur && $cur->isAdmin($this->group)) {
  98. $this->showPending();
  99. $this->showBlocked();
  100. }
  101. $this->showAdmins();
  102. if (!common_config('performance', 'high')) {
  103. $cloud = new GroupTagCloudSection($this, $this->group);
  104. $cloud->show();
  105. }
  106. }
  107. /**
  108. * Show mini-list of members
  109. *
  110. * @return void
  111. */
  112. function showMembers()
  113. {
  114. $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
  115. if (!$member) {
  116. return;
  117. }
  118. $this->elementStart('div', array('id' => 'entity_members',
  119. 'class' => 'section'));
  120. if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
  121. $this->elementStart('h2');
  122. $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
  123. $this->group->nickname))),
  124. // TRANS: Header for mini list of group members on a group page (h2).
  125. _('Members'));
  126. $this->text(' ');
  127. $this->text($this->group->getMemberCount());
  128. $this->elementEnd('h2');
  129. $gmml = new GroupMembersMiniList($member, $this);
  130. $cnt = $gmml->show();
  131. if ($cnt == 0) {
  132. // TRANS: Description for mini list of group members on a group page when the group has no members.
  133. $this->element('p', null, _('(None)'));
  134. }
  135. // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
  136. // for example http://identi.ca/group/statusnet. Broken?
  137. if ($cnt > MEMBERS_PER_SECTION) {
  138. $this->element('a', array('href' => common_local_url('groupmembers',
  139. array('nickname' => $this->group->nickname))),
  140. // TRANS: Link to all group members from mini list of group members if group has more than n members.
  141. _('All members'));
  142. }
  143. Event::handle('EndShowGroupMembersMiniList', array($this));
  144. }
  145. $this->elementEnd('div');
  146. }
  147. function showPending()
  148. {
  149. if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
  150. return;
  151. }
  152. $pending = $this->group->getQueueCount();
  153. if (!$pending) {
  154. return;
  155. }
  156. $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
  157. if (!$request) {
  158. return;
  159. }
  160. $this->elementStart('div', array('id' => 'entity_pending',
  161. 'class' => 'section'));
  162. if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
  163. $this->elementStart('h2');
  164. $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
  165. $this->group->nickname))),
  166. // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
  167. _('Pending'));
  168. $this->text(' ');
  169. $this->text($pending);
  170. $this->elementEnd('h2');
  171. $gmml = new ProfileMiniList($request, $this);
  172. $gmml->show();
  173. Event::handle('EndShowGroupPendingMiniList', array($this));
  174. }
  175. $this->elementEnd('div');
  176. }
  177. function showBlocked()
  178. {
  179. $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
  180. $this->elementStart('div', array('id' => 'entity_blocked',
  181. 'class' => 'section'));
  182. if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
  183. $this->elementStart('h2');
  184. $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
  185. $this->group->nickname))),
  186. // TRANS: Header for mini list of users that are blocked in a group page (h2).
  187. _('Blocked'));
  188. $this->text(' ');
  189. $this->text($this->group->getBlockedCount());
  190. $this->elementEnd('h2');
  191. $gmml = new GroupBlockedMiniList($blocked, $this);
  192. $cnt = $gmml->show();
  193. if ($cnt == 0) {
  194. // TRANS: Description for mini list of group members on a group page when the group has no members.
  195. $this->element('p', null, _('(None)'));
  196. }
  197. // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
  198. // for example http://identi.ca/group/statusnet. Broken?
  199. if ($cnt > MEMBERS_PER_SECTION) {
  200. $this->element('a', array('href' => common_local_url('blockedfromgroup',
  201. array('nickname' => $this->group->nickname))),
  202. // TRANS: Link to all group members from mini list of group members if group has more than n members.
  203. _('All members'));
  204. }
  205. Event::handle('EndShowGroupBlockedMiniList', array($this));
  206. }
  207. $this->elementEnd('div');
  208. }
  209. /**
  210. * Show list of admins
  211. *
  212. * @return void
  213. */
  214. function showAdmins()
  215. {
  216. $adminSection = new GroupAdminSection($this, $this->group);
  217. $adminSection->show();
  218. }
  219. function noticeFormOptions()
  220. {
  221. $options = parent::noticeFormOptions();
  222. $cur = common_current_user();
  223. if (!empty($cur) && $cur->isMember($this->group)) {
  224. $options['to_group'] = $this->group;
  225. }
  226. return $options;
  227. }
  228. function getGroup()
  229. {
  230. return $this->group;
  231. }
  232. }
  233. class GroupAdminSection extends ProfileSection
  234. {
  235. var $group;
  236. function __construct($out, $group)
  237. {
  238. parent::__construct($out);
  239. $this->group = $group;
  240. }
  241. function getProfiles()
  242. {
  243. return $this->group->getAdmins();
  244. }
  245. function title()
  246. {
  247. // TRANS: Title for list of group administrators on a group page.
  248. return _m('TITLE','Admins');
  249. }
  250. function divId()
  251. {
  252. return 'group_admins';
  253. }
  254. function moreUrl()
  255. {
  256. return null;
  257. }
  258. }
  259. class GroupMembersMiniList extends ProfileMiniList
  260. {
  261. function newListItem($profile)
  262. {
  263. return new GroupMembersMiniListItem($profile, $this->action);
  264. }
  265. }
  266. class GroupMembersMiniListItem extends ProfileMiniListItem
  267. {
  268. function linkAttributes()
  269. {
  270. $aAttrs = parent::linkAttributes();
  271. if (common_config('nofollow', 'members')) {
  272. $aAttrs['rel'] .= ' nofollow';
  273. }
  274. return $aAttrs;
  275. }
  276. }
  277. class GroupBlockedMiniList extends ProfileMiniList
  278. {
  279. function newListItem($profile)
  280. {
  281. return new GroupBlockedMiniListItem($profile, $this->action);
  282. }
  283. }
  284. class GroupBlockedMiniListItem extends ProfileMiniListItem
  285. {
  286. function linkAttributes()
  287. {
  288. $aAttrs = parent::linkAttributes();
  289. if (common_config('nofollow', 'members')) {
  290. $aAttrs['rel'] .= ' nofollow';
  291. }
  292. return $aAttrs;
  293. }
  294. }
  295. class ThreadingGroupNoticeStream extends ThreadingNoticeStream
  296. {
  297. function __construct($group, $profile)
  298. {
  299. parent::__construct(new GroupNoticeStream($group, $profile));
  300. }
  301. }