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