]> git.mxchange.org Git - friendica.git/blob - mod/contactgroup.php
Remove include/oembed and mod/oembed
[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         if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
15                 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
16                         intval($a->argv[2]),
17                         intval(local_user())
18                 );
19                 if (DBM::is_result($r)) {
20                         $change = intval($a->argv[2]);
21                 }
22         }
23
24         if (($a->argc > 1) && (intval($a->argv[1]))) {
25                 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
26                         intval($a->argv[1]),
27                         intval(local_user())
28                 );
29                 if (!DBM::is_result($r)) {
30                         killme();
31                 }
32
33                 $group = $r[0];
34                 $members = Contact::getByGroupId($group['id']);
35                 $preselected = array();
36                 if (count($members)) {
37                         foreach ($members as $member) {
38                                 $preselected[] = $member['id'];
39                         }
40                 }
41
42                 if ($change) {
43                         if (in_array($change, $preselected)) {
44                                 Group::removeMember($group['id'], $change);
45                         } else {
46                                 Group::addMember($group['id'], $change);
47                         }
48                 }
49         }
50
51         killme();
52 }