-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.php
382 lines (339 loc) · 13.4 KB
/
group.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
* group
*
* @package Delus
* @author Dmitry
*/
// fetch bootloader
require('bootloader.php');
// user access
if (!$system['system_public']) {
user_access();
}
// check username
if (is_empty($_GET['username']) || !valid_username($_GET['username'])) {
_error(404);
}
try {
// [1] get main group info
$get_group = $db->query(sprintf("SELECT `groups`.*, picture_photo.source as group_picture_full, cover_photo.source as group_cover_full, groups_categories.category_name as group_category_name FROM `groups` LEFT JOIN posts_photos as picture_photo ON groups.group_picture_id = picture_photo.photo_id LEFT JOIN posts_photos as cover_photo ON `groups`.group_cover_id = cover_photo.photo_id LEFT JOIN groups_categories ON `groups`.group_category = groups_categories.category_id WHERE `groups`.group_name = %s", secure($_GET['username'])));
if ($get_group->num_rows == 0) {
_error(404);
}
$group = $get_group->fetch_assoc();
/* check username case */
if (strtolower($_GET['username']) == strtolower($group['group_name']) && $_GET['username'] != $group['group_name']) {
redirect('/groups/' . $group['group_name']);
}
/* get group picture */
$group['group_picture_default'] = ($group['group_picture']) ? false : true;
$group['group_picture'] = get_picture($group['group_picture'], 'group');
$group['group_picture_full'] = ($group['group_picture_full']) ? $system['system_uploads'] . '/' . $group['group_picture_full'] : $group['group_picture_full'];
/* get group cover */
$group['group_cover'] = ($group['group_cover']) ? $system['system_uploads'] . '/' . $group['group_cover'] : $group['group_cover'];
$group['group_cover_full'] = ($group['group_cover_full']) ? $system['system_uploads'] . '/' . $group['group_cover_full'] : $group['group_cover_full'];
/* check group category */
$group['group_category_name'] = (!$group['group_category_name']) ? __('N/A') : $group['group_category_name']; /* in case deleted by system admin */
/* get the connection */
$group['i_admin'] = $user->check_group_adminship($user->_data['user_id'], $group['group_id']);
$group['i_joined'] = $user->check_group_membership($user->_data['user_id'], $group['group_id']);
$group['i_invited'] = $user->check_group_invitation($user->_data['user_id'], $group['group_id']);
/* get chatbox converstaion */
if ($system['chat_enabled'] && $group['chatbox_enabled'] && $group['i_joined'] == "approved") {
$group['chatbox_conversation'] = $user->get_chatbox($group['chatbox_conversation_id']);
}
/* get group posts count */
$group['posts_count'] = $user->get_posts_count($group['group_id'], 'group');
/* get group photos count */
$group['photos_count'] = $user->get_photos_count($group['group_id'], 'group');
/* get group videos count */
if ($system['videos_enabled']) {
$group['videos_count'] = $user->get_videos_count($group['group_id'], 'group');
}
/* get group reviews count */
if ($system['groups_reviews_enabled']) {
$group['reviews_count'] = $user->get_reviews_count($group['group_id'], 'group');
}
/* check if group's admin can monetize content */
$group['can_monetize_content'] = $system['monetization_enabled'] && $user->check_user_permission($group['group_admin'], 'monetization_permission');
/* check if group has monetization enabled && subscriptions plans */
$group['has_subscriptions_plans'] = $group['can_monetize_content'] && $group['group_monetization_enabled'] && $group['group_monetization_plans'] > 0;
/* check if the group needs subscription (exclude: admins & mods & group's admin) */
$group['needs_subscription'] = false;
if ($group['has_subscriptions_plans']) {
if ($user->_logged_in) {
if ($user->_data['user_group'] == 3 && !$group['i_admin']) {
if (!$user->is_subscribed($group['group_id'], 'group')) {
$group['needs_subscription'] = true;
}
}
} else {
$group['needs_subscription'] = true;
}
}
// [2] get view content
/* check group privacy */
if ($group['group_privacy'] == "secret") {
if ($group['i_joined'] != "approved" && !$group['i_invited'] && !$group['i_admin']) {
if (!$user->_is_admin && !$user->_is_moderator) {
_error(404);
}
}
if ($group['i_joined'] != "approved" && $group['i_invited']) {
$_GET['view'] = 'members';
}
}
if ($group['group_privacy'] == "closed") {
if ($group['i_joined'] != "approved" && !$group['i_admin']) {
if (!$user->_is_admin && !$user->_is_moderator) {
$_GET['view'] = 'members';
}
}
}
switch ($_GET['view']) {
case '':
/* get custom fields */
$smarty->assign('custom_fields', $user->get_custom_fields(["for" => "group", "get" => "profile", "node_id" => $group['group_id']]));
/* get subscribers */
if ($group['has_subscriptions_plans']) {
/* get subscribers count */
$group['subscribers_count'] = $user->get_subscribers_count($group['group_id'], 'group');
/* get subscribers */
if ($group['subscribers_count'] > 0) {
$group['subscribers'] = $user->get_subscribers($group['group_id'], 'group');
}
}
/* get invites */
$group['invites'] = $user->get_group_invites($group['group_id']);
/* get photos */
if (!$group['needs_subscription']) {
$group['photos'] = $user->get_photos($group['group_id'], 'group');
}
/* get [pending] group requests */
if ($group['i_admin'] && $group['group_privacy'] != "public") {
$group['total_requests'] = $user->get_group_requests_total($group['group_id']);
}
/* get [pending] group posts */
if ($group['group_publish_approval_enabled']) {
$get_all = ($group['i_admin']) ? true : false;
$group['pending_posts'] = $user->get_group_pending_posts($group['group_id'], $get_all);
}
/* prepare publisher */
$smarty->assign('feelings', get_feelings());
$smarty->assign('feelings_types', get_feelings_types());
if ($system['colored_posts_enabled']) {
$smarty->assign('colored_patterns', $user->get_posts_colored_patterns());
}
if ($user->_data['can_upload_videos']) {
$smarty->assign('videos_categories', $user->get_categories("posts_videos_categories"));
}
/* check if there is share URL */
if ($_GET['url']) {
$smarty->assign('url', $_GET['url']);
}
/* get pinned post */
$pinned_post = $user->get_post($group['group_pinned_post'], true, false, true);
$smarty->assign('pinned_post', $pinned_post);
/* get posts */
if (isset($_GET['pending'])) {
$get = ($group['i_admin']) ? "posts_group_pending_all" : "posts_group_pending";
} else {
$get = "posts_group";
}
/* newsfeed location filter */
if ($system['newsfeed_location_filter_enabled']) {
// get selected country
if (isset($_GET['country'])) {
/* get selected country */
$selected_country = $user->get_country_by_name($_GET['country']);
/* assign variables */
$smarty->assign('selected_country', $selected_country);
}
}
$posts = ($selected_country) ? $user->get_posts(['country' => $selected_country['country_id'], 'get' => $get, 'id' => $group['group_id']]) : $user->get_posts(['get' => $get, 'id' => $group['group_id']]);
/* assign variables */
$smarty->assign('posts', $posts);
$smarty->assign('get', $get);
/* get ads */
$smarty->assign('ads', $user->ads('groups', $group['group_id']));
break;
case 'photos':
/* get content */
if (!$group['needs_subscription']) {
/* get photos */
$group['photos'] = $user->get_photos($group['group_id'], 'group');
}
break;
case 'albums':
/* get content */
if (!$group['needs_subscription']) {
/* get albums */
$group['albums'] = $user->get_albums($group['group_id'], 'group');
}
break;
case 'album':
/* get content */
if (!$group['needs_subscription']) {
/* get album */
$album = $user->get_album($_GET['id']);
if (!$album || ($album['group_id'] != $group['group_id'])) {
_error(404);
}
/* assign variables */
$smarty->assign('album', $album);
}
break;
case 'videos':
/* check if videos enabled */
if (!$system['videos_enabled']) {
_error(404);
}
/* get content */
if (!$group['needs_subscription']) {
/* get videos */
$group['videos'] = $user->get_videos($group['group_id'], 'group');
}
break;
case 'reels':
/* check if reels enabled */
if (!$system['reels_enabled']) {
_error(404);
}
/* get content */
if (!$group['needs_subscription']) {
/* get reels */
$group['reels'] = $user->get_reels($group['group_id'], 'group');
}
break;
case 'products':
/* get content */
if (!$group['needs_subscription']) {
/* get posts (products) */
$posts = $user->get_posts(['get' => 'posts_group', 'id' => $group['group_id'], 'filter' => 'product']);
/* assign variables */
$smarty->assign('posts', $posts);
}
break;
case 'reviews':
/* check if reviews enabled */
if (!$system['groups_reviews_enabled']) {
_error(404);
}
/* get reviews */
if ($group['reviews_count'] > 0) {
$group['reviews'] = $user->get_reviews($group['group_id'], 'group');
}
break;
case 'members':
/* get members */
if ($group['group_members'] > 0) {
$group['members'] = $user->get_group_members($group['group_id']);
}
break;
case 'subscribers':
/* check if has subscriptions plans */
if (!$group['has_subscriptions_plans']) {
_error(404);
}
/* get subscribers count */
$group['subscribers_count'] = $user->get_subscribers_count($group['group_id'], 'group');
/* get subscribers */
if ($group['subscribers_count'] > 0) {
$group['subscribers'] = $user->get_subscribers($group['group_id'], 'group');
}
break;
case 'invites':
/* check if the viewer is a group member */
if ($group['i_joined'] != "approved") {
_error(404);
}
/* get invites */
$group['invites'] = $user->get_group_invites($group['group_id']);
break;
case 'search':
/* get search */
if (isset($_GET['query'])) {
$filter = (isset($_GET['filter'])) ? $_GET['filter'] : 'all';
$posts = $user->get_posts(['get' => 'posts_group', 'id' => $group['group_id'], 'query' => $_GET['query'], 'filter' => $filter]);
/* assign variables */
$smarty->assign('query', htmlentities($_GET['query'], ENT_QUOTES, 'utf-8'));
$smarty->assign('filter', $filter);
$smarty->assign('posts', $posts);
}
break;
case 'settings':
/* check if the viewer is the admin */
if (!$group['i_admin']) {
_error(404);
}
/* get sub_view content */
$sub_view = $_GET['id'];
switch ($sub_view) {
case '':
/* get group categories */
$smarty->assign('categories', $user->get_categories("groups_categories"));
/* get countries if not defined */
if (!$countries) {
$smarty->assign('countries', $user->get_countries());
}
/* get custom fields */
$smarty->assign('custom_fields', $user->get_custom_fields(["for" => "group", "get" => "settings", "node_id" => $group['group_id']]));
break;
case 'requests':
if ($group['group_privacy'] == "public") {
_error(404);
}
/* get requests */
$group['requests'] = $user->get_group_requests($group['group_id']);
break;
case 'members':
/* get admins */
$group['group_admins_count'] = count($user->get_group_admins_ids($group['group_id']));
$group['group_admins'] = $user->get_group_admins($group['group_id']);
/* get members */
if ($group['group_members'] > 0) {
$group['members'] = $user->get_group_members($group['group_id'], 0, true);
}
break;
case 'monetization':
// check monetization permission (only group's super admin can do this)
if (!$user->_data['can_monetize_content']) {
_error(404);
}
// get monetozaion plans
$smarty->assign('monetization_plans', $user->get_monetization_plans($group['group_id'], 'group'));
// get subscribers count
$smarty->assign('subscribers_count', $user->get_subscribers_count($group['group_id'], 'group'));
break;
case 'delete':
/* check if the viewer not the super admin */
if ($user->_data['user_id'] != $group['group_admin']) {
_error(404);
}
break;
default:
_error(404);
break;
}
/* assign variables */
$smarty->assign('sub_view', $sub_view);
break;
default:
_error(404);
break;
}
// recent rearches
if (isset($_GET['ref']) && $_GET['ref'] == "qs") {
$user->set_search_log($group['group_id'], 'group');
}
} catch (Exception $e) {
_error(__("Error"), $e->getMessage());
}
// page header
page_header($group['group_title'], $group['group_description'], $group['group_picture']);
// assign variables
$smarty->assign('group', $group);
$smarty->assign('view', $_GET['view']);
// page footer
page_footer('group');