blockedfromgroup.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of group members
  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 Group
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2009 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. /**
  33. * List of profiles blocked from this group
  34. *
  35. * @category Group
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class BlockedfromgroupAction extends GroupAction
  42. {
  43. var $page = null;
  44. function isReadOnly($args)
  45. {
  46. return true;
  47. }
  48. protected function prepare(array $args=array())
  49. {
  50. parent::prepare($args);
  51. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  52. $nickname_arg = $this->arg('nickname');
  53. $nickname = common_canonical_nickname($nickname_arg);
  54. // Permanent redirect on non-canonical nickname
  55. if ($nickname_arg != $nickname) {
  56. $args = array('nickname' => $nickname);
  57. if ($this->page != 1) {
  58. $args['page'] = $this->page;
  59. }
  60. common_redirect(common_local_url('blockedfromgroup', $args), 301);
  61. }
  62. if (!$nickname) {
  63. // TRANS: Client error displayed when requesting a list of blocked users for a group without providing a group nickname.
  64. $this->clientError(_('No nickname.'), 404);
  65. }
  66. $local = Local_group::getKV('nickname', $nickname);
  67. if (!$local) {
  68. // TRANS: Client error displayed when requesting a list of blocked users for a non-local group.
  69. $this->clientError(_('No such group.'), 404);
  70. }
  71. $this->group = User_group::getKV('id', $local->group_id);
  72. if (!$this->group) {
  73. // TRANS: Client error displayed when requesting a list of blocked users for a non-existing group.
  74. $this->clientError(_('No such group.'), 404);
  75. }
  76. return true;
  77. }
  78. function title()
  79. {
  80. if ($this->page == 1) {
  81. // TRANS: Title for first page with list of users blocked from a group.
  82. // TRANS: %s is a group nickname.
  83. return sprintf(_('%s blocked profiles'),
  84. $this->group->nickname);
  85. } else {
  86. // TRANS: Title for any but the first page with list of users blocked from a group.
  87. // TRANS: %1$s is a group nickname, %2$d is a page number.
  88. return sprintf(_('%1$s blocked profiles, page %2$d'),
  89. $this->group->nickname,
  90. $this->page);
  91. }
  92. }
  93. protected function handle()
  94. {
  95. parent::handle();
  96. $this->showPage();
  97. }
  98. function showPageNotice()
  99. {
  100. $this->element('p', 'instructions',
  101. // TRANS: Instructions for list of users blocked from a group.
  102. _('A list of the users blocked from joining this group.'));
  103. }
  104. function showContent()
  105. {
  106. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  107. $limit = PROFILES_PER_PAGE + 1;
  108. $cnt = 0;
  109. $blocked = $this->group->getBlocked($offset, $limit);
  110. if ($blocked) {
  111. $blocked_list = new GroupBlockList($blocked, $this->group, $this);
  112. $cnt = $blocked_list->show();
  113. }
  114. $blocked->free();
  115. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  116. $this->page, 'blockedfromgroup',
  117. array('nickname' => $this->group->nickname));
  118. }
  119. }
  120. class GroupBlockList extends ProfileList
  121. {
  122. var $group = null;
  123. function __construct($profile, $group, $action)
  124. {
  125. parent::__construct($profile, $action);
  126. $this->group = $group;
  127. }
  128. function newListItem(Profile $profile)
  129. {
  130. return new GroupBlockListItem($profile, $this->group, $this->action);
  131. }
  132. }
  133. class GroupBlockListItem extends ProfileListItem
  134. {
  135. var $group = null;
  136. function __construct($profile, $group, $action)
  137. {
  138. parent::__construct($profile, $action);
  139. $this->group = $group;
  140. }
  141. function showActions()
  142. {
  143. $this->startActions();
  144. $this->showGroupUnblockForm();
  145. $this->endActions();
  146. }
  147. function showGroupUnblockForm()
  148. {
  149. $user = common_current_user();
  150. if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
  151. $this->out->elementStart('li', 'entity_block');
  152. $bf = new GroupUnblockForm($this->out, $this->profile, $this->group,
  153. array('action' => 'blockedfromgroup',
  154. 'nickname' => $this->group->nickname));
  155. $bf->show();
  156. $this->out->elementEnd('li');
  157. }
  158. }
  159. }
  160. /**
  161. * Form for unblocking a user from a group
  162. *
  163. * @category Form
  164. * @package StatusNet
  165. * @author Evan Prodromou <evan@status.net>
  166. * @author Sarven Capadisli <csarven@status.net>
  167. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  168. * @link http://status.net/
  169. *
  170. * @see UnblockForm
  171. */
  172. class GroupUnblockForm extends Form
  173. {
  174. /**
  175. * Profile of user to block
  176. */
  177. var $profile = null;
  178. /**
  179. * Group to block the user from
  180. */
  181. var $group = null;
  182. /**
  183. * Return-to args
  184. */
  185. var $args = null;
  186. /**
  187. * Constructor
  188. *
  189. * @param HTMLOutputter $out output channel
  190. * @param Profile $profile profile of user to block
  191. * @param User_group $group group to block user from
  192. * @param array $args return-to args
  193. */
  194. function __construct($out=null, $profile=null, $group=null, $args=null)
  195. {
  196. parent::__construct($out);
  197. $this->profile = $profile;
  198. $this->group = $group;
  199. $this->args = $args;
  200. }
  201. /**
  202. * ID of the form
  203. *
  204. * @return int ID of the form
  205. */
  206. function id()
  207. {
  208. // This should be unique for the page.
  209. return 'unblock-' . $this->profile->id;
  210. }
  211. /**
  212. * class of the form
  213. *
  214. * @return string class of the form
  215. */
  216. function formClass()
  217. {
  218. return 'form_group_unblock';
  219. }
  220. /**
  221. * Action of the form
  222. *
  223. * @return string URL of the action
  224. */
  225. function action()
  226. {
  227. return common_local_url('groupunblock');
  228. }
  229. /**
  230. * Legend of the Form
  231. *
  232. * @return void
  233. */
  234. function formLegend()
  235. {
  236. // TRANS: Form legend for unblocking a user from a group.
  237. $this->out->element('legend', null, _('Unblock user from group'));
  238. }
  239. /**
  240. * Data elements of the form
  241. *
  242. * @return void
  243. */
  244. function formData()
  245. {
  246. $this->out->hidden('unblockto-' . $this->profile->id,
  247. $this->profile->id,
  248. 'unblockto');
  249. $this->out->hidden('unblockgroup-' . $this->group->id,
  250. $this->group->id,
  251. 'unblockgroup');
  252. if ($this->args) {
  253. foreach ($this->args as $k => $v) {
  254. $this->out->hidden('returnto-' . $k, $v);
  255. }
  256. }
  257. }
  258. /**
  259. * Action elements
  260. *
  261. * @return void
  262. */
  263. function formActions()
  264. {
  265. $this->out->submit('submit',
  266. // TRANS: Button text for unblocking a user from a group.
  267. _m('BUTTON','Unblock'),
  268. 'submit',
  269. null,
  270. // TRANS: Tooltip for button for unblocking a user from a group.
  271. _('Unblock this user'));
  272. }
  273. }