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

groupunblock.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* ============================================================================
  3. * Title: GroupUnblock
  4. * UNblock a user from a group action class.
  5. *
  6. * postActiv:
  7. * the micro-blogging software
  8. *
  9. * Copyright:
  10. * Copyright (C) 2016-2018, Maiyannah Bishop
  11. *
  12. * Derived from code copyright various sources:
  13. * o GNU Social (C) 2013-2016, Free Software Foundation, Inc
  14. * o StatusNet (C) 2008-2012, StatusNet, Inc
  15. * ----------------------------------------------------------------------------
  16. * License:
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. *
  30. * <https://www.gnu.org/licenses/agpl.html>
  31. * ----------------------------------------------------------------------------
  32. * About:
  33. * UNblock a user from a group action class.
  34. *
  35. * PHP version:
  36. * Tested with PHP 7.0
  37. * ----------------------------------------------------------------------------
  38. * File Authors:
  39. * o Evan Prodromou
  40. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  41. * o Mikael Nordfeldth <mmn@hethane.se>
  42. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  43. *
  44. * Web:
  45. * o postActiv <http://www.postactiv.com>
  46. * o GNU social <https://www.gnu.org/s/social/>
  47. * ============================================================================
  48. */
  49. // This file is formatted so that it provides useful documentation output in
  50. // NaturalDocs. Please be considerate of this before changing formatting.
  51. if (!defined('POSTACTIV')) { exit(1); }
  52. /**
  53. * Unblock a user from a group
  54. */
  55. class GroupunblockAction extends Action
  56. {
  57. var $profile = null;
  58. var $group = null;
  59. /**
  60. * Take arguments for running
  61. *
  62. * @param array $args $_REQUEST args
  63. *
  64. * @return boolean success flag
  65. */
  66. function prepare(array $args = array())
  67. {
  68. parent::prepare($args);
  69. if (!common_logged_in()) {
  70. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  71. $this->clientError(_('Not logged in.'));
  72. }
  73. $token = $this->trimmed('token');
  74. if (empty($token) || $token != common_session_token()) {
  75. // TRANS: Client error displayed when the session token does not match or is not given.
  76. $this->clientError(_('There was a problem with your session token. Try again, please.'));
  77. }
  78. $id = $this->trimmed('unblockto');
  79. if (empty($id)) {
  80. // TRANS: Client error displayed when trying to unblock a user from a group without providing a profile.
  81. $this->clientError(_('No profile specified.'));
  82. }
  83. $this->profile = Profile::getKV('id', $id);
  84. if (empty($this->profile)) {
  85. // TRANS: Client error displayed when trying to unblock a user from a group without providing an existing profile.
  86. $this->clientError(_('No profile with that ID.'));
  87. }
  88. $group_id = $this->trimmed('unblockgroup');
  89. if (empty($group_id)) {
  90. // TRANS: Client error displayed when trying to unblock a user from a group without providing a group.
  91. $this->clientError(_('No group specified.'));
  92. }
  93. $this->group = User_group::getKV('id', $group_id);
  94. if (empty($this->group)) {
  95. // TRANS: Client error displayed when trying to unblock a user from a non-existing group.
  96. $this->clientError(_('No such group.'));
  97. }
  98. $user = common_current_user();
  99. if (!$user->isAdmin($this->group)) {
  100. // TRANS: Client error displayed when trying to unblock a user from a group without being an administrator for the group.
  101. $this->clientError(_('Only an admin can unblock group members.'), 401);
  102. }
  103. if (!Group_block::isBlocked($this->group, $this->profile)) {
  104. // TRANS: Client error displayed when trying to unblock a non-blocked user from a group.
  105. $this->clientError(_('User is not blocked from group.'));
  106. }
  107. return true;
  108. }
  109. /**
  110. * Handle request
  111. *
  112. * @param array $args $_REQUEST args; handled in prepare()
  113. *
  114. * @return void
  115. */
  116. function handle()
  117. {
  118. parent::handle();
  119. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  120. $this->unblockProfile();
  121. }
  122. }
  123. /**
  124. * Unblock a user.
  125. *
  126. * @return void
  127. */
  128. function unblockProfile()
  129. {
  130. $result = Group_block::unblockProfile($this->group, $this->profile);
  131. if (!$result) {
  132. // TRANS: Server error displayed when unblocking a user from a group fails because of an unknown error.
  133. $this->serverError(_('Error removing the block.'));
  134. }
  135. foreach ($this->args as $k => $v) {
  136. if ($k == 'returnto-action') {
  137. $action = $v;
  138. } else if (substr($k, 0, 9) == 'returnto-') {
  139. $args[substr($k, 9)] = $v;
  140. }
  141. }
  142. if ($action) {
  143. common_redirect(common_local_url($action, $args), 303);
  144. } else {
  145. common_redirect(common_local_url('blockedfromgroup', array('nickname' => $this->group->nickname)), 303);
  146. }
  147. }
  148. }
  149. // END OF FILE
  150. // ============================================================================
  151. ?>