]> git.mxchange.org Git - friendica.git/blob - mod/manage.php
Improve Console/Config display for array values
[friendica.git] / mod / manage.php
1 <?php
2 /**
3  * @file mod/manage.php
4  */
5 use Friendica\App;
6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10
11 require_once "include/text.php";
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((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
23                 $r = q("select * from user where uid = %d limit 1",
24                         intval($_SESSION['submanage'])
25                 );
26                 if (DBM::is_result($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 = (x($_POST['identity']) ? intval($_POST['identity']) : 0);
39         if (!$identity) {
40                 return;
41         }
42
43         $limited_id = 0;
44         $original_id = $uid;
45
46         if (DBM::is_result($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                         dbesc($orig_record['uid'])
64                 );
65
66                 // Check if the target user is one of our siblings
67                 if (!DBM::is_result($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                                 dbesc($orig_record['parent-uid'])
71                         );
72                 }
73
74                 // Check if it's our parent
75                 if (!DBM::is_result($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 (!DBM::is_result($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 (!DBM::is_result($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_url']);
102         if (x($_SESSION, 'submanage')) {
103                 unset($_SESSION['submanage']);
104         }
105         if (x($_SESSION, 'sysmsg')) {
106                 unset($_SESSION['sysmsg']);
107         }
108         if (x($_SESSION, 'sysmsg_info')) {
109                 unset($_SESSION['sysmsg_info']);
110         }
111
112         require_once('include/security.php');
113         authenticate_success($r[0], true, true);
114
115         if ($limited_id) {
116                 $_SESSION['submanage'] = $original_id;
117         }
118
119         $ret = [];
120         Addon::callHooks('home_init',$ret);
121
122         goaway( System::baseUrl() . "/profile/" . $a->user['nickname'] );
123         // NOTREACHED
124 }
125
126
127
128 function manage_content(App $a) {
129
130         if (! local_user()) {
131                 notice(L10n::t('Permission denied.') . EOL);
132                 return;
133         }
134
135         if ($_GET['identity']) {
136                 $_POST['identity'] = $_GET['identity'];
137                 manage_post($a);
138                 return;
139         }
140
141         $identities = $a->identities;
142
143         //getting additinal information for each identity
144         foreach ($identities as $key=>$id) {
145                 $thumb = q("SELECT `thumb` FROM `contact` WHERE `uid` = '%s' AND `self` = 1",
146                         dbesc($id['uid'])
147                 );
148
149                 $identities[$key]['thumb'] = $thumb[0]['thumb'];
150
151                 $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
152
153                 $notifications = 0;
154
155                 $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
156                         intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
157
158                 if (DBM::is_result($r)) {
159                         $notifications = sizeof($r);
160                 }
161
162                 $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
163                         intval($id['uid']));
164
165                 if (DBM::is_result($r)) {
166                         $notifications = $notifications + sizeof($r);
167                 }
168
169                 $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
170                         intval($id['uid']));
171
172                 if (DBM::is_result($r)) {
173                         $notifications = $notifications + $r[0]["introductions"];
174                 }
175
176                 $identities[$key]['notifications'] = $notifications;
177         }
178
179         $o = replace_macros(get_markup_template('manage.tpl'), [
180                 '$title' => L10n::t('Manage Identities and/or Pages'),
181                 '$desc' => L10n::t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
182                 '$choose' => L10n::t('Select an identity to manage: '),
183                 '$identities' => $identities,
184                 '$submit' => L10n::t('Submit'),
185         ]);
186
187         return $o;
188
189 }