The official, canonical postActiv repository. http://www.postactiv.com

blockedfromgroup.php 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. // !TODO: I WRITE HTML, REFACTOR FOR SMARTY
  3. /* ============================================================================
  4. * Title: BlockedFromGroup
  5. * List of profiles blocked from this group
  6. *
  7. * postActiv:
  8. * the micro-blogging software
  9. *
  10. * Copyright:
  11. * Copyright (C) 2016-2018, Maiyannah Bishop
  12. *
  13. * Derived from code copyright various sources:
  14. * o GNU Social (C) 2013-2016, Free Software Foundation, Inc
  15. * o StatusNet (C) 2008-2012, StatusNet, Inc
  16. * ----------------------------------------------------------------------------
  17. * License:
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. * <https://www.gnu.org/licenses/agpl.html>
  32. * ----------------------------------------------------------------------------
  33. * About:
  34. * List of profiles blocked from this group
  35. *
  36. * PHP version:
  37. * Tested with PHP 7.0
  38. * ----------------------------------------------------------------------------
  39. * File Authors:
  40. * o Evan Prodromou
  41. * o Zach Copley
  42. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  43. * o Mikael Nordfeldth <mmn@hethane.se>
  44. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  45. *
  46. * Web:
  47. * o postActiv <http://www.postactiv.com>
  48. * o GNU social <https://www.gnu.org/s/social/>
  49. * ============================================================================
  50. */
  51. // This file is formatted so that it provides useful documentation output in
  52. // NaturalDocs. Please be considerate of this before changing formatting.
  53. if (!defined('POSTACTIV')) { exit(1); }
  54. /**
  55. * List of profiles blocked from this group
  56. */
  57. class BlockedfromgroupAction extends GroupAction
  58. {
  59. var $page = null;
  60. function isReadOnly($args)
  61. {
  62. return true;
  63. }
  64. protected function prepare(array $args=array())
  65. {
  66. parent::prepare($args);
  67. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  68. $nickname_arg = $this->arg('nickname');
  69. $nickname = common_canonical_nickname($nickname_arg);
  70. // Permanent redirect on non-canonical nickname
  71. if ($nickname_arg != $nickname) {
  72. $args = array('nickname' => $nickname);
  73. if ($this->page != 1) {
  74. $args['page'] = $this->page;
  75. }
  76. common_redirect(common_local_url('blockedfromgroup', $args), 301);
  77. }
  78. if (!$nickname) {
  79. // TRANS: Client error displayed when requesting a list of blocked users for a group without providing a group nickname.
  80. $this->clientError(_('No nickname.'), 404);
  81. }
  82. $local = Local_group::getKV('nickname', $nickname);
  83. if (!$local) {
  84. // TRANS: Client error displayed when requesting a list of blocked users for a non-local group.
  85. $this->clientError(_('No such group.'), 404);
  86. }
  87. $this->group = User_group::getKV('id', $local->group_id);
  88. if (!$this->group) {
  89. // TRANS: Client error displayed when requesting a list of blocked users for a non-existing group.
  90. $this->clientError(_('No such group.'), 404);
  91. }
  92. return true;
  93. }
  94. function title()
  95. {
  96. if ($this->page == 1) {
  97. // TRANS: Title for first page with list of users blocked from a group.
  98. // TRANS: %s is a group nickname.
  99. return sprintf(_('%s blocked profiles'),
  100. $this->group->nickname);
  101. } else {
  102. // TRANS: Title for any but the first page with list of users blocked from a group.
  103. // TRANS: %1$s is a group nickname, %2$d is a page number.
  104. return sprintf(_('%1$s blocked profiles, page %2$d'),
  105. $this->group->nickname,
  106. $this->page);
  107. }
  108. }
  109. protected function handle()
  110. {
  111. parent::handle();
  112. $this->showPage();
  113. }
  114. function showPageNotice()
  115. {
  116. $this->element('p', 'instructions',
  117. // TRANS: Instructions for list of users blocked from a group.
  118. _('A list of the users blocked from joining this group.'));
  119. }
  120. function showContent()
  121. {
  122. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  123. $limit = PROFILES_PER_PAGE + 1;
  124. $cnt = 0;
  125. $blocked = $this->group->getBlocked($offset, $limit);
  126. if ($blocked) {
  127. $blocked_list = new GroupBlockList($blocked, $this->group, $this);
  128. $cnt = $blocked_list->show();
  129. }
  130. $blocked->free();
  131. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  132. $this->page, 'blockedfromgroup',
  133. array('nickname' => $this->group->nickname));
  134. }
  135. }
  136. class GroupBlockList extends ProfileList
  137. {
  138. var $group = null;
  139. function __construct($profile, $group, $action)
  140. {
  141. parent::__construct($profile, $action);
  142. $this->group = $group;
  143. }
  144. function newListItem(Profile $profile)
  145. {
  146. return new GroupBlockListItem($profile, $this->group, $this->action);
  147. }
  148. }
  149. class GroupBlockListItem extends ProfileListItem
  150. {
  151. var $group = null;
  152. function __construct($profile, $group, $action)
  153. {
  154. parent::__construct($profile, $action);
  155. $this->group = $group;
  156. }
  157. function showActions()
  158. {
  159. $this->startActions();
  160. $this->showGroupUnblockForm();
  161. $this->endActions();
  162. }
  163. function showGroupUnblockForm()
  164. {
  165. $user = common_current_user();
  166. if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
  167. $this->out->elementStart('li', 'entity_block');
  168. $bf = new GroupUnblockForm($this->out, $this->profile, $this->group,
  169. array('action' => 'blockedfromgroup',
  170. 'nickname' => $this->group->nickname));
  171. $bf->show();
  172. $this->out->elementEnd('li');
  173. }
  174. }
  175. }
  176. /**
  177. * Form for unblocking a user from a group
  178. *
  179. * @category Form
  180. * @package StatusNet
  181. * @author Evan Prodromou <evan@status.net>
  182. * @author Sarven Capadisli <csarven@status.net>
  183. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  184. * @link http://status.net/
  185. *
  186. * @see UnblockForm
  187. */
  188. class GroupUnblockForm extends Form
  189. {
  190. /**
  191. * Profile of user to block
  192. */
  193. var $profile = null;
  194. /**
  195. * Group to block the user from
  196. */
  197. var $group = null;
  198. /**
  199. * Return-to args
  200. */
  201. var $args = null;
  202. /**
  203. * Constructor
  204. *
  205. * @param HTMLOutputter $out output channel
  206. * @param Profile $profile profile of user to block
  207. * @param User_group $group group to block user from
  208. * @param array $args return-to args
  209. */
  210. function __construct($out=null, $profile=null, $group=null, $args=null)
  211. {
  212. parent::__construct($out);
  213. $this->profile = $profile;
  214. $this->group = $group;
  215. $this->args = $args;
  216. }
  217. /**
  218. * ID of the form
  219. *
  220. * @return int ID of the form
  221. */
  222. function id()
  223. {
  224. // This should be unique for the page.
  225. return 'unblock-' . $this->profile->id;
  226. }
  227. /**
  228. * class of the form
  229. *
  230. * @return string class of the form
  231. */
  232. function formClass()
  233. {
  234. return 'form_group_unblock';
  235. }
  236. /**
  237. * Action of the form
  238. *
  239. * @return string URL of the action
  240. */
  241. function action()
  242. {
  243. return common_local_url('groupunblock');
  244. }
  245. /**
  246. * Legend of the Form
  247. *
  248. * @return void
  249. */
  250. function formLegend()
  251. {
  252. // TRANS: Form legend for unblocking a user from a group.
  253. $this->out->element('legend', null, _('Unblock user from group'));
  254. }
  255. /**
  256. * Data elements of the form
  257. *
  258. * @return void
  259. */
  260. function formData()
  261. {
  262. $this->out->hidden('unblockto-' . $this->profile->id,
  263. $this->profile->id,
  264. 'unblockto');
  265. $this->out->hidden('unblockgroup-' . $this->group->id,
  266. $this->group->id,
  267. 'unblockgroup');
  268. if ($this->args) {
  269. foreach ($this->args as $k => $v) {
  270. $this->out->hidden('returnto-' . $k, $v);
  271. }
  272. }
  273. }
  274. /**
  275. * Action elements
  276. *
  277. * @return void
  278. */
  279. function formActions()
  280. {
  281. $this->out->submit('submit',
  282. // TRANS: Button text for unblocking a user from a group.
  283. _m('BUTTON','Unblock'),
  284. 'submit',
  285. null,
  286. // TRANS: Tooltip for button for unblocking a user from a group.
  287. _('Unblock this user'));
  288. }
  289. }
  290. // END OF FILE
  291. // ============================================================================
  292. ?>