Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

  1. <?php
  2. use Friendica\App;
  3. use Friendica\Database\DBA;
  4. use Friendica\Model\Contact;
  5. use Friendica\Model\Group;
  6. function contactgroup_content(App $a)
  7. {
  8. if (!local_user()) {
  9. exit();
  10. }
  11. $change = null;
  12. if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
  13. $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
  14. intval($a->argv[2]),
  15. intval(local_user())
  16. );
  17. if (DBA::isResult($r)) {
  18. $change = intval($a->argv[2]);
  19. }
  20. }
  21. if (($a->argc > 1) && (intval($a->argv[1]))) {
  22. $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
  23. intval($a->argv[1]),
  24. intval(local_user())
  25. );
  26. if (!DBA::isResult($r)) {
  27. exit();
  28. }
  29. $group = $r[0];
  30. $members = Contact::getByGroupId($group['id']);
  31. $preselected = [];
  32. if (count($members)) {
  33. foreach ($members as $member) {
  34. $preselected[] = $member['id'];
  35. }
  36. }
  37. if (!empty($change)) {
  38. if (in_array($change, $preselected)) {
  39. Group::removeMember($group['id'], $change);
  40. } else {
  41. Group::addMember($group['id'], $change);
  42. }
  43. }
  44. }
  45. exit();
  46. }