PageRenderTime 60ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/actions/groupmembers.php

https://github.com/Br3nda/laconica
PHP | 472 lines | 237 code | 80 blank | 155 comment | 22 complexity | 08f32f8ebb98227d17fc4530a6c64f2f MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. /**
  3. * Laconica, 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 Laconica
  24. * @author Evan Prodromou <evan@controlyourself.ca>
  25. * @copyright 2008-2009 Control Yourself, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://laconi.ca/
  28. */
  29. if (!defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once(INSTALLDIR.'/lib/profilelist.php');
  33. require_once INSTALLDIR.'/lib/publicgroupnav.php';
  34. /**
  35. * List of group members
  36. *
  37. * @category Group
  38. * @package Laconica
  39. * @author Evan Prodromou <evan@controlyourself.ca>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://laconi.ca/
  42. */
  43. class GroupmembersAction extends GroupDesignAction
  44. {
  45. var $page = null;
  46. function isReadOnly($args)
  47. {
  48. return true;
  49. }
  50. function prepare($args)
  51. {
  52. parent::prepare($args);
  53. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  54. $nickname_arg = $this->arg('nickname');
  55. $nickname = common_canonical_nickname($nickname_arg);
  56. // Permanent redirect on non-canonical nickname
  57. if ($nickname_arg != $nickname) {
  58. $args = array('nickname' => $nickname);
  59. if ($this->page != 1) {
  60. $args['page'] = $this->page;
  61. }
  62. common_redirect(common_local_url('groupmembers', $args), 301);
  63. return false;
  64. }
  65. if (!$nickname) {
  66. $this->clientError(_('No nickname'), 404);
  67. return false;
  68. }
  69. $this->group = User_group::staticGet('nickname', $nickname);
  70. if (!$this->group) {
  71. $this->clientError(_('No such group'), 404);
  72. return false;
  73. }
  74. return true;
  75. }
  76. function title()
  77. {
  78. if ($this->page == 1) {
  79. return sprintf(_('%s group members'),
  80. $this->group->nickname);
  81. } else {
  82. return sprintf(_('%s group members, page %d'),
  83. $this->group->nickname,
  84. $this->page);
  85. }
  86. }
  87. function handle($args)
  88. {
  89. parent::handle($args);
  90. $this->showPage();
  91. }
  92. function showPageNotice()
  93. {
  94. $this->element('p', 'instructions',
  95. _('A list of the users in this group.'));
  96. }
  97. function showLocalNav()
  98. {
  99. $nav = new GroupNav($this, $this->group);
  100. $nav->show();
  101. }
  102. function showContent()
  103. {
  104. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  105. $limit = PROFILES_PER_PAGE + 1;
  106. $cnt = 0;
  107. $members = $this->group->getMembers($offset, $limit);
  108. if ($members) {
  109. $member_list = new GroupMemberList($members, $this->group, $this);
  110. $cnt = $member_list->show();
  111. }
  112. $members->free();
  113. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  114. $this->page, 'groupmembers',
  115. array('nickname' => $this->group->nickname));
  116. }
  117. }
  118. class GroupMemberList extends ProfileList
  119. {
  120. var $group = null;
  121. function __construct($profile, $group, $action)
  122. {
  123. parent::__construct($profile, $action);
  124. $this->group = $group;
  125. }
  126. function newListItem($profile)
  127. {
  128. return new GroupMemberListItem($profile, $this->group, $this->action);
  129. }
  130. }
  131. class GroupMemberListItem extends ProfileListItem
  132. {
  133. var $group = null;
  134. function __construct($profile, $group, $action)
  135. {
  136. parent::__construct($profile, $action);
  137. $this->group = $group;
  138. }
  139. function showFullName()
  140. {
  141. parent::showFullName();
  142. if ($this->profile->isAdmin($this->group)) {
  143. $this->out->text(' ');
  144. $this->out->element('span', 'role', _('Admin'));
  145. }
  146. }
  147. function showActions()
  148. {
  149. $this->startActions();
  150. $this->showSubscribeButton();
  151. $this->showMakeAdminForm();
  152. $this->showGroupBlockForm();
  153. $this->endActions();
  154. }
  155. function showMakeAdminForm()
  156. {
  157. $user = common_current_user();
  158. if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group) &&
  159. !$this->profile->isAdmin($this->group)) {
  160. $this->out->elementStart('li', 'entity_make_admin');
  161. $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
  162. array('action' => 'groupmembers',
  163. 'nickname' => $this->group->nickname));
  164. $maf->show();
  165. $this->out->elementEnd('li');
  166. }
  167. }
  168. function showGroupBlockForm()
  169. {
  170. $user = common_current_user();
  171. if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
  172. $this->out->elementStart('li', 'entity_block');
  173. $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
  174. array('action' => 'groupmembers',
  175. 'nickname' => $this->group->nickname));
  176. $bf->show();
  177. $this->out->elementEnd('li');
  178. }
  179. }
  180. }
  181. /**
  182. * Form for blocking a user from a group
  183. *
  184. * @category Form
  185. * @package Laconica
  186. * @author Evan Prodromou <evan@controlyourself.ca>
  187. * @author Sarven Capadisli <csarven@controlyourself.ca>
  188. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  189. * @link http://laconi.ca/
  190. *
  191. * @see BlockForm
  192. */
  193. class GroupBlockForm extends Form
  194. {
  195. /**
  196. * Profile of user to block
  197. */
  198. var $profile = null;
  199. /**
  200. * Group to block the user from
  201. */
  202. var $group = null;
  203. /**
  204. * Return-to args
  205. */
  206. var $args = null;
  207. /**
  208. * Constructor
  209. *
  210. * @param HTMLOutputter $out output channel
  211. * @param Profile $profile profile of user to block
  212. * @param User_group $group group to block user from
  213. * @param array $args return-to args
  214. */
  215. function __construct($out=null, $profile=null, $group=null, $args=null)
  216. {
  217. parent::__construct($out);
  218. $this->profile = $profile;
  219. $this->group = $group;
  220. $this->args = $args;
  221. }
  222. /**
  223. * ID of the form
  224. *
  225. * @return int ID of the form
  226. */
  227. function id()
  228. {
  229. // This should be unique for the page.
  230. return 'block-' . $this->profile->id;
  231. }
  232. /**
  233. * class of the form
  234. *
  235. * @return string class of the form
  236. */
  237. function formClass()
  238. {
  239. return 'form_group_block';
  240. }
  241. /**
  242. * Action of the form
  243. *
  244. * @return string URL of the action
  245. */
  246. function action()
  247. {
  248. return common_local_url('groupblock');
  249. }
  250. /**
  251. * Legend of the Form
  252. *
  253. * @return void
  254. */
  255. function formLegend()
  256. {
  257. $this->out->element('legend', null, _('Block user from group'));
  258. }
  259. /**
  260. * Data elements of the form
  261. *
  262. * @return void
  263. */
  264. function formData()
  265. {
  266. $this->out->hidden('blockto-' . $this->profile->id,
  267. $this->profile->id,
  268. 'blockto');
  269. $this->out->hidden('blockgroup-' . $this->group->id,
  270. $this->group->id,
  271. 'blockgroup');
  272. if ($this->args) {
  273. foreach ($this->args as $k => $v) {
  274. $this->out->hidden('returnto-' . $k, $v);
  275. }
  276. }
  277. }
  278. /**
  279. * Action elements
  280. *
  281. * @return void
  282. */
  283. function formActions()
  284. {
  285. $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
  286. }
  287. }
  288. /**
  289. * Form for making a user an admin for a group
  290. *
  291. * @category Form
  292. * @package Laconica
  293. * @author Evan Prodromou <evan@controlyourself.ca>
  294. * @author Sarven Capadisli <csarven@controlyourself.ca>
  295. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  296. * @link http://laconi.ca/
  297. */
  298. class MakeAdminForm extends Form
  299. {
  300. /**
  301. * Profile of user to block
  302. */
  303. var $profile = null;
  304. /**
  305. * Group to block the user from
  306. */
  307. var $group = null;
  308. /**
  309. * Return-to args
  310. */
  311. var $args = null;
  312. /**
  313. * Constructor
  314. *
  315. * @param HTMLOutputter $out output channel
  316. * @param Profile $profile profile of user to block
  317. * @param User_group $group group to block user from
  318. * @param array $args return-to args
  319. */
  320. function __construct($out=null, $profile=null, $group=null, $args=null)
  321. {
  322. parent::__construct($out);
  323. $this->profile = $profile;
  324. $this->group = $group;
  325. $this->args = $args;
  326. }
  327. /**
  328. * ID of the form
  329. *
  330. * @return int ID of the form
  331. */
  332. function id()
  333. {
  334. // This should be unique for the page.
  335. return 'makeadmin-' . $this->profile->id;
  336. }
  337. /**
  338. * class of the form
  339. *
  340. * @return string class of the form
  341. */
  342. function formClass()
  343. {
  344. return 'form_make_admin';
  345. }
  346. /**
  347. * Action of the form
  348. *
  349. * @return string URL of the action
  350. */
  351. function action()
  352. {
  353. return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
  354. }
  355. /**
  356. * Legend of the Form
  357. *
  358. * @return void
  359. */
  360. function formLegend()
  361. {
  362. $this->out->element('legend', null, _('Make user an admin of the group'));
  363. }
  364. /**
  365. * Data elements of the form
  366. *
  367. * @return void
  368. */
  369. function formData()
  370. {
  371. $this->out->hidden('profileid-' . $this->profile->id,
  372. $this->profile->id,
  373. 'profileid');
  374. $this->out->hidden('groupid-' . $this->group->id,
  375. $this->group->id,
  376. 'groupid');
  377. if ($this->args) {
  378. foreach ($this->args as $k => $v) {
  379. $this->out->hidden('returnto-' . $k, $v);
  380. }
  381. }
  382. }
  383. /**
  384. * Action elements
  385. *
  386. * @return void
  387. */
  388. function formActions()
  389. {
  390. $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));
  391. }
  392. }