]> git.mxchange.org Git - friendica.git/blob - mod/manage.php
Merge pull request #7725 from dew-git/develop
[friendica.git] / mod / manage.php
1 <?php
2 /**
3  * @file mod/manage.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\Hook;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Session;
11 use Friendica\Database\DBA;
12
13 function manage_post(App $a) {
14
15         if (!local_user()) {
16                 return;
17         }
18
19         $uid = local_user();
20         $orig_record = $a->user;
21
22         if(!empty($_SESSION['submanage'])) {
23                 $user = DBA::selectFirst('user', [], ['uid' => $_SESSION['submanage']]);
24                 if (DBA::isResult($user)) {
25                         $uid = intval($user['uid']);
26                         $orig_record = $user;
27                 }
28         }
29
30         $identity = (!empty($_POST['identity']) ? intval($_POST['identity']) : 0);
31         if (!$identity) {
32                 return;
33         }
34
35         $limited_id = 0;
36         $original_id = $uid;
37
38         $manage = DBA::select('manage', ['mid'], ['uid' => $uid]);
39         while ($m = DBA::fetch($manage)) {
40                 if ($identity == $m['mid']) {
41                         $limited_id = $m['mid'];
42                         break;
43                 }
44         }
45         DBA::close($manage);
46
47         if ($limited_id) {
48                 $user = DBA::selectFirst('user', [], ['uid' => $limited_id]);
49         } else {
50                 // Check if the target user is one of our children
51                 $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
52
53                 // Check if the target user is one of our siblings
54                 if (!DBA::isResult($user) && ($orig_record['parent-uid'] != 0)) {
55                         $user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
56                 }
57
58                 // Check if it's our parent
59                 if (!DBA::isResult($user) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
60                         $user = DBA::selectFirst('user', [], ['uid' => $identity]);
61                 }
62
63                 // Finally check if it's out own user
64                 if (!DBA::isResult($user) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
65                         $user = DBA::selectFirst('user', [], ['uid' => $identity]);
66                 }
67
68         }
69
70         if (!DBA::isResult($user)) {
71                 return;
72         }
73
74         Session::clear();
75
76         Session::setAuthenticatedForUser($a, $user, true, true);
77
78         if ($limited_id) {
79                 $_SESSION['submanage'] = $original_id;
80         }
81
82         $ret = [];
83         Hook::callAll('home_init', $ret);
84
85         $a->internalRedirect('profile/' . $a->user['nickname']);
86         // NOTREACHED
87 }
88
89 function manage_content(App $a) {
90
91         if (!local_user()) {
92                 notice(L10n::t('Permission denied.') . EOL);
93                 return;
94         }
95
96         if (!empty($_GET['identity'])) {
97                 $_POST['identity'] = $_GET['identity'];
98                 manage_post($a);
99                 return;
100         }
101
102         $identities = $a->identities;
103
104         //getting additinal information for each identity
105         foreach ($identities as $key => $id) {
106                 $thumb = DBA::selectFirst('contact', ['thumb'], ['uid' => $id['uid'] , 'self' => true]);
107                 if (!DBA::isResult($thumb)) {
108                         continue;
109                 }
110
111                 $identities[$key]['thumb'] = $thumb['thumb'];
112
113                 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
114
115                 $condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $id['uid'], NOTIFY_INTRO, NOTIFY_MAIL];
116                 $params = ['distinct' => true, 'expression' => 'parent'];
117                 $notifications = DBA::count('notify', $condition, $params);
118
119                 $params = ['distinct' => true, 'expression' => 'convid'];
120                 $notifications += DBA::count('mail', ['uid' => $id['uid'], 'seen' => false], $params);
121
122                 $notifications += DBA::count('intro', ['blocked' => false, 'ignore' => false, 'uid' => $id['uid']]);
123
124                 $identities[$key]['notifications'] = $notifications;
125         }
126
127         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('manage.tpl'), [
128                 '$title' => L10n::t('Manage Identities and/or Pages'),
129                 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
130                 '$choose' => L10n::t('Select an identity to manage: '),
131                 '$identities' => $identities,
132                 '$submit' => L10n::t('Submit'),
133         ]);
134
135         return $o;
136
137 }