]> git.mxchange.org Git - friendica.git/blob - mod/manage.php
Rewrite Proxy module
[friendica.git] / mod / manage.php
1 <?php
2 /**
3  * @file mod/manage.php
4  */
5 use Friendica\App;
6 use Friendica\Core\Authentication;
7 use Friendica\Core\Addon;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\System;
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                 $r = q("select * from user where uid = %d limit 1",
24                         intval($_SESSION['submanage'])
25                 );
26                 if (DBA::isResult($r)) {
27                         $uid = intval($r[0]['uid']);
28                         $orig_record = $r[0];
29                 }
30         }
31
32         $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
33                 intval($uid)
34         );
35
36         $submanage = $r;
37
38         $identity = (!empty($_POST['identity']) ? intval($_POST['identity']) : 0);
39         if (!$identity) {
40                 return;
41         }
42
43         $limited_id = 0;
44         $original_id = $uid;
45
46         if (DBA::isResult($submanage)) {
47                 foreach ($submanage as $m) {
48                         if ($identity == $m['mid']) {
49                                 $limited_id = $m['mid'];
50                                 break;
51                         }
52                 }
53         }
54
55         if ($limited_id) {
56                 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
57                         intval($limited_id)
58                 );
59         } else {
60                 // Check if the target user is one of our children
61                 $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
62                         intval($identity),
63                         DBA::escape($orig_record['uid'])
64                 );
65
66                 // Check if the target user is one of our siblings
67                 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0)) {
68                         $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `parent-uid` = %d LIMIT 1",
69                                 intval($identity),
70                                 DBA::escape($orig_record['parent-uid'])
71                         );
72                 }
73
74                 // Check if it's our parent
75                 if (!DBA::isResult($r) && ($orig_record['parent-uid'] != 0) && ($orig_record['parent-uid'] == $identity)) {
76                         $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
77                                 intval($identity)
78                         );
79                 }
80
81                 // Finally check if it's out own user
82                 if (!DBA::isResult($r) && ($orig_record['uid'] != 0) && ($orig_record['uid'] == $identity)) {
83                         $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
84                                 intval($identity)
85                         );
86                 }
87         }
88
89         if (!DBA::isResult($r)) {
90                 return;
91         }
92
93         unset($_SESSION['authenticated']);
94         unset($_SESSION['uid']);
95         unset($_SESSION['visitor_id']);
96         unset($_SESSION['administrator']);
97         unset($_SESSION['cid']);
98         unset($_SESSION['theme']);
99         unset($_SESSION['mobile-theme']);
100         unset($_SESSION['page_flags']);
101         unset($_SESSION['return_path']);
102         if (!empty($_SESSION['submanage'])) {
103                 unset($_SESSION['submanage']);
104         }
105         if (!empty($_SESSION['sysmsg'])) {
106                 unset($_SESSION['sysmsg']);
107         }
108         if (!empty($_SESSION['sysmsg_info'])) {
109                 unset($_SESSION['sysmsg_info']);
110         }
111
112         Authentication::setAuthenticatedSessionForUser($r[0], true, true);
113
114         if ($limited_id) {
115                 $_SESSION['submanage'] = $original_id;
116         }
117
118         $ret = [];
119         Addon::callHooks('home_init',$ret);
120
121         $a->internalRedirect('profile/' . $a->user['nickname'] );
122         // NOTREACHED
123 }
124
125
126
127 function manage_content(App $a) {
128
129         if (! local_user()) {
130                 notice(L10n::t('Permission denied.') . EOL);
131                 return;
132         }
133
134         if (!empty($_GET['identity'])) {
135                 $_POST['identity'] = $_GET['identity'];
136                 manage_post($a);
137                 return;
138         }
139
140         $identities = $a->identities;
141
142         //getting additinal information for each identity
143         foreach ($identities as $key=>$id) {
144                 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
145                         DBA::escape($id['uid'])
146                 );
147
148                 $identities[$key]['thumb'] = $thumb[0]['thumb'];
149
150                 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
151
152                 $notifications = 0;
153
154                 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
155                         intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
156
157                 if (DBA::isResult($r)) {
158                         $notifications = sizeof($r);
159                 }
160
161                 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
162                         intval($id['uid']));
163
164                 if (DBA::isResult($r)) {
165                         $notifications = $notifications + sizeof($r);
166                 }
167
168                 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
169                         intval($id['uid']));
170
171                 if (DBA::isResult($r)) {
172                         $notifications = $notifications + $r[0]["introductions"];
173                 }
174
175                 $identities[$key]['notifications'] = $notifications;
176         }
177
178         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('manage.tpl'), [
179                 '$title' => L10n::t('Manage Identities and/or Pages'),
180                 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
181                 '$choose' => L10n::t('Select an identity to manage: '),
182                 '$identities' => $identities,
183                 '$submit' => L10n::t('Submit'),
184         ]);
185
186         return $o;
187
188 }